温馨提示×

php在centos上如何进行版本升级

小樊
132
2025-09-13 17:17:08
栏目: 编程语言

在CentOS上升级PHP版本,常用方法有使用Remi仓库和手动编译安装两种,以下是具体步骤:

使用Remi仓库

  1. 备份配置文件:cp -r /etc/php.ini /etc/php.ini.bak,cp -r /etc/php-fpm.d /etc/php-fpm.d.bak。
  2. 安装EPEL仓库:sudo yum install epel-release。
  3. 安装Remi仓库:sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm(CentOS 7)或sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm(CentOS 8)。
  4. 启用Remi仓库:sudo yum-config-manager --enable remi-phpX.X(X.X为目标PHP版本号)。
  5. 更新PHP:sudo yum update php\*(CentOS 7用yum,CentOS 8用dnf)。
  6. 重启Web服务器:Apache用sudo systemctl restart httpd,Nginx和PHP - FPM用sudo systemctl restart nginx和sudo systemctl restart php-fpm。

手动编译安装

  1. 安装依赖包:sudo yum install gcc make autoconf zlib-devel libxml2-devel openssl-devel libjpeg-devel libpng-devel freetype-devel。
  2. 下载源码:从PHP官网下载所需版本源码,如wget https://www.php.net/distributions/php-8.0.10.tar.gz。
  3. 解压源码:tar -zxvf php-8.0.10.tar.gz,然后cd php-8.0.10。
  4. 配置编译选项:./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mbstring --with-curl --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --with-zlib --with-mysqli --with-pdo-mysql --with-openssl。
  5. 编译并安装:make && sudo make install。
  6. 配置PHP:复制配置文件cp php.ini-production /usr/local/php/etc/php.ini等。
  7. 重启Web服务器:同使用Remi仓库的步骤。

0 踩