The solution to the problem that Linux cannot recognize the PHP command: 1. Go to Linux to find the location of the PHP file of the integrated environment; 2. Set the PHP environment variable; 3. Execute the update environment variable command.
The operating environment of this article: linux5.9.8 system, PHP5.4.26 version, DELL G3 computer
linux cannot recognize the php command. What to do?
How to solve the problem that the php command cannot be used under Linux, test whether to add the php environment variable method:
As follows: Enter php -v to display the php command not found
[root@iz8vbhc4d7zoazstpw7gw8z ~]# php -v -bash: php: command not found
1. First go to linux to find the location of the php file of the integrated environment
[root@iz8vbhc4d7zoazstpw7gw8z /]# cd phpstudy/server/php/ [root@iz8vbhc4d7zoazstpw7gw8z php]# ls bin do_not_delete etc include lib php sbin var [root@iz8vbhc4d7zoazstpw7gw8z php]# cd bin/ [root@iz8vbhc4d7zoazstpw7gw8z bin]# ls phar phar.phar php php-cgi php-config phpize [root@iz8vbhc4d7zoazstpw7gw8z bin]# pwd /phpstudy/server/php/bin
Obtain the location of the php bin directory as above. I use phpstudy integrated environment for linux
Then you need to go to the environment variable file of the Linux system to set the PHP environment variables, similar to Windows. The file is in the etc
[root@iz8vbhc4d7zoazstpw7gw8z ~]# cd /[root@iz8vbhc4d7zoazstpw7gw8z /]# vim etc/profile
under the root directory/ and then start editing the configuration file of the environment variables
As shown in the figure:
will be found Put the path to the bin directory of php and add these two lines of code here;
If you need to add other environment variables, just find the directory where the executable file is located, append a colon (":") and the directory. Okay, then save and exit
Execute the update environment variable command:
[root@iz8vbhc4d7zoazstpw7gw8z /]# source /etc/profile
Then enter php -v and it will be OK
[root@iz8vbhc4d7zoazstpw7gw8z /]# php -vPHP 5.4.26 (cli) (built: Sep 7 2017 12:52:40)Copyright (c) 1997-2014 The PHP GroupZend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies
It works!
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What should I do if linux cannot recognize the php command?. For more information, please follow other related articles on the PHP Chinese website!