Reputation: 3623
I'm trying to set up a cronjob which sends me an email when it runs.
when I execute the file using a ssh command via PuTTY, it works, it also works when I set it up as an URL, but doesn't work when setting using absolute path.
Here is what all I've tried till now : Does work :
* * * * * http://example.com/cron/cron.php
Doesn't work :
* * * * * php /var/www/clients/client2/web6/web/global/cron/cron.php
* * * * * /var/www/clients/client2/web6/web/global/cron/cron.php
* * * * * /usr/bin/php /var/www/clients/client2/web6/web/global/cron/cron.php
All 3 that I listed in 'doesn't work' works when executed as commands through PuTTY
File permissions are all sorted out and are 777 for the cron file, and the directory it resides in.
I'm using IspConfig3 and Debian and Apache2, if that matters
EDIT : here's the code in cron.php :
#!/usr/bin/php
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Cronjob <[email protected]>' . "\r\n";
mail("[email protected]", "Cronjob Complete - ". date('d-m-Y'), "At".date("H:i:s"), $headers);
?>
Upvotes: 0
Views: 2138
Reputation: 111
Run this to find the directory:
<?php print __FILE__; ?>
Try this:
* * * * * php /var/www/clients/client2/web6/web/global/cron/cron.php
This is how my crons work on my website.
Upvotes: 1
Reputation: 674
User must have rights to execute your script. Also, if it not helps, check logs: tail -f /var/log/cron
Upvotes: 1
Reputation: 364
You probably have some relative includes in your PHP file. So:
Hope this helps.
Upvotes: 1