ZSH: command not found: php

ZSH: command not found: php

If you see the error "zsh: command not found: php" when you run the php command in a terminal, it means that the php command is unavailable in your current path. This can happen if you have not installed PHP on your system or if the PHP binary is not in a directory that is included in your PATH environment variable.

To fix this error, you can either install PHP on your system or you can modify your PATH environment variable to include the directory where the php binary is located. For example, if PHP is installed in the /usr/local/bin directory, you can add this directory to your PATH variable by running the following command:

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

After modifying your PATH variable, you should be able to run the php command without any errors.

Note: If you are using the zsh shell, you may need to modify your .zshrc file instead of your PATH variable to add the php binary to your path permanently. You can add the export command shown above to your .zshrc file, which is located in your home directory.

How to install PHP

To install PHP on your system, you will need to download the PHP binary from the official PHP website and install it on your computer. The exact steps for installing PHP will vary depending on your operating system and the method you use to download and install PHP.

Here are the general steps for installing PHP on a computer running a Unix-like operating system like Linux or macOS:

  1. Download the PHP binary from the official PHP website: https://www.php.net/downloads.php

  2. Extract the downloaded file to a directory on your computer, such as /usr/local/php.

  3. Add the php binary to your PATH environment variable. This will allow you to run the php command from any directory on your system.

  4. Verify that PHP is installed correctly by running the php -v command in a terminal. This should display the version of PHP installed on your system.

If you are using a Windows operating system, you can download a PHP installer from the official PHP website and use it to install PHP on your computer. The PHP installer will automatically add the php binary to your PATH environment variable, so you can run the php command from any directory on your system.

Note: If you are using a Linux distribution, you may be able to install PHP using your distribution's package manager. For example, on Ubuntu, you can use the apt-get command to install PHP:

sudo apt-get install php

This will install the latest version of PHP and any dependencies required by PHP. A package manager can make installing and managing PHP on your system easier.
How to install PHP using brew

To install PHP using Homebrew, you must have Homebrew installed on your system. Homebrew is a package manager for macOS that allows you to install and manage software on your computer easily.

If you do not have Homebrew installed, you can install it by following these steps:

  1. Open a terminal on your computer.

  2. Run the following command to install Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  1. Follow the on-screen instructions to complete the installation of Homebrew.

Once you have Homebrew installed, you can use it to install PHP by running the following command in a terminal:

brew install php

This will install the latest version of PHP and any dependencies required by PHP. After the installation is complete, you can run the php command to use PHP on your system.

Note: If you want to install a specific version of PHP, you can use the brew search command to search for available versions of PHP, and then use the brew install command to install the version you want. For example, to install PHP 7.4, you can run the following command:

brew install [email protected]

This will install PHP 8.1 and any dependencies required by PHP. You can then use the php command to run PHP scripts and use PHP on your system.

Useful links:

brew

PHP

Related articles

Ruslan Osipov
Written by author: Ruslan Osipov