I want to run a php script using cron job on localhost. My script is located at:
/opt/lampp/htdocs/rrugd/myscript.php
Since opt is under root, I tried adding the cron job for root, as well as normal user, but it is not executing. This is the cron job for executing the php script every 2 minutes:
*/2 * * * * php /opt/lampp/htdocs/rrugd/myscript.php
My script is basically meant to truncate a table from the database. It will actually be happening at midnight, so the actual variables of cron job will change to
00 00 * * * php /path/to/script.php
But for testing I've used every two minutes. Ive searched on the internet, and AU, but I cannot get it to run. I saw something related to setting a PATH but I didn't understand what is to be done exactly in that method.
Also, I would like to specify that the PHP script myscript.php
DID NOT execute on CLI with the PHP command, however it does execute when executed or called through the browser on localhost!
PHP Information:
some@somepc$: php -v
PHP 5.5.3-1ubuntu2.2 (cli) (built: Feb 28 2014 20:06:05)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
*/2 * * * * /usr/local/bin/php /opt/lampp/htdocs/rrugd/myscript.php
instead & let me know whether it works.. or the location of wherephp
is located.. :)sudo apt-get install php5-cli
in order execute using terminal commands. And then you can try replacingphp
intophp5
. Let me know how it goesphp -v
&whereis php
... also as an alternative you can try to place your php script in localhostwww
dir (or htdocs or whatever) & try to call it as a url*/2 * * * * wget -q http://localhost//myscript.php
. Let me try to make it more clear after looking at the outputs.