CloudLinux

Run cron jobs with the right PHP version on CloudLinux

Make cPanel cron jobs use the same PHP version as your website on CloudLinux: correct binary paths, wget versus PHP CLI, logging output and fixing cron errors.

IntermediatecPanel hosting with CloudLinux3 min read

A cron job that works in your browser can fail from cron with errors such as "unexpected token" or "missing extension". The usual cause is that cron runs a different PHP version than your website. On CloudLinux you can choose the exact PHP binary.

Before you start

  • cPanel access with Cron Jobs in cPanel → Advanced.
  • The PHP version your site uses, from Select PHP Version (see changing PHP version).

How PHP is chosen in cron

  • Cron jobs run inside your CageFS, so the plain php command follows your Select PHP Version choice on most CloudLinux servers.
  • If the domain is pinned to a MultiPHP version, or your server is configured differently, php may still be another version (see PHP Selector vs MultiPHP).
  • Calling the full path removes all doubt.

Use the full PHP path

CloudLinux PHP versions live in /opt/alt/phpXX/usr/bin/php, where XX is the version without the dot. For PHP 8.2:

/opt/alt/php82/usr/bin/php /home/username/public_html/cron.php

Check which version a path runs from cPanel → Advanced → Terminal:

/opt/alt/php82/usr/bin/php -v

Add the cron job

  1. Go to cPanel → Advanced → Cron Jobs.
  2. Choose a schedule, for example Once Per Fifteen Minutes.
  3. Enter the command with the full PHP path, as above.
  4. Click Add New Cron Job.

WordPress example

After setting define('DISABLE_WP_CRON', true); in wp-config.php, run WordPress cron every 15 minutes:

/opt/alt/php82/usr/bin/php -q /home/username/public_html/wp-cron.php >/dev/null 2>&1

This avoids running cron on visitor page loads, which helps prevent 508 errors.

Log output while testing

Send output to a file instead of discarding it, so you can read errors:

/opt/alt/php82/usr/bin/php /home/username/public_html/cron.php >> /home/username/cron.log 2>&1

Remove the logging once it works, or the file keeps growing.

Note: Cron jobs count against your CloudLinux limits like any other process. Heavy jobs every minute can cause faults; schedule them less often or at quiet times.

Troubleshooting

"Could not open input file"

The script path is wrong. Use the absolute path starting with /home/username/.

Missing extension errors

The extension is enabled for one PHP version but cron uses another. Use the matching path, or enable the extension for that version (see PHP extensions).

wget or curl crons return 403

URL-based crons can be blocked by security rules or caching. Prefer the PHP CLI method above.

Frequently asked questions

How often may a cron job run?

Every 15 minutes or less often is good practice on shared hosting. Every-minute jobs add load and can hit limits.

Does the cron command get my php.ini options?

It uses the options set for that PHP version in Select PHP Version. CLI may have a different max_execution_time, which is usually unlimited.

Where do cron emails go?

cPanel emails cron output to the address set at the top of the Cron Jobs page. Add >/dev/null 2>&1 to stop emails once the job works.

Can I run Node.js or Python scripts from cron?

Yes. Use the virtual environment's binary path shown on the app page in Setup Node.js App or Setup Python App.

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.