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
*/5 * * * * php bin/schedule.php
FIXED — safer pattern
*/5 * * * * /usr/bin/php8.3 /srv/app/bin/schedule.php >>/srv/app/var/cron.log 2>&1
Step-by-step diagnosis
- As the cron user, verify the binary and script with test -x and test -r.
- Run the exact crontab command with a minimal environment.
- Record stderr and exit code to a protected log.
Fixes
Use absolute verified paths
Invoke the intended binary and application entry point explicitly.
*/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