User

Cron Job Examples

Ready-to-use cron job commands for common web hosting tasks in Opterius.

Last updated 1775606400

The examples below use /home/username/domain.com/ as the account home path. Replace username, domain.com, and PHP version with your own values. See Creating Cron Jobs for how to add these to your account.

[!NOTE] Always use absolute paths in cron commands. Cron runs with a minimal $PATH and relative paths will fail silently.


WordPress Cron

WordPress uses wp-cron.php for scheduled tasks (scheduled posts, plugin jobs, etc.). By default it runs on page load — calling it from a real cron job is more reliable.

Command:

/usr/bin/php8.3 /home/username/domain.com/public_html/wp-cron.php

Schedule: Every 15 minutes — */15 * * * *

[!TIP] Disable WP's built-in pseudo-cron by adding this to wp-config.php, then rely solely on the real cron job:

define('DISABLE_WP_CRON', true);

Laravel Task Scheduler

Laravel's scheduler dispatches all scheduled jobs from a single cron entry:

Command:

/usr/bin/php8.3 /home/username/domain.com/artisan schedule:run >> /dev/null 2>&1

Schedule: Every minute — * * * * *

Laravel's App\Console\Kernel (or routes/console.php in Laravel 11+) handles the actual job frequency internally.


Database Backup with mysqldump

Export a database to a dated file in your home directory:

Command:

/usr/bin/mysqldump -u username_dbuser -p'yourpassword' username_dbname | /bin/gzip > /home/username/backups/db_$(date +\%Y\%m\%d).sql.gz

Schedule: Daily at 3:00 AM — 0 3 * * *

[!IMPORTANT] The % character has special meaning in crontab and must be escaped as \% in commands written directly to the crontab file. The Opterius panel handles this escaping automatically when you enter the command through the UI.

To avoid a password in the command, create ~/.my.cnf with chmod 600:

[client]
user     = username_dbuser
password = yourpassword

Then shorten the command:

/usr/bin/mysqldump username_dbname | /bin/gzip > /home/username/backups/db_$(date +\%Y\%m\%d).sql.gz

Clear Laravel Cache

Useful after a deployment to clear config, route, and view caches:

Command:

/usr/bin/php8.3 /home/username/domain.com/artisan cache:clear && /usr/bin/php8.3 /home/username/domain.com/artisan config:cache

Schedule: Run manually as needed — or daily at off-peak hours if your app caches aggressively.


Run a Custom PHP Script

Command:

/usr/bin/php8.3 /home/username/domain.com/public_html/scripts/send-digest.php >> /home/username/logs/digest.log 2>&1

Schedule: Daily at 8:00 AM — 0 8 * * *


Download a Remote File

Fetch a remote data file (exchange rates, product feed, etc.) and save it locally:

Command:

/usr/bin/curl -s -o /home/username/domain.com/public_html/data/feed.xml https://example.com/feed.xml

Schedule: Hourly — 0 * * * *


Summary Table

Task PHP Version Suggested Schedule Crontab Expression
WordPress cron 8.3 Every 15 min */15 * * * *
Laravel scheduler 8.3 Every minute * * * * *
Database backup Daily at 3 AM 0 3 * * *
Clear Laravel cache 8.3 As needed manual
Custom PHP script 8.3 Daily at 8 AM 0 8 * * *
Download remote file Hourly 0 * * * *