How to solve the problem that the php command cannot be used under Linux

小云云
Release: 2023-03-21 09:28:01
Original
2649 people have browsed it

This article mainly shares with you 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
Copy after login

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
Copy after login

As above, get the location of the bin directory of php. 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
Copy after login

under the root directory/ Then start editing the configuration file of the environment variables

As shown in the figure:

Will find the bin directory of php Put the path here and add these two lines of code;

If you need to add other environment variables, just find the directory where the executable file is located, append a colon (":") and the directory, then save and Exit

执行更新环境变量命令:

[root@iz8vbhc4d7zoazstpw7gw8z /]# source /etc/profile    

 然后再输入php -v 就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    

好使!
Copy after login

The above is the detailed content of How to solve the problem that the php command cannot be used under Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!