解决CentOS7安装php7.2之后php -v显示的版本是5.4的问题

1.查找系统里PHP相关的目录或文件

find / -name php

/var/lib/php
/usr/bin/php
/usr/lib64/php
/usr/share/swig/2.0.10/php
/usr/share/php
/usr/include/php-zts/php
/usr/include/php
/usr/local/bin/php
/usr/local/include/php
/usr/local/lib/php
/usr/local/php

/selftemp/php-5.4.17/ext/pcntl/sapi/cli/php

2.查看列出的php的版本信息

/usr/local/bin/php -v

PHP 5.4.17 (cli) (built: Sep 21 2017 10:27:13) 
Copyright (c) 1997-2013 The PHP Group

Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

/usr/bin/php -v

PHP 7.2.6 (cli) (built: Jun  2 2018 07:49:42) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.6, Copyright (c) 1999-2018, by Zend Technologies

3.因为5.4.17版本php在/usr/local/bin/下,所以删除/usr/local/bin/目录下的所有PHP相关的目录或文件

cd /usr/local/bin/

ls

courierauthconfig  c_rehash  parl     par.pl  peardev  phantomjs  phar.phar  php-cgi     phpize  scandeps.pl  zipdetails

crc32              openssl   parldyn  pear    pecl     phar       php        php-config  pp      tkpp

rm -rf ./php

rm -rf ./php-cgi

rm -rf ./php-config

4.环境变量中加上正确PHP版本的路径
vim /etc/profile
文件末尾加上 export PATH="/usr/local/php/bin:$PATH"

5.执行

source /etc/profile

6.如果不出错则再次查看php版本如果是7则说明成功了

php -v

PHP 7.2.6 (cli) (built: Jun  2 2018 07:49:42) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

with Zend OPcache v7.2.6, Copyright (c) 1999-2018, by Zend Technologies

7.如果报错没有sokcet函数,stream_socket_server() has been disabled for security...

编辑php.ini把disable_functions=...中找到stream_socket_server()、stream_socket_client,删除掉,重新启动web组件

----------------------------------------------------------------------------------------------------

其他可能用到的知识点:

查找php.ini配置文件 :find / -name php.ini

/etc/php.ini

查看PHP加载的是哪个配置文件,这个获取的是系统内的php.ini 的位置。不是网页apache加载的php.ini文件
php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/lib

你可能感兴趣的:(Linux)