How to write cron job in AWS EC2 server

后端 未结 3 861
一生所求
一生所求 2021-01-31 10:01

I\'ve created a cron job in AWS EC2 but it is not working.

I followed below steps to create cron tab:

  • Step 1: I logged in to AWS EC2 Instace
  • step
3条回答
  •  死守一世寂寞
    2021-01-31 10:48

    First of all, you need to put an space between php and /var:

    From

    * * * * * php/var/www/html/welcome.php
    

    to

    * * * * * php /var/www/html/welcome.php
                 ^
    

    Then, you'd better use /bin/php instead of just php. To determine where the php executable is located, type which php in your console, it will give you the file path. So it will become something like this:

    * * * * * /bin/php /var/www/html/welcome.php
              ^^^^^^^^
    

    More things:

    • check if crontab is saved properly? Type crontab -l. Your new crontab line should be there.
    • is the script exactly in this dir? Try ls -l /var/www/html/welcome.php.
    • is the script executing if you do from console? Try /bin/php var/www/html/welcome.php to see if it is a script or crontab problem.
    • does the script have executing mode? Try chmod 755 /var/www/html/welcome.php

    Keep us updated so we can find what can be causing the error.

提交回复
热议问题