How to run a Cron Job?

To run the script on schedule, we will look at the category of “Cron Job” in the server control panel cPanel. Different control panels to configure Cron have differs in details, but in General the procedure is the same.

The software utility Cron is a time-based job scheduler in Unix-like computer operating systems

For example, we need to create a backup of the database every day. For a start go to  Tools->Database Backup page and  find the path to the PHP script which need to execute:

Cron backup: /home/yourlogin/public_html/pm/cron/backup.php

Next, go to the server control panel and select the menu item “Cron Jobs”

In the opened window, you will see several sections. The first is email. Enter your email address, and if the script fails, you will be notified.

The second is the “Add a new Cron job”. There you will be able to run the script.

In the list of “Common settings”, select “Once Per day” and in the field “Command” enter

php /home/yourlogin/public_html/pm/cron/backup.php

Note: this command is not universal, and different servers can have different options for running Cron. Therefore, before installing Cron contact to support of your server and ask for a sample command to run the Cron.

Here are some common commands:

php -f /home/yourlogin/public_html/pm/cron/backup.php
/usr/bin/php /home/yourlogin/public_html/pm/cron/backup.php
/usr/local/bin/php -q /home/yourlogin/public_html/pm/cron/backup.php

Run cron manually

To run the cron via an http link, you need to disable the file .htaccess in the cron/ folder. Just rename this file. This will make it possible to execute a cron file via an http link, example:

http://[your site]/cron/backup.php

Sometimes the server may not allow the execution of a php command. In such a case, use the link above to run the wget command.