Centos LNMP一键安装包 安装多PHP版本

背景

PHP进入7时代,部分项目未兼容PHP7,所以在原PHP5.4的版本上,新安装PHP7,实现php7和php5共存。

系统环境

Centos7.3
lnmp1.4(php5.4.45+mysql5.7.11)

编译安装PHP7.1.5

取lnmp1.4安装包中的PHP7包

1
2
3
4
5
6
wget -c --progress=bar:force http://cn2.php.net/distributions/php-7.1.5.tar.bz2
tar zxf php-7.1.5.tar.gz
cd php-7.1.5
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-config-file-scan-dir=/usr/local/php7/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-xsl
make ZEND_EXTRA_LIBS='-liconv'
make install

配置PHP7.0.7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
\cp php.ini-production /usr/local/php7/etc/php.ini
sed -i 's/post_max_size =.*/post_max_size = 50M/g' /usr/local/php7/etc/php.ini
sed -i 's/upload_max_filesize =.*/upload_max_filesize = 50M/g' /usr/local/php7/etc/php.ini
sed -i 's/;date.timezone =.*/date.timezone = PRC/g' /usr/local/php7/etc/php.ini
sed -i 's/short_open_tag =.*/short_open_tag = On/g' /usr/local/php7/etc/php.ini
sed -i 's/;cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/g' /usr/local/php7/etc/php.ini
sed -i 's/max_execution_time =.*/max_execution_time = 300/g' /usr/local/php7/etc/php.ini
sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /usr/local/php7/etc/php.ini
mkdir -p /usr/local/php7/conf.d
cat >/usr/local/php7/conf.d/002-zendguardloader.ini<<EOF
[Zend ZendGuard Loader]
;php7 do not support zendguardloader,after support you can uncomment the following line.
;zend_extension=/usr/local/zend/ZendGuardLoader.so
;zend_loader.enable=1
;zend_loader.disable_licensing=0
;zend_loader.obfuscation_level_support=3
;zend_loader.license_path=
EOF
cat >/usr/local/php7/etc/php-fpm.conf<<EOF
[global]
pid = /usr/local/php7/var/run/php-fpm.pid
error_log = /usr/local/php7/var/log/php-fpm.log
log_level = notice
[www]
listen = /tmp/php7-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow7.log
EOF

php7-fpm设为系统服务

1
2
3
4
\cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
chmod +x /etc/init.d/php7-fpm
/etc/init.d/php7-fpm start
chkconfig --add php7-fpm

创建enable-php7.conf脚本

1
2
cp /usr/local/nginx/conf/enable-php.conf /usr/local/nginx/conf/enable-php7.conf
vi /usr/local/nginx/conf/enable-php7.conf


fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_pass unix:/tmp/php7-cgi.sock;

1
2
cp /usr/local/nginx/conf/enable-php-pathinfo.conf /usr/local/nginx/conf/enable-php7-pathinfo.conf
vi /usr/local/nginx/conf/enable-php7-pathinfo.conf


fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_pass unix:/tmp/php7-cgi.sock;

修改vhost的conf文件使用PHP7

1
vi /usr/local/nginx/conf/vhost/xxxxxx.conf


include enable-php.conf;

include enable-php7.conf;

修改lnmp脚本(/usr/bin/lnmp)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
PHPFPMPIDFILE=/usr/local/php/var/run/php-fpm.pid
PHP7FPMPIDFILE=/usr/local/php7/var/run/php-fpm.pid
/etc/init.d/php-fpm start
/etc/init.d/php7-fpm start
/etc/init.d/php-fpm stop
/etc/init.d/php7-fpm stop
/etc/init.d/php-fpm reload
/etc/init.d/php7-fpm reload
killall php-fpm
killall php7-fpm
lnmp_status()
{
/etc/init.d/nginx status
if [ -f $PHPFPMPIDFILE ]; then
echo "php-fpm is runing!"
else
echo "php-fpm is stop!"
fi
if [ -f $PHP7FPMPIDFILE ]; then
echo "php7-fpm is runing!"
else
echo "php7-fpm is stop!"
fi
/etc/init.d/mysql status
}
文章目录
  1. 1. 背景
  2. 2. 系统环境
    1. 2.1. 编译安装PHP7.1.5
    2. 2.2. 配置PHP7.0.7
    3. 2.3. php7-fpm设为系统服务
    4. 2.4. 创建enable-php7.conf脚本
    5. 2.5. 修改vhost的conf文件使用PHP7
    6. 2.6. 修改lnmp脚本(/usr/bin/lnmp)