php7.4.33 编译安装

一、 下载

wget https://www.php.net/distributions/php-7.4.33.tar.gz

二、 安装依赖

yum install gcc gcc++ gcc-c++ libxml2-devel libicu-devel sqlite-devel oniguruma oniguruma-devel autoconf zip unzip openssl-devel libcurl-devel libpng-devel libjpeg-devel freetype-devel libxslt-devel

安装libzip

2.1 删除原有libzip

yum remove libzip

2.2 下载指定版本的libzip

wget --no-check-certificate https://nih.at/libzip/libzip-1.2.0.tar.gz

2.3 安装libzip1.2.0

tar -xzvf libzip-1.2.0.tar.gz ```
cd libzip-1.2.0 ```
./configure --prefix=/usr/local/libzip-1.2.0 ```
make && make install

2.4 配置环境

export PKG_CONFIG_PATH="/usr/local/libzip-1.2.0/lib/pkgconfig/"

三、 编译安装

tar -xzvf php-7.4.33.tar.gz
cd php-7.4.33
./configure \
--prefix=/usr/local/php7.4 --with-config-file-path=/usr/local/php7.4/etc \
--enable-fpm --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--enable-pdo --with-iconv-dir --with-freetype --with-jpeg --with-zlib \
--enable-xml --enable-session --disable-rpath --enable-bcmath --enable-shmop \
--enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex \
--enable-mbstring --enable-intl --enable-pcntl --enable-bcmath --enable-ftp \
--enable-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets \
--with-xmlrpc --with-zip --enable-soap --with-gettext --disable-fileinfo \
--enable-opcache --enable-maintainer-zts --with-xsl --enable-tokenizer
make && make install

关于编译配置选项

关于一些配置项, 可以参考php的官方文档
或者运行 ./configure –help 命令

3.1 配置 php

ln -s /usr/local/php7.4/bin/php /usr/bin/php
cat $PATH_OF_PHP_SOURCE_FOLDER/php.ini-development > /usr/local/php7.4/etc/php.ini

行:962 ```date.timezone = Asia/Shanghai```

3.2 配置 php-fpm

ln -s /usr/local/php7.4/sbin/php-fpm /usr/bin/php-fpm
cd /usr/local/php7.4/etc
cp php-fpm.conf.default php-fpm.conf

3.3 配置 php-fpm 用户文件

cd /usr/local/php7.4/etc/php-fpm.d
cp www.conf.default www.conf

3.4 使用 systemctl 管理 php-fpm

# vim /usr/lib/systemd/system/php74-fpm.service

[Unit]
Description=The PHP 7.4 FastCGI Process Manager
Documentation=man:php-fpm7.4
After=network.target

[Service]
Type=simple
PIDFile=/var/run/php74-fpm.pid
ExecStart=/usr/local/php74/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php74/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

四、 相关问题

4.1 error: Package requirements (openssl >= 1.0.1) were not met

解决: yum install openssl-devel

4.2 error: Package requirements (libcurl >= 7.15.5) were not met

解决: yum install libcurl-devel

4.3 error: Package requirements (libpng) were not met

解决: yum install libpng-devel

4.4 error: Package requirements (libjpeg) were not met

解决: yum install libjpeg-devel

4.5 error: Package requirements (freetype2) were not met

解决: yum install freetype-devel

4.6 configure: error: C++ preprocessor “/lib/cpp” fails sanity check

解决: yum install gcc-c++

4.7 error: Package requirements (libxslt >= 1.1.0) were not met

解决: yum install libxslt-devel