PHP error guide

php command not found: meaning and fix

Error summary

Install or expose the intended PHP CLI binary and invoke its verified absolute path when multiple versions or restricted PATH values are involved.

What it means

Install or expose the intended PHP CLI binary and invoke its verified absolute path when multiple versions or restricted PATH values are involved.

What the error means

The shell cannot resolve an executable named php through its current PATH; the web server having PHP-FPM does not prove the CLI binary is installed.

Why PHP produces it

PHP CLI is absent, installed under a versioned name, or outside the invoking user’s executable search path.

PHP version notes

The behavior described for php command not found 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

  • Only PHP-FPM packages are installed.
  • The binary is versioned, such as php8.3, without a php alternative.
  • A restricted shell PATH omits the installation directory.

Minimal examples

BAD — reproduces the problem

shell
export PATH=.:$PATH
php task.php

FIXED — safer pattern

shell
/usr/bin/php8.3 /srv/app/bin/task.php

Step-by-step diagnosis

  1. Run command -v php and type -a php as the same user.
  2. Inspect installed PHP CLI packages without changing the web SAPI.
  3. Use the discovered binary to run php -v and php --ini.

Fixes

Use the verified CLI binary

Install the matching CLI package or configure the job with its absolute path.

shell
/usr/bin/php8.3 -v
/usr/bin/php8.3 /srv/app/bin/task.php

Common mistakes when fixing it

  • Changing the server-wide default PHP version for one script.
  • Adding the current directory to PATH.
  • Assuming which -a output from an interactive shell applies to cron.

How to prevent it

  • Record the intended absolute binary in deployment configuration.
  • Verify php -v and php --ini during deploy.
  • Keep site-specific version selection explicit.

Web server / environment notes

cli, linux. CLI packaging and PATH are independent from FPM service configuration.

Tags: cli,linux

Categories