
为了方便管理,我们可以统一将两个PHP版本都装到/usr/local/php中
# mkdir -p /usr/local/php56
# mkdir -p /usr/local/php73
# mkdir -p /usr/local/php74
两个版本的PHP的依赖都必须要装齐,可参考其他第三方多版本PHP管理软件
# yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
# yum install -y make cmake gcc gcc-c++ autoconf automake libpng-devel libjpeg-devel zlib libxml2-devel ncurses-devel bison libtool-ltdl-devel libiconv libmcrypt mhash mcrypt pcre-devel openssl-devel freetype-devel libcurl-devel oniguruma oniguruma-devel
//先安装remi (7.4.15用)
#yum --enablerepo=remi install libzip5-devel
安装jpeg png支持GD库
jpeg官网:http://www.ijg.org/files/
#wget http://www.ijg.org/files/jpegsrc.v9d.tar.gz
#tar zxvf jpegsrc.v9d.tar.gz
#cd jpeg-9d/
#mkdir /usr/local/imagelib/ //图片库统一在这个文件夹内
#./configure --prefix=/usr/local/imagelib/jpeg --enable-shared --enable-static
#make
#make install
下载php5.6 /7.4.15
# wget https://www.php.net/distributions/php-5.6.40.tar.bz2
//https://developer.aliyun.com/packageSearch?word=php 阿里的开发者仓库
//http://php.p2hp.com/downloads.php 搜狐中国节点 GOOD!😍
解压php
# tar -xjf php-5.6.40.tar.bz2
# tar -zxvf php-7.4.15.tar.gz
进入php目录
# cd php-5.6.40
编译
5.6
./configure \
--prefix=/usr/local/php56 \ //指定目录(安装时请删除此注释)
--with-config-file-path=/usr/local/php56/etc \ // 指定配置(安装时请删除此注释)
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysql=mysqlnd \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-xml \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
7.2.34
./configure --prefix=/usr/local/php72 --with-config-file-path=/usr/local/php74/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --enable-ftp --with-openssl-dir --with-webp-dir --with-zlib-dir --with-freetype-dir --enable-gd-jis-conv --with-gd --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-xsl --enable-xml --enable-mysqlnd-compression-support --with-pear --enable-opcache --with-jpeg-dir=/usr/local/imagelib/jpeg
7.4.15
#dnf --enablerepo=powertools install oniguruma-devel
./configure --prefix=/usr/local/php74 --with-config-file-path=/usr/local/php74/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml --with-xmlrpc --with-openssl --with-mhash --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --enable-ftp --with-openssl-dir --with-webp --with-zlib-dir --with-freetype --enable-gd-jis-conv --enable-gd --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-xsl --enable-xml --enable-mysqlnd-compression-support --with-pear --enable-opcache --with-jpeg=/usr/local/imagelib/jpeg
8.0.26
./configure --prefix=/usr/local/php80 --with-config-file-path=/usr/local/php80/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml --with-xmlrpc --with-openssl --with-mhash --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --enable-ftp --with-openssl-dir --with-webp --with-zlib-dir --with-freetype --enable-gd-jis-conv --enable-gd --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-xsl --enable-xml --enable-mysqlnd-compression-support --with-pear --enable-opcache --with-jpeg=/usr/local/imagelib/jpeg
在Linux给PHP7.4安装gd库的时候,会报错error: –with-freetype-dir –with-jpeg-dir等等,仔细查看PHP7.4的手册Other Changes才发现with参数改了

安装
# make && make install
# ln -s /usr/local/php80/bin/php /usr/local/bin/php
配置php-fpm
# cp /usr/local/php-7.4.15/php.ini-production /usr/local/php74/etc/php.ini
# cp /usr/local/php74/etc/php-fpm.conf.default /usr/local/php74/etc/php-fpm.conf
# cp /usr/local/php74/etc/php-fpm.d/www.conf.default /usr/local/php74/etc/php-fpm.d/www.conf
# cp /usr/local/php-7.2.34/php.ini-production /usr/local/php72/etc/php.ini
# cp /usr/local/php72/etc/php-fpm.conf.default /usr/local/php72/etc/php-fpm.conf
# cp /usr/local/php72/etc/php-fpm.d/www.conf.default /usr/local/php72/etc/php-fpm.d/www.conf
# cp /usr/local/php-8.0.26/php.ini-production /usr/local/php80/etc/php.ini
# cp /usr/local/php80/etc/php-fpm.conf.default /usr/local/php80/etc/php-fpm.conf
# cp /usr/local/php80/etc/php-fpm.d/www.conf.default /usr/local/php80/etc/php-fpm.d/www.conf
# vi /usr/local/php74/etc/php-fpm.conf
pid = run/php-fpm.pid //将注释取消掉
error_log = /usr/local/php74/var/log/php-fpm.log //将注释取消掉
log_level = notice //将注释取消掉
listen = 127.0.0.1:9001 <<<<<<<修改为 listen 127.0.0.1:9001 或其他端口
//listen = /tmp/php56.sock //或监听sock 二选一 推荐监听端口的
//listen = /var/run/php56-cgi.sock
//可能listen在这个目录中
/usr/local/php74/etc/php-fpm.d/www.conf
//在末尾加入(按上步操作安装reids)
vi /usr/local/php74/etc/php.ini
extension=redis.so
安装并支持redis请看这里: Redis安装笔记
现在已经可以启动php-fpm
# /usr/local/php74/sbin/php-fpm
添加php-fpm系统服务
//复制服务文件
cp /usr/local/php-8.0.26/sapi/fpm/php-fpm.service /lib/systemd/system/php-fpm.service
//
PrivateTmp=true 中改为false
cat>/lib/systemd/system/php-fpm.service<<EOF
[Unit]
Description=The PHP 8.0 FastCGI Process Manager
Documentation=man:php-fpm8.0(8)
After=network.target
[Service]
Type=simple
PIDFile=/usr/local/php80/php-fpm.pid
/usr/local/php80/sbin/php-fpm
ExecStart=/usr/local/php80/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php80/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=false
[Install]
WantedBy=multi-user.target
EOF
chmod 745 /lib/systemd/system/php-fpm.service
systemctl daemon-reload
//开机启动
systemctl enable php-fpm.service
pkill php-fpm
systemctl restart php-fpm.service
//出现如下情况时
failed to open error_log (/usr/local/php80/var/log/php-fpm.log): Read-only file system>
到/usr/lib/systemd/system/php-fpm.service 把
ProtectSystem=true
改成
ProtectSystem=false
服务器相关的命令
启动服务:service php74-fpm start ; service php56-fpm start
停止服务:service php74-fpm stop ; service php56-fpm stop ;
重启服务:service php74-fpm restart ; service php56-fpm restart ;
加入开机启动
# vi /etc/rc.local
service php56-fpm start
service php74-fpm start
配置网站nginx.conf
fastcgi_pass 127.0.0.1:9001; //监听端口 对应上面设置
fastcgi_pass unix:/tmp/php56.sock; //或监听sock 二选一
配置cli中使用的php版本
# /usr/local/php74/bin/php -v
检查配置是否成功
分别在两个站点建立phpinfo文件查看对应信息