0

I log into my AWS server as ec2-user, but I try to have everything run as root, so I manage my crontab with the sudo crontab -e command. This is what is in it:

* * * * * php /var/www/html/a*****/cron/cron.php
* * * * * php /var/www/html/d*****/cron/cron.php
* * * * * /usr/bin/php -f /var/www/html/k*****/cron/cron.php
* * * * * php /var/www/html/l*****/cron/cron.php

The /var/www/html/k*****/cron/cron.php script looks like the following:

<?php
include_once('../functions.php');
date_default_timezone_set("UTC");


// ==============================================

$content = file_get_contents("output.txt");

file_put_contents("output.txt", date('j M Y \a\t g:ia').
                  "\n\n---------------------\n".$content);

// ==============================================

performScheduledJobs();

The other cron.php files in the sudo crontab -e view all look identical, except without the bit between the // ===== marks.

Since these scripts are supposed to run every minute (per the sudo crontab -e settings, with the five spaced asterisk marks * * * * *), I would expect the output.txt to have the current timestamp (in UTC) being printed every minute. Instead, it only contains the (UTC) timestamp of every time the script is run manually using the following command:

sudo php cron.php

That command (from within the /var/www/html/k*****/cron/ directory, of course) works 100% successfully.

Of course, my instinct is that the cron.php file isn't even being attempted to be run, but when I sudo vi /var/log/cron I see the following:

Mar 27 21:51:01 ip-172-***-***-184 CROND[32032]: (root) CMD (php /var/www/html/a*****/cron/cron.php)
Mar 27 21:51:01 ip-172-***-***-184 CROND[32033]: (root) CMD (php /var/www/html/d*****/cron/cron.php)
Mar 27 21:51:01 ip-172-***-***-184 CROND[32035]: (root) CMD (/usr/bin/php -f /var/www/html/k*****/cron/cron.php)
Mar 27 21:51:01 ip-172-***-***-184 CROND[32034]: (root) CMD (php /var/www/html/l*****/cron/cron.php)

As I said running the sudo php cron.php command works, so whatever is wrong is likely with my crontab configuration.

Anyone have and ideas?

1 Answer 1

1

php is not in the path when running in crond. You need to specify the full path to the php executable. You can find what this is by running which php

This should output the full path to the php binary called when you run php cron.php and will be something like /usr/bin/php If you replace php with this in your crontab it should run fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.