Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a php file under php called test.php set to run every 5th minute of the hour. When ever I run the file manually (by going to the web browser and runnint the path) it works fine. But when the cron job tries to run it I get the error message

my cron job is

#### Delete Records
5 * * * * /var/www/html/phpsysinfo/cronUpdateLeadBucketOnEnergycAlliance.php

my phpfile is (path : /var/www/html/phpsysinfo/phpfile)

 $sql = mysql_query("DELETE FROM list where status <> 'LEAD'") or die(mysql_error());

and the error that I get is:

/var/www/html/phpsysinfo/phpFile.php: line 1: ?php: No such file or directory
/var/www/html/phpsysinfo/phpFile.php: line 2: syntax error near unexpected token `"dbconnect.php"'
/var/www/html/phpsysinfo/phpFile.php: line 2: `require("dbconnect.php");


share|improve this question
up vote 6 down vote accepted

You're missing the call to the php binary in your cron, it should look like this

### Delete Records
5 * * * * php -q /var/www/html/phpsysinfo/cronUpdateLeadBucketOnEnergycAlliance.php

Please substitute php with php-cli depending on how the php command line binary is named on your distribution :)

share|improve this answer
2 will probably have to specify the path to the php binary too. – David Mackintosh Feb 1 '11 at 15:12
only if php is in a location not available in the PATH but yeah, good point :) +1 – lynxman Feb 1 '11 at 15:20
ok, strictly speaking you "should" include the path to the php binary so that you are explicit about what you are running and not getting hijacked by something unexpected in the path. – David Mackintosh Feb 1 '11 at 16:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.