一、准备
1、环境
系统平台:Red Hat Enterprise Linux Server release 7.3 (Maipo)
内核版本:3.10.0-514.el7.x86_64
2、下载安装包
http://php.net/downloads.php
3、安装相关依赖
# yum -y install gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel
三、安装
1、解压
# tar zxvf php-7.1.0.tar.gz
2、编译
# cd php-7.1.0
./configure \--prefix=/usr/local/php7 \ --with-config-file-path=/usr/local/php7/etc/ \--with-curl \--with-freetype-dir \--with-gd \--with-gettext \--with-iconv-dir \--with-kerberos \--with-libdir=lib64 \--with-libxml-dir \--with-mysqli \--with-openssl \--with-pcre-regex \--with-pdo-mysql \--with-pdo-sqlite \--with-pear \--with-png-dir \--with-xmlrpc \--with-xsl \--with-zlib \--with-zlib-dir \--with-mhash \--with-mcrypt \--with-openssl-dir \--with-jpeg-dir \--with-apxs2=/usr/local/apache/bin/apxs \--enable-gd-jis-conv \--enable-fpm \--enable-bcmath \--enable-libxml \--enable-inline-optimization \--enable-gd-native-ttf \--enable-mbregex \--enable-mbstring \--enable-opcache \--enable-pcntl \--enable-shmop \--enable-soap \--enable-sockets \--enable-sysvsem \--enable-xml \--enable-zip
可能出现的错误:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方法:安装 libmcrypt
地址:https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
再编译后出现以下错误:
configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
# vi /etc/ld.so.conf.d/local.conf
添加以下语句
/usr/local/lib
# ldconfig
再执行configure,编译通过
问题内容:
checking size of off_t... 0
configure: error: off_t undefined; check your library configuration解决方式:yum install libzip
4、安装
# make
# make install
5、测试是否安装成功
查看php版本
# /usr/local/php7/bin/php -v
显示版本信息,证明已安装成功
四、配置
1、配置php
1)配置php.ini
php.ini-development 适合开发测试,如本地测试环境, php.ini-production 拥有较高的安全性设定,适合服务器上线运营当产品。一般修改php.ini-production为php.ini,安全性更高,确保测试环境(本地)与正式环境(线上)一致。
# cd php-7.1.0
# cp php.ini-production /usr/local/php/etc/php.ini
2)配置fpm
# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
注意:php7中www.conf这个配置文件配置phpfpm的端口号等信息,如果你修改默认的9000端口号需在这里改,再改nginx的配置
# cp php-7.1.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
3)启动命令
/etc/init.d/php-fpm {start|stop|force-quit|restart|reload|status|configtest}
启动
# /etc/init.d/php-fpm start
重启
# killall php-fpm
# /etc/init.d/php-fpm start或者
/etc/init.d/php-fpm restart
2、配置apache,使其支持php
apache是把php作为自己的模块来调用的
1)配置 httpd.conf
AddType application/x-httpd-php .php (.前面有空格)
AddType application/x-httpd-php-source .phps (.前面有空格)
在最后添加如下配置
<FilesMatch \.php$>
SetHandler application/x-httpd-php</FilesMatch>2)编写
写一个php测试页info.php,放到 /usr/local/apache/htdocs 目录
1
3)重启apache
# /usr/local/apache/bin/apachectl -k restart
4)测试
3、配置nginx,使其支持php
Nginx是以fastcgi的方式结合php的,可以理解为nginx代理了php的fastcgi
1)配置
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name; include fastcgi_params;}
2)编写php代码
写一个php测试页info.php,放到apache/htdocs目录
1
3)重新加载nginx配置
# /usr/local/nginx/sbin/nginx -s reload
4)测试