前段时间更新了 debian 编译安装 php7.4 的方法,现在再记录一下 php7/8 编译安装 php7.4.4 的过程。
预先安装依赖
这里我整理了大部分情况需要用到的依赖,将其安装。
# centos
yum install -y sqlite-devel
yum install -y libwebp-devel
yum install -y openldap-devel
yum install -y oniguruma-devel
yum install -y libxml2-devel
yum install -y openssl-devel
yum install -y libcurl-devel
yum install -y libpng-devel
yum install -y libjpeg-devel
yum install -y libzip-devel
cp -frp /usr/lib64/libldap* /usr/lib/
oniguruma 依赖
错误;Package 'oniguruma', required by 'virtual:world', not found
安装方法:
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -zxvf oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4/
./autogen.sh && ./configure --prefix=/usr
make && make install
如果过程中遇到错误:
[root@en oniguruma-6.9.4]# ./autogen.sh && ./configure --prefix=/usr
Generating autotools files.
./autogen.sh: line 6: autoreconf: command not found
解决:
yum install autoconf automake libtool
icu4c 依赖
错误:
checking for icu-uc >= 50.1 icu-io icu-i18n... no
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:
Package 'icu-uc', required by 'virtual:world', not found
Package 'icu-io', required by 'virtual:world', not found
Package 'icu-i18n', required by 'virtual:world', not found
解决:编译安装 icu
wget https://github.com/unicode-org/icu/releases/download/release-65-1/icu4c-65_1-src.tgz
tar -xf icu4c-65_1-src.tgz
cd icu/source
./configure --prefix=/usr
make
make install
libzip 版本较低
如果你通过 yum install -y libzip
及 yum install -y libzip-devel
也无法更新到要求版本时。建议将 libzip 卸载,编译安装或者找一个 rpm 包进行安装。
卸载 libzip 及 libzip-devel
yum remove libzip-devel -y
yum remove libzip -y
编译安装 libzip
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
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
完整配置
关于参数变更详参:
https://www.php.net/manual/en/migration74.other-changes.php#migration74.other-changes.pkg-config
PHP7.4
wget http://php.net/get/php-7.4.4.tar.gz/from/this/mirror -O php-7.4.4.tar.gz
tar -xzf php-7.4.4.tar.gz -C ./
cd php-7.4.4
./configure --prefix=/usr/local/php/php7.4.4/\
--with-config-file-path=/usr/local/php/php7.4.4/\
--with-libdir=lib\
--enable-fpm\
--enable-gd\
--enable-gd-jis-conv\
--with-fpm-user=www\
--with-fpm-group=www\
--enable-mysqlnd\
--with-pdo-mysql=mysqlnd\
--enable-opcache\
--enable-pcntl\
--enable-mbstring\
--enable-soap\
--enable-calendar\
--enable-bcmath\
--enable-exif\
--enable-ftp\
--enable-intl\
--enable-sockets\
--with-openssl\
--with-zlib\
--with-curl\
--with-gettext\
--with-mhash\
--with-webp\
--with-jpeg\
--with-ldap\
--with-zip
进行编译
make && make install
编译遇到错误:
/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_memfree'
//usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
解决办法:编辑 MakeFile 文件,找到EXTRA_LIBS
开头的这一行,在结尾加上-llber。
复制配置文件
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp php.ini-production /usr/local/php/php7.4.4/php.ini
cp /usr/local/php/php7.4.4/etc/php-fpm.conf.default /usr/local/php/php7.4.4/etc/php-fpm.conf
cp /usr/local/php/php7.4.4/etc/php-fpm.d/www.conf.default /usr/local/php/php7.4.4/etc/php-fpm.d/www.conf
写入执行权限
chmod +x /etc/init.d/php-fpm
重载系统服务,否则无法使用 systemctl 进行管理
systemctl daemon-reload
启动 php-fpm
systemctl start php-fpm
停止 php-fpm
systemctl stop php-fpm
增加到开启自启
systemctl enable php-fpm
Enjoy ~
Comments