centos安装PHP8.1

时间:2021-08-22

第一步:添加软件源

centos7

sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

centos8

将上面centos7中的7换成8即可

第二步:启用php8.1版本

sudo yum-config-manager --disable 'remi-php*'

sudo yum-config-manager --enable remi-php81

sudo yum update

第三步:安装PHP8.1

yum install php81

第四步:安装其它扩展

查看已安装的PHP扩展

php81 -m

bcmath

bz2

calendar

Core

ctype

curl

date

exif

fileinfo

filter

ftp

gd

gettext

hash

iconv

json

libxml

mbstring

mysqli

mysqlnd

openssl

pcntl

pcre

PDO

pdo_mysql

pdo_sqlite

Phar

readline

Reflection

session

sockets

SPL

sqlite3

standard

tokenizer

Zend OPcache

zlib

根据你的需要安装所需的扩展,比如:安装pdo扩展

yum install php81-php-pdo

php81-php-扩展名称

你应该安装fpm扩展,以便nginx可以解析PHP

yum install php81-php-fpm

启动它,并设置成开机自启动

service php81-php-fpm start

systemctl enable php81-php-fpm.service

修改nginx配置,以便可以处理PHP文件

参考:https://note.wyzda.com/74cf98bfe0d59215a212dafb2acdcdaf

修改配置后,需要重启nginx!

查看PHP版本

php81 -v

PHP 8.1.0beta2 (cli) (built: Aug  3 2021 13:39:35) (NTS gcc x86_64)

Copyright (c) The PHP Group

Zend Engine v4.1.0-dev, Copyright (c) Zend Technologies

with Zend OPcache v8.1.0beta2, Copyright (c), by Zend Technologies

查看PHP配置文件所在目录

php81 -i | grep php.ini

Configuration File (php.ini) Path => /etc/opt/remi/php81

Loaded Configuration File => /etc/opt/remi/php81/php.ini