You can have DreamHost automatically configure a cron job in the panel on the Cron Jobs page. This article contains the following contents.
- Creating a cron job in the panel
- Running a cron job from a URL with variables
- Paths to common programs
When creating the cron job, you must assign it to a shell user in your panel. Only shell users are able to run cron jobs.
Cron jobs can be created on any hosting plan.
Creating a cron job in the panel
This example runs a single file named script.php.
- Navigate to the Cron Jobs page.
- The Cron Jobs page appears:
- Click the Add New Cron Job button.
- The Creating New Cron Job page opens:
- To create the cron, fill in the following fields:
- User: From the dropdown menu choose an existing shell user you'd like the cron job to run under.
- Title: Give the cron job a name you'll remember.
- Email output to: Enter an email address you'd like to receive the cron output to. You can also leave this blank to not receive emails.
- Command to run: Enter the command to run.
The command you enter usually must first specify the path to the program you'd like to use to run the cron job. View the 'Paths to common programs' below for examples. For example let's say you have a PHP file named script.php in your domains directory:
To run this command you'd enter the path to your chosen version of PHP followed by a space, followed by the path to the file:
- /usr/local/php74/bin/php /home/username/example.com/script.php
- Use locking: Enabling this if you want to prevent the job from running more than once at a time.
- When to run: From the dropdown menu, choose how often you'd like this job to execute.
The time you choose should be PDT/PST since this is the timezone your webserver is set to. To figure out the correct time you can either log into your server via SSH and run the command date, or you can check a website that lists this information.
It's currently only possible to add 12 different minutes within an hour. You can arrange these how you like, but the cron can run no more than 12 times within a single hour.
The 'Day of Week' and 'Day of Month' fields
When the 'Day of Week' field overrides the 'Day of Month'
The Day of Week field will override the Day of Month field only if the Day of Month field is set to Every Day. For example, the following configuration would only run on Thursdays.
When the 'Day of Week' field does NOT override the 'Day of Month'
The Day of Week field will NOT override the Day of Month field if the Day of Month field is set to a specific day(s). They will then run together.
In the example below, the Day of Week field is set to run at 3:44 pm Thursday. The Day of Month field is also set for the 26th (which is a Wednesday). The cron job will still run every Thursday, but also on the 26th of the month.
Running a cron job from a URL with variables
It's common for a custom URL in your site to use variables. For example:
The problem is that the variables only work in a web browser when visiting the URL. They will not function when running the URL on the server. There are two ways you can have a cron job run such a URL.
Using curl or wget
When running curl or wget on a URL with variables, make sure to enclose the URL in single quotes.
Here's how it would look in the panel.
The other option is to use php.cgi instead of the path to PHP. When creating the URL, you must change the first ? sign into a space, and every & after that into a space. For example:
Path to original file and URL
Edited path to file and URL
/home/username/example.com/script.php firstname=john lastname=doe
Finally, add the path to the php.cgi binary.
/dh/cgi-system/php74.cgi /home/username/example.com/script.php firstname=john lastname=doe
Here's how it would look in the panel.
Paths to common programs
Below are the paths to common programs on the server. This is the path you would add before the file you wish to run.