一、环境

物理服务器,系统centos7.6 x86_64位,关闭selinux
[root@localhost src]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

二、源码编译安装php

下载lanp1.3的版本一键安装包,从中找到php源码包来编译安装

tar xf php-5.4.45.tar.gz
cd php-5.4.45
mkdir -p /usr/local/php5.4
./configure --prefix=/usr/local/php5.4 --with-config-file-path=/usr/local/php5.4/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=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 --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-intl --with-xsl --without-pear --disable-phar
vim Makefile
107 EXTRA_LIBS 此行的末尾添加参数-liconv
make && make  install

准备php-fpm.conf配置文件和php-fpm的启动脚本:

[root@localhost php-5.4.45]# cp php.ini-production /usr/local/php5.4/etc/php.ini
[root@localhost php-5.4.45]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php5.5-fpm
[root@localhost php-5.4.45]# chmod +x /etc/init.d/php
php5.5-fpm  php-fpm     
[root@localhost php-5.4.45]# chmod +x /etc/init.d/php5.5-fpm 
[root@localhost php-5.4.45]# cat /usr/local/php5.4/etc/php-fpm.conf
[global]
pid = /usr/local/php5.4/var/run/php-fpm.pid
error_log = /usr/local/php5.4/var/log/php-fpm.log
log_level = notice

[www]
listen = /dev/shm/php-cgi5.4.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.status_path = /fpmstatus
pm.max_children = 100
pm.start_servers = 70
pm.min_spare_servers = 60
pm.max_spare_servers = 100
pm.max_requests = 10000
pm.process_idle_timeout = 10s
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
security.limit_extensions=.php .html .js .css .jpg .jpeg .gif .png .htm

查看版本:

[root@localhost ~]# /usr/local/php5.4/bin/php -v
PHP 5.4.45 (cli) (built: May 29 2020 14:49:41) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

编写phpinfo文件测试版本:


[root@localhost ~]# cat 1.php