1
votes

I am running Ubunutu Linux server, PHP5, Apache2 and am having trouble getting any sort of cronjob to run through the crontab.

I edit the crontab using

crontab -e

I save the file I want to run:

*/5 * * * * php /home/user/public_html/crx/cronx.php

it saves fine. I can run the file from the console and goes through fine. I can't even find any existing logs for the file. I checked cron was running, stopped and started... no change.

The current php file is just a simple test script that inserts a single line into a database.

I checked the permissions for the file and has read and write. Am absolutely stumped. I can't seem to get ANYTHING to run through cron. Is there something I can run to test permissions?

EDIT I have also tried the following command

          • /usr/bin/php /home/user/public_html/crx/cronx.php

I used whereis php and which php to locate and confirm it is all running in the right area

1

1 Answers

3
votes

You have too many * values for your times.

Also, cron may not have a PATH set up correctly to use PHP.

Instead try:

*/5 * * * * /usr/bin/php /home/user/public_html/crx/cronx.php

Where /usr/bin/php is the actual path to PHP. From the console you can run which php to see the path to the PHP binary you should use.

EDIT: Here are a couple of more things to try in order to troubleshoot:

# see if cron is running just by having it create a file
*/5 * * * * touch /tmp/crontab-$(date +%s)

Another option:

Set the permissions of your PHP script to 755, and change the beginning to:

#!/usr/bin/php -q
<?php
// rest of script

Then change your cron tab to:

*/5 * * * * /home/user/public_html/crx/cronx.php

I'm still not sure if cron is the issue or the running of the PHP script.