运维日常:Linux调用双版本PHP
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了运维日常:Linux调用双版本PHP相关的知识,希望对你有一定的参考价值。
1.当前系统状态
[[email protected] ~]# php -v
PHP 5.6.31 (cli) (built: Nov 24 2017 12:37:03)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
[[email protected] ~]# uname -r
3.10.0-693.5.2.el7.x86_64
2.下载解压软件包
wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
tar -xf php-7.1.6.tar.bz2
cd php-7.1.6
3.安装环境包,保证服务器的gcc和g++环境yum -y install libxml2 libxml2-devel openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel
4.预编译,检查环境./configure --prefix=/usr/local/php7 --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-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --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-sysvshm --enable-xml --enable-zip
5.编译安装
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
make ZEND_EXTRA_LIBS=‘-liconv‘
make install
6.配置相关php文件(/usr/local/php7是安装目录,区别原来的PHP版本)
cp php.ini-development /usr/local/php7/lib/php.ini
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp sapi/fpm/php-fpm /usr/local/bin/php7-fpm
7.设置php.ini文件
vim /usr/local/php7/lib/php.ini
cgi.fix_pathinfo=0
打开php配置文件找到cgi.fix_pathinfo配置项,这一项默认被注释并且值为1,根据官方文档的说明,这里为了当文件不存在时,阻止nginx将请求发送到后端的PHP-FPM模块,从而避免恶意脚本注入的×××,所以此项应该去掉注释并设置为0
8.查看启动进程管理用户
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
vim /usr/local/php7/etc/php-fpm.d/www.conf
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user‘s group
; will be used.
user = nobody
group = nobody
9.启动php-fpm服务
/usr/local/bin/php7-fpm
[[email protected] ~]# netstat -tunlp |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 23384/php-fpm: mast
10.设置nginx调用PHP7
vim /usr/local/nginx/conf/vhost/linuxview.conf
location ~ .php$ {
#不能有下面这句 try_files ,不然报错500
# try_files $uri /index.php =404;
# fastcgi_split_path_info ^(.+.php)(/.+)$;
# root html;
#这句注意 后面是127.0.0.1,不然调用不了
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
11.重加载nginx服务
nginx -s reload
nginx:这个便捷命令是/usr/local/nginx/sbin/nginx 的别名,
命令如下:建议写入环境变量文件。
alias nginx=/usr/local/nginx/sbin/nginx
以上是关于运维日常:Linux调用双版本PHP的主要内容,如果未能解决你的问题,请参考以下文章
Linux双因素身份认证大全:ssh + console + 图形界面