CentOS8.x编译PHP多版本报错解决
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免费学习笔记”;
安装依赖包:: 使用yum命令安装PHP 7.4.x所需的编译工具和库文件: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登录后复制 安装Oniguruma:: PHP 7.4.x需要Oniguruma库。下载、解压并安装:
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登录后复制 安装Libzip:: PHP 7.4.x需要Libzip库。下载、解压并安装:
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文件,避免编译错误登录后复制 编译PHP 7.4.x:: 设置环境变量并执行编译安装:
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登录后复制 错误处理:: 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:
安装低版本OpenSSL (例如1.0.1e)::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登录后复制
如果遇到POD document had syntax errors错误,执行 rm -f /usr/bin/pod2man 后再重新编译。
设置环境变量:
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"登录后复制 编译PHP 5.6.x::
./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登录后复制
三、编译安装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 命令可以帮助您查看所有可用的配置选项。
文章版权声明:除非注明,否则均为泥小猴系统网网络收集而来,如有任何问题请联系站长。