1.首先更新依赖包。
yum -y update
2.安装依赖包
yum -y 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 zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip gcc-c++ yum -y install sqlit3-devel configure时检测时如果遇到缺少包,一般是缺少对应的devel包,如上安装sqlite-devel一样处理。
3.转到 /usr/local/src 目录,下载php7.3.5
cd /usr/local/src
wget https://www.php.net/distributions/php-7.3.5.tar.gz
4.解压安装包,并进入目录
tar -zxvf php-7.3.5.tar.gz
cd php-7.3.5
5.添加用户和组
groupadd www
useradd -g www www
6.开始编译
./configure --prefix=/usr/local/php --with-fpm-user=www --with-fpm-group=www --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm
这里会提示 configure: error: Please reinstall the libzip distribution,我们需要移除libzip,手动安装最新版本
7.安装libzip
(1)先安装cmake(在阿里云centos不需要这一步)
cd /usr/local/src
wget https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gz
tar -zxvf cmake-3.14.3.tar.gz
cd cmake-3.14.3
./bootstrap
make && make install
(2)再编译安装libzip(在阿里云centos不需要这一步)
yum remove libzip -y
cd /usr/local/src
wget https://libzip.org/download/libzip-1.5.2.tar.gz
tar -zxvf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
make && make install
(3)执行以下命令
vi /etc/ld.so.conf
添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
保存退出
ldconfig -v # 使之生效
- 再次编译PHP7.3
make && make install
9.编译完成后,添加环境变量
vi /etc/profile PATH=$PATH:/usr/local/php/bin export PATH
刷新环境变量
source /etc/profile
10.配置文件
将启动脚本复制到init.d中。
cp /usr/local/src/php-7.3.5/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm73
给启动脚本加上执行权限
chmod +x /etc/init.d/php-fpm73
将默认配置文件复制为.conf文件
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
添加pool的配置
cat << EOF > /usr/local/php/etc/php-fpm.d/www.conf
[www]
listen = /home/www/logs/php73-fpm.sock
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 128
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 300
rlimit_files = 1024
slowlog = /home/www/logs/php73-fpm-slow.log
EOF
11.修改apache
镜像中默认是用的php-fpm,使用的是socket方式的监听,Apache对应配置文件/usr/local/apache/conf/httpd.conf
修改指定位置为:
ProxyPassMatch ^/(..php(/.)?)$ unix:/home/www/logs/php73-fpm.sock|fcgi://127.0.0.1/home/www/htdocs
12.重启服务
停止旧版本的PHP(实际不停止也不影响,停止可以减少一些系统资源占用)
/etc/init.d/php-fpm stop
启动新版PHP-FPM
/etc/init.d/php-fpm73 start
启动报错请修改文件名
修改/usr/local/php/etc/php-fpm.conf.default为php-fpm.conf
重启apache
/etc/init.d/apachectl restart
修改自启动
chkconfig --del php-fpm chkconfig --add php73-fpm
参考https://blog.csdn.net/qq_43701912/article/details/107020920,中间根据个人情况进行修改。