PHP error guide

Cron uses the wrong PHP path: meaning and fix

Error summary

Put the verified absolute PHP binary and script path in the crontab, then capture stderr and the exit status.

What it means

Put the verified absolute PHP binary and script path in the crontab, then capture stderr and the exit status.

What the error means

The scheduled shell cannot execute the configured PHP path, so the PHP script never starts.

Why PHP produces it

The crontab copied a path from another host, relies on interactive PATH lookup, or points at a removed PHP version.

PHP version notes

The behavior described for Cron uses the wrong PHP path applies to PHP 7.4–8.4 unless a narrower version is stated; exact wording can vary by SAPI and patch release.

Most common causes

  • The PHP CLI binary moved after an upgrade.
  • Cron has a minimal PATH.
  • A relative script path resolves from an unexpected working directory.

Minimal examples

BAD — reproduces the problem

shell
*/5 * * * * php bin/schedule.php

FIXED — safer pattern

shell
*/5 * * * * /usr/bin/php8.3 /srv/app/bin/schedule.php >>/srv/app/var/cron.log 2>&1

Step-by-step diagnosis

  1. As the cron user, verify the binary and script with test -x and test -r.
  2. Run the exact crontab command with a minimal environment.
  3. Record stderr and exit code to a protected log.

Fixes

Use absolute verified paths

Invoke the intended binary and application entry point explicitly.

shell
*/5 * * * * /usr/bin/php8.3 /srv/app/bin/schedule.php >>/srv/app/var/cron.log 2>&1

Common mistakes when fixing it

  • Changing the system PHP alternative for one cron job.
  • Discarding stderr to /dev/null during diagnosis.
  • Using a web URL as a substitute for a protected CLI task.

How to prevent it

  • Verify scheduled command paths during deploy.
  • Monitor non-zero exits and stale run timestamps.
  • Keep site jobs version-pinned.

Web server / environment notes

cron, cli, linux. Cron does not inherit the interactive shell’s full setup.

Tags: cron,cli,linux

Categories