第一步:安装和启用EPEL和Remi存储库
# CentOS 8
shell > dnf -y install epel-release
shell > dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
shell > dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
# CentOS 9
shell > dnf -y install epel-release
shell > dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
shell > dnf -y install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
第二步:安装yum-utils(已经安装可跳过)
shell > dnf -y install yum-utils
第三步:配置dnf PHP版本 (根据自己的需求配置)
# 查看当前支持哪些版本
shell > dnf module list | grep php
# 重置默认模块
shell > dnf module reset php
# 设置默认 安装PHP 7.0 (以此类推, 必须先重置模块)
shell > dnf module enable php:remi-7.4 -y
第四步:安装PHP和一些扩展
shell > dnf -y install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo php-msgpack php-redis php-mbstring php-posix php-process
# 以下是我常用扩展
shell > dnf -y install php-amqp php-bcmath php-bz2 php-calendar php-core php-ctype php-curl php-date php-dom php-exif php-fileinfo php-filter php-ftp php-gd php-gettext php-hash php-iconv php-igbinary php-imap php-json php-ldap php-libxml php-mbstring php-mcrypt php-msgpack php-mysqli php-mysqlnd php-openssl php-pcntl php-pcre php-pdo php-pdo_mysql php-pdo_sqlite php-phar php-posix php-readline php-redis php-reflection php-session php-shmop php-simplexml php-sockets php-spl php-sqlite3 php-standard php-swoole php-sysvmsg php-sysvsem php-sysvshm php-tokenizer php-wddx php-xml php-xmlreader php-xmlrpc php-xmlwriter php-xsl php-opcache php-zlib php-zip
第五步:安装PHP-FPM (我习惯与NGINX搭配,且账号都用nginx,所以有了以下修改)
shell > dnf -y install php-fpm
#修改一些PHP-FPM的配置(习惯PHP-FPM通过TCP交互而不是SOCK)
shell > vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
listen = 127.0.0.1:9000
listen.owner = nginx
listen.group = nginx
#添加nginx用户(存在跳过)
shell > useradd nginx
#设置php-fpm执行用户对运行时需要临时存储的一些文件夹有权限
shell > chown -R root:nginx /var/lib/php
shell > chown -R nginx:root /var/log/php-fpm
#加入开机启动项并启动
shell > systemctl enable php-fpm --now