Linux – run PHP file from shell script

cronlinuxshellUbuntu

I have never added a cron job and am not much use with shell either…
My chosen cron directory is /etc/cron.daily/

all I need my script to do is run a php file daily. I would be nice if it ran at 11:00 AM.

Is this all I need for the 'script'?:

#!/bin/sh
php myphppage.php

how (what command) do I 'submit' the script to the cron.daily?

Sincere thanks!

Best Answer

You should setup a cron task by yourself instead.

Just type crontab -e to edit the crontab and add the following to run your script every days at 11:00 AM :

00 11 * * * /path/to/script.sh

Or run your PHP script directly from crontab :

00 11 * * * /usr/bin/php /path/to/myphppage.php

Save and exit.


If you want to use an external script call (first sample i used with script.sh), you should specify full path to binaries/script within your shell script :

#!/bin/sh
/usr/bin/php /path/to/myphppage.php

As a side note, using the appropriate shebang in your PHP script you don't even need to specify the program to use to run your script. Add the following at the beginning of your PHP file :

#!/usr/bin/php

Then your crontab will just look like this :

00 11 * * * /path/to/myphppage.php