一、编译安装PHP7.4
1.1 系统环境
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
1.2 下载php-7.4源码并解压
wget https://www.php.net/distributions/php-7.4.30.tar.gz
tar zxf php-7.4.30.tar.gz
1.3 安装依赖
yum install gcc libxml2-devel openssl-devel libcurl-devel gmp-devel sqlite-devel oniguruma-devel libpng-devel libwebp-devel libjpeg-devel freetype-devel net-snmp-devel
1.4 预编译、检查环境
./configure --prefix=/usr/local/php74 \
--with-config-file-path=/usr/local/php74/etc \
--with-mysqli \
--enable-mysqlnd \
--with-pdo-mysql \
--with-iconv-dir \
--with-freetype \
--with-jpeg \
--with-webp \
--with-curl \
--enable-gd \
--with-gmp \
--with-zlib \
--with-xmlrpc \
--with-openssl \
--without-pear \
--with-gettext \
--with-mhash \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-xml \
--enable-fpm \
--enable-ftp \
--enable-bcmath \
--enable-soap \
--enable-shmop \
--enable-sysvsem \
--enable-sockets \
--enable-inline-optimization \
--enable-maintainer-zts \
--enable-mbregex \
--enable-mbstring \
--enable-pcntl \
--with-zip \
--disable-fileinfo \
--disable-rpath \
--enable-opcache \
--with-snmp
1.5 编译并安装
make && make install
1.6 设置PHP配置文件
cp ~/php-7.4.30/php.ini-production /usr/local/php74/etc/php.ini
cp /usr/local/php74/etc/php-fpm.d/www.conf.default /usr/local/php74/etc/php-fpm.conf
1.7 设置php启动脚本,并使其开机自启动
cp ~/php-7.4.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
systemctl enable php-fpm.service
systemctl start php-fpm.service
systemctl status php-fpm.service
二、问题处理
预编译PHP过程中会出现错误提示:No package 'libzip' found
编译安装libzip
2.1 安装cmake3.6.0
[root@localhost ~]# curl -O https://cmake.org/files/v3.6/cmake-3.6.0-Linux-x86_64.tar.gz
[root@localhost ~]# tar zxf cmake-3.6.0-Linux-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# echo "export PATH=$PATH:/usr/local/cmake-3.6.0-Linux-x86_64/bin" >> /etc/profile
[root@localhost ~]# source /etc/profile
[root@localhost ~]# cmake -version
cmake version 3.6.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
2.2 安装libzip-1.10.0(发文时最新版本)
[root@localhost ~]# wget https://libzip.org/download/libzip-1.10.0.tar.gz
[root@localhost ~]# tar zxf libzip-1.10.0.tar.gz
[root@localhost ~]# mkdir -p libzip-1.10.0/build
[root@localhost ~]# cd libzip-1.10.0/build
[root@localhost ~]# cmake DCMAKE_INSTALL_PREFIX=/usr ..
[root@localhost ~]# make && make install
[root@localhost ~]# export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib64/pkgconfig
[root@localhost ~]# echo "/usr/local/lib64" > /etc/ld.so.conf.d/libzip.conf
[root@localhost ~]# ldconfig
[root@localhost ~]# pkg-config --libs libzip
-L/usr/local/lib64 -lzip
三、配置Nginx
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}