安装各种依赖
yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel sqlite-devel
编译 (选择自己需要的安装)
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --enable-ftp --enable-gd --enable-gd-jis-conv --enable-mysqlnd --enable-pdo --enable-sockets --enable-fpm --enable-xml --enable-soap --enable-pcntl --enable-cli --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-pear --with-zlib --with-iconv --with-curl --enable-bcmath
编译 安装
make && make install
开始配置
新增环境变量
> vim /etc/profile 最后增加
export PHP=/usr/local/php
export PATH=$PHP/bin:$PHP/sbin:$PATH
> source /etc/profile
配置PHP
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
测试
[root@localhost www]# php -v
PHP 8.0.7 (cli) (built: Jun 25 2021 10:10:16) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.7, Copyright (c) Zend Technologies
添加权限 指定配置文件
vim /etc/init.d/php-fpm
php_fpm_INI=${prefix}/etc/php.ini
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID -c $php_fpm_INI -R"
将user group 改成 root
vim /usr/local/php/etc/php-fpm.d/www.conf
user = root
group = root
重新加载和重启php-fpm服务
systemctl daemon-reload
systemctl restart php-fpm