StackArena

Quick Tip: Running a PHP script at intervals (Scheduled Task) using Cron Jobs on cPanel

| 2 Comments

There are times you might want to perform a particular task several times on your website e.g, sending an email to your users on their birthday, deleting old records from your database every month etc. With Cron, you can get it done easily.

Here I will try to show you how quickly you can get that done on cPanel if you already have the PHP script you want to run at intervals.

Even if you do not know anything about cron jobs and have never run a cron job before, you can get started with the simple cron tool built into cPanel. To get to Cron Jobs on cPanel, enter the url below on your browser; remember to change “mysite.com” to your website url.

https://mysite.com:2083/frontend/x3/cron/index.html

To run a job, you’ll need the path to the PHP script you want to execute. I always advise you put all Cron scripts in a folder and use .htaccess to protect the files there.

The command to run:
wget -O - -q -t 1 http://www.mysite.com/cron/scriptname.php where “/con/scriptname.php” is the path to your PHP script or /home/mysite/public_html/cron.php

Next you’ll want to select an option from all the select boxes. Remember to select an option in each box. If you want something to run every day at 4AM, select Minute: 0; Hour: 4; Day: Every; Month: Every; Weekday: Every;

Click save and that’s all. You’ll get an email every time the cron job runs, but if you don’t want to get an email, put a blank space into the output email field at the top.

Like this post?

By: Tunde Olabenjo

I write codes... web, mobile, desktop and hack stuffs

  • Prabhakar Shelke

    Dear Sir,

    Please tell me where I need to upload executable file on server.

    Because i did all the necessory setting of cron job but i got the mail and it gives below error,

    /bin/sh: faq/admin/mailtest.php: No such file or directory

    Thanks Inadvance….

    Thanks N Regards,
    Prabhakar Shelke.

    • http://www.facebook.com/tbenjis Tunde Olabenjo

      if you dont want to use wget, you can use php command directly.

      /usr/local/bin/php -f /home/sitename/public_html/cron.php

      If you host your site on a linux server, you will most likely have your files located at /home/sitename/public_html/ which would be your root directory.

      you may eventually end up with : /home/sitename/public_html/faq/admin/mailtest.php