Skip to content
php: command not found

php: command not found

DodaTech 2 min read

The “php: command not found” error means your shell cannot locate the PHP binary. This usually happens when PHP is not installed or its directory is not in your system’s PATH variable.

What It Means

When you type php in your terminal, the shell searches through the directories listed in your PATH environment variable. If no directory contains a php executable, you get “command not found.” On Windows, the message may appear as “php is not recognized as an internal or external command.”

Why It Happens

  • PHP is not installed on your system.
  • PHP is installed but the binary’s directory (e.g., /usr/local/bin or C:\php) is not in your PATH.
  • You installed PHP via a package manager but forgot to add it to the environment variables.
  • The installed PHP version is incompatible with your OS architecture.
  • You are using a shared hosting environment where PHP is available only through a different command like php81 or php8.2.

How to Fix It

1. Install PHP via your package manager

Ubuntu / Debian:

sudo apt update && sudo apt install php

macOS (Homebrew):

brew install php

Windows: Download the PHP ZIP package from windows.php.net and extract it to C:\php.

2. Add PHP to your PATH

Linux / macOS: Add this to your ~/.bashrc or ~/.zshrc:

export PATH="$PATH:/usr/local/bin"

Then reload with source ~/.bashrc.

Windows: Go to System Properties → Environment Variables and add C:\php to the Path variable.

3. Verify the installation

php -v

You should see output like PHP 8.3.x with version details.

4. Use the full path as a workaround

If you cannot modify PATH, run PHP with its full path:

/usr/bin/php script.php
I installed PHP but still get “command not found”
After installation, you may need to restart your terminal or run hash -r (Linux) / rehash (macOS) to clear the command cache.
What if my hosting provider doesn’t allow me to install PHP?
Most shared hosts provide PHP through a different binary name (like php82). Run which php82 or contact your hosting provider.
How do I check if PHP is already on my system?
Run which php (Linux/macOS) or where php (Windows). If it returns a path, PHP is installed but not in your standard shell PATH.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro