本文共 3143 字,大约阅读时间需要 10 分钟。
yum -y update
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++
cd /usr/local/src
wget https://www.php.net/distributions/php-7.3.5.tar.gz
tar -zxvf php-7.3.5.tar.gzcd php-7.3.5
groupadd wwwuseradd -g www www
./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,手动安装最新版本
(1)先安装cmake
cd /usr/local/srcwget https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gztar -zxvf cmake-3.14.3.tar.gzcd cmake-3.14.3./bootstrapmake && make install
(2)再编译安装libzip
yum remove libzip -ycd /usr/local/srcwget https://libzip.org/download/libzip-1.5.2.tar.gztar -zxvf libzip-1.5.2.tar.gzcd libzip-1.5.2mkdir buildcd buildcmake ..make && make install
(3)执行以下命令
vi /etc/ld.so.conf#添加如下几行/usr/local/lib64/usr/local/lib/usr/lib/usr/lib64#保存退出ldconfig -v # 使之生效
make && make install
vi /etc/profile#添加以下内容到最后PATH=$PATH:/usr/local/php/binexport PATH#刷新环境变量source /etc/profile
# 将启动脚本复制到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 ${PHP73_DIR}/etc/php-fpm.conf# 添加pool的配置cat << EOF > /usr/local/php/etc/php-fpm.d/www.conf[www]listen = /home/www/logs/php73-fpm.socklisten.mode = 0666user = wwwgroup = wwwpm = dynamicpm.max_children = 128pm.start_servers = 5pm.min_spare_servers = 5pm.max_spare_servers = 15pm.max_requests = 300rlimit_files = 1024slowlog = /home/www/logs/php73-fpm-slow.logEOF
镜像中默认是用的php-fpm,使用的是socket方式的监听,Apache对应配置文件/usr/local/apache/conf/httpd.conf
,其中配置如下:
需要修改其中socket的文件路径指向到新版本的PHP就可以了,在/usr/local/php73/etc/php-fpm.d/www.conf
有指定,新的配置到/home/www/logs/php73-fpm.sock
即可,如图:
# 停止旧版本的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
转载地址:http://zbgwi.baihongyu.com/