I‘ve written a PHP script. I would like to run it as a cron job. I’m using CentOS server with Apache web server. How do I setup a PHP script as a cron job on a Linux or Unix-like systems?
You need to setup execute permission on a php script. You need to use chmod command to change file access permissions. [donotprint][/donotprint] Use the chmod command as follows on your php script:
chmod +x scriptname.php
Also make sure you add following line to top of php script (first line should be #!/usr/bin/php):
#!/usr/bin/php
|
#!/usr/bin/php
If you are using FreeBSD unix os, use:
#!/usr/local/bin/php
|
#!/usr/local/bin/php
#!/usr/bin/php is called as a shebang (pound bang). It execute php script using the interpreter /usr/bin/php. Save and close the file.
Setup and run php script as a cron job
Now add cron job by typing following command:
$ crontab -e
Sample outputs:
# run everday at 10:45 45 10 * * * /path/to/myphpscript.php |
# run everday at 10:45
45 10 * * * /path/to/myphpscript.php
Save and close the file.
- What is cron on a Linux or Unix-like systems?
- HowTo: Add Jobs To cron Under Linux or UNIX?
- Linux Verify crond Daemon And Cronjobs Are Running
- Linux Start Restart and Stop The Cron or Crond Service
- Linux: List / Display All Cron Jobs
- Linux / UNIX Crontab File Location
- Linux / UNIX: Change Crontab Email Settings ( MAILTO )
- Disable The Mail Alert By Crontab Command On a Linux or Unix-like Systems
- Linux: At What Time Cron Entries In cron.daily, cron.weekly, cron.monthly Run?
- Linux Execute Cron Job After System Reboot
- Linux / UNIX Setup and Run PHP Script As A Cron Job
- How to run crontab job every minute on a Linux or Unix-like system
- Run crontab (cron jobs) Every 10 Minutes
- Cron Job Script Execution on the Last Day of a Month
- Run crontab (cron jobs) every 1 minute
(adsbygoogle = window.adsbygoogle || []).push({});