Add a Cron Job in cPanelAA-00306KB: How to Create a Cron Job in cPanelA cron job is a command that schedules scripts or commands to run automatically on your server at a specified time and date. This is useful for automating repetitive tasks like backups, sending newsletters, or cleaning up temporary files. Here is a guide on how to create a cron job in cPanel. Step 1: Access the Cron Jobs Interface
Step 2: Configure the Cron Job ScheduleIn the Add New Cron Job section, you will define the schedule for your task. You can use the "Common Settings" dropdown to choose a predefined schedule, or you can manually set the time using the fields for Minute, Hour, Day, Month, and Weekday.
For example, to run a script every day at 3:00 AM, you would set:
Step 3: Enter the CommandIn the Command field, enter the command you want to execute. The command needs to specify the program to run and the path to your script. Below are two common examples. Example 1: Executing a PHP ScriptTo run a PHP script directly on the server, use the PHP interpreter path followed by the script's path. This method is efficient as it doesn't involve a web server request. Replace Example 2: Running a Script as a Browser WouldIf your script requires a web server environment or is designed to be executed as if a browser were visiting it, you can use a command-line browser like Step 4: Add the Cron JobAfter setting the schedule and entering the command, click the Add New Cron Job button. The cron job will now be active and will run according to your specified schedule. You can view all your active cron jobs in the Current Cron Jobs section. From there, you can edit or delete them as needed. |