-bash: php: command not found
Introduction
The error “bash: php: command not found” occurs when the system cannot locate the PHP binary. This usually happens because the PHP path is not included in the $PATH variable.
Prerequisites
- Root or SSH access
- Basic knowledge of Linux commands
- Access to .bash_profile
Implementation
bash: php: command not found
[root@01 ~]# php -v
-bash: php: command not found
[root@01 ~]#
A common type of message you can see on H-Sphere servers. These kinds of command-line messages are displayed because the PATH variable was not specified in the .bash_profile file.
The $PATH variable is a list of directories Red Hat will look in for executable files.
To edit the bash_profile, vi .bash_profile, then arrow down until you find the line that looks similar to “PATH=$PATH:$HOME/bin”
and add the location of the PHP binary to the above line in the .bash_profile file.
To get the path of PHP, you can use the following command:
ps aux | grep php
Please note that the ‘which php’ command will not work as the PATH is not specified.
Conclusion
By adding the correct PHP binary path to the $PATH variable in .bash_profile, the system will recognise the php command and execute it successfully.
