本文参考http://www.jb51.net/article/109228.htm文章,并在安装过程中出现的问题加入解决方法。
系统CentOS6.5
首先升级YUM仓
yum install epel-release //扩展包更新包
yum update //更新yum源
安装PHP依赖环境
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
安装HTTPD
yum -y install httpd httpd-devel #这里必须加上HTTPD扩展,如果不加编译安装PHP时会报错
下载php
wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror
解压
tar -zxvf php7.tar.gzmv php7.1.1 phpcd php
配置PHP
./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-apxs2=/usr/sbin/apxs --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
编译安装make && make install
配置环境变量vim /etc/profile
在最下方加入PATH=$PATH:/usr/local/php/bin
export PATH使配置立即生效
source /etc/profile配置php-fpmcp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm添加nginx用户 因为/usr/local/php/etc/php-fpm.d/www.conf文件中对用户和组为nginx的关系
useradd nginx启动php-fpm
service php-fpm start修改httpd.conf文件
vim /etc/httpd/conf/httpd.conf在AddType application*后面加如下一行
AddType application/x-httpd-php .php .phtml在DirectoryIndex index.html加上index.php
DirectoryIndex index.php index.html确保httd.conf文件中包含以下字段,如不包含则加入此字段
LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so重启HTTPD
service httpd restart