Home  >  Article  >  Backend Development  >  How to solve the problem that the linux php -v command cannot be found

How to solve the problem that the linux php -v command cannot be found

藏色散人
藏色散人Original
2021-10-15 09:22:453153browse

linux php -v command cannot find the solution: 1. Find the location of the php file in linux; 2. Set the php environment variable in the environment variable file of the linux system; 3. Execute and update the environment variable Just order.

How to solve the problem that the linux php -v command cannot be found

The operating environment of this article: linux5.9.8 system, PHP5.4.26 version, DELL G3 computer

php command cannot be used under linux How to solve, test whether to add php environment variables:

is 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 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

Get the location of the bin directory of php as above. I use phpstudy integrated environment for linux

Then I need to go to the environment variable file of the linux system to set it PHP environment variables are similar to those in 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:

How to solve the problem that the linux php -v command cannot be found

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 How to solve the problem that the linux php -v command cannot be found. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn