|

Linux安装多个版本的PHP

怎么在服务器上安装多个版本的php同时运行,主要是把php安装到不同的目录,使用不同的端口
下面以编译安装php5.6为例子

安装php 5.6

进入/usr/local/src/目录下载文件

cd /usr/local/src/
wget -c http://cn2.php.net/distributions/php-5.6.21.tar.gz

解压安装包

tar -zxvf php-5.6.21.tar.gz

进入解压好的文件

cd php-5.6.21/

安装配置(安装到/usr/local/php56)

./configure --prefix=/usr/local/php56 --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 --enable-sockets --with-iconv-dir

编辑安装

make & make install

配置PHP5.6

cp php.ini-development /usr/local/php56/lib/php.ini

//编辑配置
vim /usr/local/php56/lib/php.ini

mysql.default_socket = /var/lib/mysql/mysql.sock
mysqli.default_socket = /var/lib/mysql/mysql.sock
date.timezone = PRC

安装完成

/usr/local/php56/bin/php -v

配置php-fpm

cp /usr/local/php56/etc/php-fpm.conf.default /usr/local/php56/etc/php-fpm.conf
vim /usr/local/php56/etc/php-fpm.conf

//修改用户
user = nobody
group = nobody
//如下
user = nginx
group = nginx

//修改端口
listen = 127.0.0.1:9000

配置 php-fpm 服务

cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php56-fpm.service
vim /usr/lib/systemd/system/php56-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/php56/var/run/php-fpm.pid
ExecStart=/usr/local/php56/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php56/etc/php-fpm.conf

重新载入 systemd

systemctl daemon-reload

开机自启动

systemctl enable php56-fpm

启动服务php-fpm

systemctl start php56-fpm

nginx怎么配置?

//控制使用哪个php版本关键在 fastcgi_pass
location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

类似文章