先安装 php7,正常安装

php7.2 安装完成后,进行 php5.6 的安装

安装 php5

[root@VM_0_2_centos ~]# cd ~
[root@VM_0_2_centos ~]# wget -c http://cn2.php.net/distributions/php-5.6.30.tar.gz
[root@VM_0_2_centos ~]# tar -zxvf php-5.6.30.tar.gz
[root@VM_0_2_centos ~]# cd php-5.6.30/
[root@VM_0_2_centos php-5.6.30]# ./configure  --prefix=/usr/local/php5 --enable-fpm --with-mysql  --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo
[root@VM_0_2_centos php-5.6.30]# make

make 可能会报错:make: *** [sapi/cli/php] error 1 ,

则使用

[root@VM_0_2_centos php-5.6.30]# make clean
[root@VM_0_2_centos php-5.6.30]# make ZEND_EXTRA_LIBS='-liconv'

安装

[root@VM_0_2_centos php-5.6.30]# make install

复制 php 配置文件

[root@VM_0_2_centos php-5.6.30]# cp php.ini-production /usr/local/php5/etc/php.ini

已经安装完成,查看版本号

[root@VM_0_2_centos php-5.6.30]# /usr/local/php5/bin/php -v

返回

PHP 5.6.30 (cli) (built: Aug 29 2018 09:09:28) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

配置 php-fpm

[root@VM_0_2_centos php-5.6.30]# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
[root@VM_0_2_centos php-5.6.30]# vim /usr/local/php5/etc/php-fpm.conf

查找 user 将

user = nobody
group = nobody

改成

user = nginx
group = nginx

查找 listen 将

listen = 127.0.0.1:9000

改成

listen = 127.0.0.1:9001

配置 php-fpm 服务

[root@VM_0_2_centos php-5.6.30]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php5-fpm.service
[root@VM_0_2_centos php-5.6.30]# vim /usr/lib/systemd/system/php5-fpm.service 

将:

PIDFile=${prefix}/var/run/php-fpm.pid
ExecStart=${exec_prefix}/sbin/php-fpm --nodaemonize --fpm-config ${prefix}/etc/php-fpm.conf

改成

PIDFile=/usr/local/php5/var/run/php-fpm.pid
ExecStart=/usr/local/php5/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php5/etc/php-fpm.conf

重新载入 systemd

[root@VM_0_2_centos php-5.6.30]# systemctl daemon-reload

可以设置开机启动:

[root@VM_0_2_centos php-5.6.30]# systemctl enable php5-fpm

启动:

[root@VM_0_2_centos php-5.6.30]# systemctl start php5-fpm

关闭:

[root@VM_0_2_centos php-5.6.30]# systemctl stop php5-fpm

查看状态:

[root@VM_0_2_centos php-5.6.30]# systemctl status php5-fpm

返回

● php5-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php5-fpm.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2018-08-29 09:36:39 CST; 47s ago
 Main PID: 14996 (php-fpm)
   CGroup: /system.slice/php5-fpm.service
           ├─14996 php-fpm: master process (/usr/local/php5/etc/php-fpm.conf)
           ├─14997 php-fpm: pool www
           └─14998 php-fpm: pool www

配置不同的 nginx 站点使用不用的 PHP 版本

[root@VM_0_2_centos php-5.6.30]# cd /usr/local/nginx/conf/vhost/
[root@VM_0_2_centos vhost]# vim test.liuguofeng.com.conf 
server {
    listen       80;
    server_name  test.liuguofeng.com;
    root         /home/wwwroot/test.liuguofeng.com
    location / {
        index  index.php index.html index.htm;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

PHP 5 使用 9001 端口, PHP 7,使用 9000端口。

重载 nginx 服务

[root@lnmp conf.d]# systemctl reload nginx

访问 PHPINFO

2 Comments

发表评论

电子邮件地址不会被公开。 必填项已用*标注