PHP官网www.php.net
; 当前主流版本为5.6/7.1php
[root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz [root@localhost src]# tar -zxvf php-5.6.30.tar.gz
# libmcrypt-devel包在epel仓库内,若是系统内尚未安装过epel仓库,执行yum install -y epel-release进行安装 #[root@localhost php-5.6.30]# yum install -y epel-release [root@localhost php-5.6.30]# yum install -y libxml2-devel openssl-devel bzip2-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel [root@localhost php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --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 [root@localhost php-5.6.30]# echo $? 0 [root@localhost php-5.6.30]# make [root@localhost php-5.6.30]# make install
查看php编译信息mysql
[root@localhost php-5.6.30]# /usr/local/php/bin/php -i # 正常状况下使用php.ini-production,开发环境能够使用php.ini-development [root@localhost php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini
php软件是以模块的形式安装进apache的,在/usr/local/apache2.4/conf/httpd.conf文件内的sql
查看php是否被apache加载apache
[root@localhost php-5.6.30]# cat /usr/local/apache2.4/conf/httpd.conf | grep php LoadModule php5_module modules/libphp5.so
一个apache服务器内能够同时安装php5和php7,可是只能运行其中一个,另一个须要注释掉apache配置文件内对应的LoadModule行vim
下载、安装PHP7服务器
[root@localhost src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.gz [root@localhost src]# tar -zxvf php-7.1.6.tar.gz
编译安装php7
# php7内已经移除了--with-mysql参数 [root@localhost src]# ./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 [root@localhost src]# make && make install
apache生成php7模块socket
[root@localhost src]# ls /usr/local/apache2.4/modules/libphp7.so
查看php7所加载的模块ui
[root@localhost src]# /usr/local/php7/bin/php -m
apache服务器能够存在2种版本的php,经过在apache的配置文件中注释掉相应的行来关闭某个版本的php模块spa
[root@localhost src]# vim /usr/local/apache2.4/conf/httpd.conf 在LoadModule行前加#注释
编译时没法执行apxs脚本
Sorry, I cannot run apxs. Possible reasons follow: 1. Perl is not installed 2. apxs was not found. Try to pass the path using --with-apxs2=/path 3. Apache was not built using --enable-so (the apxs usage page is di The output of /usr/local/apache/bin/apxs follows: ./configure: /usr/local/apache/bin/apxs: /replace/with/path/to/perl/ configure: error: Aborting
解决方法:
该报错是因为perl解释器路径无效 -- “/replace/with/path/to/perl/” 修改/usr/local/apache/bin/apxs文件,将首行改成#!/usr/bin/apxs -w
相关依赖包未安装
configure: error: xml2-config not found. Please check your libxml2 installation. 解决:安装libxml2包 yum install -y libxml2-devel
configure: eror: Cannot find OpenSSL's <evp.h> 解决:安装openssl包 yum install -y openssl-devel
configure: error: Please reinstall the BZip2 distribution 解决:安装bzip2包 yum install -y bzip2-devel
configure: error: jpeglib.h not found. 解决:安装libjpeg包(libjpeg-turbo-devel) yum install -y libjpeg-devel
configure: error: png.h not found. 解决:安装libpng包 yum install -y libpng-devel
configure: error: freetype-config not found. 解决:安装freetype包 yum install -y freetype-devel
缺乏libmcrypt包
configure: error: mcrypt.h not found. Please reinstall libmcrypt. 解决:安装libmcrypt包(在epel扩展源内,未安装需yum install -y epel-release) yum install -y libmcrypt-devel