centos 同时安装php56和php7
安装php7请参考:https://blog.yongit.com/note/211000.html
本人有一台服务器有三个php版本,预览一下:
[root@hostname /]# ps -ef |grep php
root 1013 1 0 Jan30 ? 00:01:54 php-fpm: master process (/usr/local/php5/etc/php-fpm.conf)
www 1069 1013 0 Jan30 ? 00:00:01 php-fpm: pool www
www 1070 1013 0 Jan30 ? 00:00:01 php-fpm: pool www
root 485245 1 0 Feb01 ? 00:01:48 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
www 485246 485245 0 Feb01 ? 00:00:01 php-fpm: pool www
www 485247 485245 0 Feb01 ? 00:00:01 php-fpm: pool www
root 3720590 1 0 18:50 ? 00:00:00 php-fpm: master process (/usr/local/php72/etc/php-fpm.conf)
www 3720591 3720590 0 18:50 ? 00:00:00 php-fpm: pool www
www 3720592 3720590 0 18:50 ? 00:00:00 php-fpm: pool www
root 3720601 3566741 0 18:50 pts/1 00:00:00 grep --color=auto php
注意事项(如openssl版本是openssl-1.0.2请忽略)
看看你的openssl是什么版本openssl version
,如果版本过高,如:
[root@fouryear php-5.6.40]# openssl version
OpenSSL 1.1.1g FIPS 21 Apr 2020
会在编译--with-openssl的时候提示:make: *** [Makefile:623: ext/openssl/openssl.lo] Error 1
则需要安装与5.6.40兼容的版本:openssl1.0.2,完整步骤:
wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz
tar xvf openssl-1.0.2k.tar.gz
cd openssl-1.0.2k
./config
make && make install
确认一下:
[root@fouryear php-5.6.40]# /usr/local/ssl/bin/openssl version
OpenSSL 1.0.2k 26 Jan 2017
然后就可以使用:--with-openssl=/usr/local/ssl
需要确认ssl目录,也可能需要如此:--with-openssl-dir=/usr/include/openssl
,或直接-with-openssl
就行
下载解压
wget -c http://cn2.php.net/distributions/php-5.6.40.tar.gz
tar -zxvf php-5.6.40.tar.gz
cd php-5.6.40/
编译 php5.6
./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 --with-fpm-user=www --with-fpm-group=www --with-pdo-mysql
编译php7.4.3 (注意编译参数)
./configure --prefix=/usr/local/php73 --enable-fpm --with-mysqli --with-zlib --with-curl --enable-gd --with-jpeg --with-freetype --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo --with-fpm-user=toutiao --with-fpm-group=toutiao --with-pdo-mysql
如果提示:
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
No package 'sqlite3' found
则安装一下:yum -y install sqlite-devel
可能也要:yum -y install libcurl-devel
可能也要:yum -y install libpng-devel
可能也要:yum -y install libjpeg-devel
可能也要:yum -y install oniguruma-devel
安装
make && make install
完成提示
[root@fiveyear php-5.6.40]# make install
Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226/
Installing PHP CLI binary: /usr/local/php5/bin/
Installing PHP CLI man page: /usr/local/php5/php/man/man1/
Installing PHP FPM binary: /usr/local/php5/sbin/
Installing PHP FPM config: /usr/local/php5/etc/
Installing PHP FPM man page: /usr/local/php5/php/man/man8/
Installing PHP FPM status page: /usr/local/php5/php/php/fpm/
Installing PHP CGI binary: /usr/local/php5/bin/
Installing PHP CGI man page: /usr/local/php5/php/man/man1/
Installing build environment: /usr/local/php5/lib/php/build/
Installing header files: /usr/local/php5/include/php/
Installing helper programs: /usr/local/php5/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php5/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php5/lib/php/
[PEAR] Archive_Tar - installed: 1.4.4
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.3
[PEAR] PEAR - installed: 1.10.7
Wrote PEAR system config file at: /usr/local/php5/etc/pear.conf
You may want to add: /usr/local/php5/lib/php to your php.ini include_path
/root/php-5.6.40/build/shtool install -c ext/phar/phar.phar /usr/local/php5/bin
ln -s -f phar.phar /usr/local/php5/bin/phar
Installing PDO headers: /usr/local/php5/include/php/ext/pdo/
完成收尾
php.ini的配置就自行调整:/usr/local/php5/bin/php -v
cp php.ini-development /usr/local/php5/lib/php.ini
重点1:是需要修改php-fpm的listen端口(因为默认的socket端口9000已经被php7使用了)cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
vim /usr/local/php5/etc/php-fpm.conf
找到listen = 127.0.0.1:9000
改成listen = 127.0.0.1:9056
重点2:配置php5的php-fpm服务(作为系统服务,开启自启,也可以通过init.d/xxx自主管理)
cp /root/php-5.6.40/sapi/fpm/php-fpm.service /usr/lib/systemd/system/php5-fpm.service
vim /usr/lib/systemd/system/php5-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=${prefix}/var/run/php-fpm.pid
ExecStart=${exec_prefix}/sbin/php-fpm --nodaemonize --fpm-config ${prefix}/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
将PIDFile和ExecStart改成:
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
重新载入:systemctl daemon-reload
开机启动:systemctl enable php5-fpm
立即启动:systemctl start php5-fpm
查看状态:systemctl status php5-fpm
或ps -ef |grep php
完成,然后就是在nginx配置的时候,配置到底fastcgi_pass你想用php5还是php7的socket来处理请求了。