Saturday , 21 October 2017

cPanel Cron Jobs: Run PHP File Itself Automatically

cPanel Cron Jobs Tutorial

If you are a curious programmer then you must have searched about running PHP file automatically by server because it helps to make great apps like you can develop web apps to send scheduled data to users automatically means you don’t have to sit and send data by yourself it will be done by the host server where you have uploaded (hosted) your PHP file and remember you can run any file but as you know PHP is the most famous server-side scripting language so I decided to write the tutorial to run PHP file itself but you can follow this article to run any file so let’s start the tutorial.

cPanel Cron Jobs!

cPanel Cron Jobs helps webmasters to run specific files at a specific time like every minute, hour, day, week etc. Webmasters can use this cPanel feature to take backup of their websites automatically because when we create a new cron job in cPanel it asks us to enter Linux command to run at specific time so it depends on webmasters that what they want to do or what they want to enter in the command field so cPanel Cron Jobs is the great feature to do a lot of things automatically which saves time.

How to Run PHP File Itself Automatically

So this tutorial is about that how we can run a PHP file itself automatically using cPanel Cron Jobs feature as I talked above that we can enter any Linux command to run at a specific time but this article is specially for PHP programmers who want to run PHP files automatically so let’s get started.

The first thing you need to do is to go to your website’s cPanel and there scroll down there you will see link to Cron Jobs in the Advance section.

cPanel Cron Jobs Feature

After clicking on that link you will see a new page there right below the heading Add New Cron Job you will see few boxes and in those boxes you have to type in the exact time when you want to run the PHP file, in the Common Settings you can select default time options like every minute, hour etc in the screen show below I have selected to run PHP file once an hour also see the last box where you have to type in the Linux command as you can see I have typed in php /home/hosting-username/public_html/test.php so you can clearly see if you are going to run a PHP file then you must type php before the command then mostly all the hosting service providers give you the same file directory structure just replace hosting-username with your hosting account username if you are not so sure about your directory structure then you can send support ticket in your web-hosting account, test.php means the file in your root directory which is public_html so first you have to upload the PHP file that you want to run then add this command.

Add New Cron Job in cPanel

Once you fill all the text boxes then press the button Add New Cron Job to save the settings and it is done.

Cron Job Is Not Working!

Sometimes it happens that cron job doesn’t work due to unknown problem as I am not a master in cPanel :P but I have  solution if you are cron job is not working then in the command field just type wget http://www.yourdomain.com/file.php and then save changes it will work without any trouble because it is just a Linux command to run any file so just replace URL without your own and that’s it.

Have Any Question?

If you still have any question regarding this tutorial then you must ask it in the comments below without any hesitation I will reply as soon as possible with your answer and if you like this tutorial then please share it.

Leave a Reply