centos 8.x系统下编译安装php 7.4、php 5.6、php 5.3多版本及错误解决方法

本文档阐述如何在CentOS 8.x系统上编译并安装PHP 7.4、PHP 5.6和PHP 5.3多个版本,并提供常见错误的解决方法。
一、编译安装PHP 7.4.x
参考CentOS 8.0.1905编译安装Nginx1.16.1+MySQL8.0.18+PHP7.3.10文档,步骤如下:
立即学习“PHP免费学习笔记(深入)”;
<code class="bash">yum install apr* autoconf automake bison bzip2 bzip2* cpp curl curl-devel fontconfig fontconfig-devel freetype-devel gcc gcc-c++ gd gd-devel gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libxml* libXaw-devel libXmu-devel libtiff libtiff* make openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet wget zlib-devel ncurses-devel libtirpc-devel gtk* ntpstat bison* sqlite-devel oniguruma libzip-devel</code>
<code class="bash">cd /usr/local/src wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz # 或使用其他下载源 tar -zxf oniguruma-6.9.4.tar.gz cd oniguruma-6.9.4 ./autogen.sh ./configure --prefix=/usr make make install</code>
<code class="bash">cd /usr/local/src wget https://nih.at/libzip/libzip-1.2.0.tar.gz tar -zxvf libzip-1.2.0.tar.gz cd libzip-1.2.0 ./configure make make install cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h # 复制zipconf.h文件,避免编译错误</code>
<code class="bash">export LD_LIBRARY_PATH=/usr/local/libgd/lib # 设置libgd库环境变量 export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/" # 设置libzip环境变量 ./configure --prefix=/usr/local/php74 --with-config-file-path=/usr/local/php74/etc --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-gd --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype --with-xpm=/usr/lib64 --with-zlib-dir=/usr/local/zlib --with-iconv --with-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --with-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype --enable-mysqlnd make make install</code>
No package 'libzip' found: 检查PKG_CONFIG_PATH环境变量是否正确设置。No package 'sqlite3' found: 使用 yum install sqlite-devel 安装sqlite3开发包。No package 'oniguruma' found: 确保已按照步骤2安装Oniguruma。二、编译安装PHP 5.6.x
由于CentOS 8.x默认的openssl版本与PHP 5.6.x不兼容,需要安装低版本openssl:
<code class="bash">cd /usr/local/src wget <openssl-1.0.1e.tar.gz下载地址> # 下载openssl-1.0.1e.tar.gz mkdir /usr/local/openssl101e tar zxvf openssl-1.0.1e.tar.gz cd openssl-1.0.1e ./config --prefix=/usr/local/openssl101e make make install</code>
如果遇到POD document had syntax errors错误,执行 rm -f /usr/bin/pod2man 后再重新编译。
设置环境变量:
<code class="bash">export PATH=/usr/local/openssl101e/bin:$PATH export LD_LIBRARY_PATH=/usr/local/openssl101e/lib export LC_ALL="en_US.UTF-8" export LDFLAGS="-L/usr/local/openssl101e/lib -Wl,-rpath,/usr/local/openssl101e/lib"</code>
<code class="bash">./configure --prefix=/usr/local/php56 --with-config-file-path=/usr/local/php56/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd=/usr/local/libgd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/lib64 --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl-dir=/usr/local/openssl101e --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype --enable-mysqlnd make make install</code>
三、编译安装PHP 5.3.x
PHP 5.3.x需要更低版本的GD库和OpenSSL库,步骤类似于PHP 5.6.x,需要根据实际情况调整GD库和OpenSSL的版本和安装路径。
注意: 以上步骤中,/usr/local/mysql, /usr/local/libgd, /usr/local/jpeg, /usr/local/freetype, /usr/local/libpng, /usr/local/zlib, /usr/local/libvpx 等路径需要根据您实际安装MySQL和相关库的路径进行调整。 请务必在编译前仔细检查所有依赖库的版本和安装路径。 ./configure --help 命令可以帮助您查看所有可用的配置选项。
以上就是CentOS 8.x下编译php多版本报错处理的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号