说明
一个apache服务器内可以同时安装php5和php7,但是只能运行其中一个,另外一个需要注释掉apache配置文件内对应的LoadModule
1,下载并安装
[root@dl-001 src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.gz
[root@dl-001 src]# tar -zxvf php-7.1.6.tar.gz
[root@dl-001 src]# cd php-7.1.6
2,初始化
[root@dl-001 php-7.1.6]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
说明:php7内已经移除了–with-mysql参数
错误1
configure: error: xml2-config not found. Please check your libxml2 installation.
说明:缺少xml2库。
解决办法:
[root@dl-001 php-5.6.30]# yum list |grep libxml2 //查找相关的库安装包
[root@dl-001 php-5.6.30]# yum install -y libxml2-devel //安装库文件
错误2
configure: error: Cannot find OpenSSL's <evp.h>
说明:缺少OpenSSL’s。
解决办法
[root@dl-001 php-5.6.30]# yum install -y openssl-devel
错误3
configure: error: Please reinstall the BZip2 distribution
说明:重新安装BZip2。
解决办法
[root@dl-001 php-5.6.30]# yum install -y bzip2-devel
错误4
configure: error: jpeglib.h not found.
说明:缺少jpeg库。
解决办法
[root@dl-001 php-5.6.30]# yum install -y libjpeg-devel
错误5
configure: error: png.h not found.
说明:缺少png库。
解决办法
[root@dl-001 php-5.6.30]# yum install -y libpng-devel
错误6
configure: error: freetype-config not found.
说明:缺少freetype库。
解决办法
[root@dl-001 php-5.6.30]# yum install -y freetype-devel
错误7
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
说明:缺少mcrypt库。
解决办法
[root@dl-001 php-5.6.30]# yum install epel-release
[root@dl-001 php-5.6.30]# yum install -y libmcrypt-devel
3,编译安装
[root@dl-001 php-7.1.6]# make //编译
[root@dl-001 php-7.1.6]# make install //安装
PHP说明:
查看apache生成php7模块
[root@dl-001 src]# ls /usr/local/apache2.4/modules/libphp7.so
查看php7所加载的模块
[root@dl-001 src]# /usr/local/php7/bin/php -m
apache服务器可以存在2种版本的php,通过在apache的配置文件中注释掉相应的行来关闭某个版本的php模块
[root@dl-001 src]# vim /usr/local/apache2.4/conf/httpd.conf
在LoadModule行前加#注释