一、安装依赖
yum install libxml2-devel openssl-devel sqlite-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel openldap-devel oniguruma-devel libxslt-devel
因yum安装的libzip 版本过低,这里卸载后需要安装个高版本的libzip
#先卸载已有 yum remove libzip #安装 wget https://libzip.org/download/libzip-1.2.0.tar.gz tar -zxvf libzip-1.2.0.tar.gz cd libzip-1.2.0 ./configure make && make install #装完了之后找一下/usr/local/lib下有没有 pkgconfig 目录,有的话执行命令 export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"指定 PKG_CONFIG_PATH export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
二、安装PHP 7.4.30
wget https://www.php.net/distributions/php-7.4.30.tar.gz tar -zxvf php-7.4.30.tar.gz cd php-7.4.30 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-fpm-user=www --with-fpm-group=www --enable-fpm --with-bz2 --enable-gd --with-mysqli=mysqlnd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-zlib-dir --with-iconv-dir=/usr/local --enable-soap --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-curl --enable-bcmath --enable-sockets --enable-calendar --with-gettext --with-pdo-mysql=mysqlnd --disable-fileinfo --with-ldap --with-openssl --with-pear --with-xmlrpc --with-libdir=lib64 --with-libxml-dir --with-pcre-regex --with-pear --with-xsl --with-zlib --with-mhash --enable-libxml --enable-inline-optimization --enable-mbregex --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --with-zip --with-pdo-mysql=mysqlnd --with-pdo-mysql make && make install #You may want to add: /usr/local/php/lib/php to your php.ini include_path
在 /etc/profile文件中末尾出,添加如下代码,指定php的执行命令的路径,方便命令执行
export PATH=$PATH:/usr/local/php/bin
添加后,需要执行 source /etc/profile ,是文件生效
三、查看PHP版本
[root@iZ2zeif4b ~]# php -v PHP 7.4.30 (cli) (built: Sep 10 2022 09:34:10) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies
四、配置php-fpm
先配置几个文件
cp -rf php.ini-production /usr/local/php/etc/php.ini cp -rf /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf cp -rf /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
创建www用户
useradd -r -s /sbin/nologin www
启动php-fpm
/usr/local/php/sbin/php-fpm