Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a file in /var/www/sample/index.php. The php file will add text to sample.txt file.

Now I want to automate this by cronjob in CentOS.

I have added my cron code in /etc/crontab as following:

* * * * * root var/www/sample/index.php

But the above cron is not running.

Any guesses on why this happens?

Is there a way to interpret where i go wrong during execution of cron?

share|improve this question
Despite my answer this is probably a duplicate of askubuntu.com/questions/177971/… – Jacob Tomlinson Sep 12 '12 at 13:17
possible duplicate of How Do I Setup Cron Job? – Jorge Castro Sep 13 '12 at 12:54
Welcome to Ask Ubuntu! Questions that are about CentOS and not about Ubuntu are off-topic. You should instead ask this someplace CentOS is supported, like the CentOS forums or Unix.SE. – Eliah Kagan Sep 13 '12 at 16:48

closed as off topic by Jorge Castro, Eliah Kagan, Tom Brossman, Ringtail, Uri Herrera Sep 14 '12 at 5:27

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

Below taken from this tutorial

You must make sure your PHP is installed as CGI. To check do the following: Create a new file, name it info.php (just an example), and put in the following code, “”. Upload to your webserver and go to it with your browser.

Now check for Server API (4th item from the top), if it says “CGI”, you have PHP compiled as CGI, if it reads “Apache”, you have it running as an Apache module.

Now you need to check you have an extra line in your PHP script. It has to be the first line of your script and must contain your server’s PHP executable location:

#!/usr/local/bin/php -q

That looks a lot like PERL now, doesn’t it? After that let’s add the necessary command to our crontab. Edit /etc/crontab and add the following line:

* * * * * php /path/to/your/cron.php

Execute the following from the command line:

Shell> crontab crontab

Be sure your “script.php” has the necessary permissions to be executable (“chmod 755 script.php”).

Now you are all set!

Missing PHP

It is very possible that you're just missing the php command in your cron. You have

* * * * * root var/www/sample/index.php

but it should be

* * * * * php var/www/sample/index.php

But you must also check you have the php binary location in the PHP file as stated above.

share|improve this answer

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