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 -q /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 /home/yourlogin/public_html/pm/cron/backup.php
/usr/bin/php -q /home/yourlogin/public_html/pm/cron/backup.php
/usr/local/bin/php -q /home/yourlogin/public_html/pm/cron/backup.php

Also note that run a script using wget forbidden in the file .htaccess in the folder /cron/