If you see the error "Bash: php: command not found" when trying to run the
php command on your system, it means that the PHP command line interface (CLI) is not installed on your system or is not added to your system's
PATH environment variable.
To fix this error, you can try the following steps:
Check if PHP is installed on your system by running the
php --versioncommand. If you see a message with the PHP version, it means that PHP is installed on your system but is not added to your
PATHenvironment variable. PHP is not installed on your system if you don't see any output or an error message.
If PHP is not installed on your system, you can install it by following the instructions on the PHP website or using your system's package manager. For example, on Ubuntu, you can use the following commands to install PHP:
sudo apt update sudo apt install php
If PHP is installed on your system, but it is not added to your
PATHenvironment variable, you can add it to your
PATHby modifying your
~/.bash_profilefile and adding the following lines to the end of the file:
/path/to/php/bin is the path to the directory where the
php executable is located. This directory is usually
After modifying your
~/.bash_profilefile, run the
sourcecommand to reload the file and update your
Try rerunning the php command and see if the error message disappears. If you still see the error message, you may need to log out of your system and log back in for the changes to take effect.
Bash: php: command not found for Mac os users
If you are using a Mac, installing and configuring PHP on your system may be slightly different from the steps described above. However, the overall process should be similar.
To install PHP on a Mac, you can use the built-in package manager called Homebrew. First, you will need to install Homebrew by following the instructions on the Homebrew website. Once Homebrew is installed, you can use the following commands to install PHP:
brew update brew install php
After installing PHP, you must add it to your
PATH environment variable to run the
php command from the terminal. To do this, open your
~/.bash_profile file in a text editor and add the following line to the end of the file:
Save the file and run the
source command to reload your
~/.bash_profile file and update your
PATH environment variable:
You should now be able to run the
php command from the terminal.