Linux: Run PHP Script Using a Cron Job

This post will guide you how to execute a PHP script in your own cron job under CentOS/RHEL/Ubuntu Linux system. How to setup and run a PHP script as a cron job in Linux. How to run a PHP script automatically at a specified date and time with Linux cron tool.

Run PHP Script Using a Cron Job


We have talked that the cron jobs are used to schedule commands or your own scripts to be executed periodically. and You can setup a cron job in /etc/crontab configuration file to run a PHP script at a specified date and time.

Add Execute Permission for PHP Script

Before you add the cron job entry into the /etc/crontab file, you need to make sure that your php script have execute permisson. and you can use the chmod command to change the PHP file permission. Type the following command:

#chmod u+x /root/fio.php

Setup Cron Job for PHP Script

To call the PHP script from your crontab, just do the following steps:

#1 Type the following command to edit /etc/crontab file

#crontab -e

#2 add the below line into crontab file

00 * * * * /usr/local/bin/php /root/fio.php

#3 save an close configuration file.

You might also like:

Sidebar



back to top