在CentOS系统中升级PHP版本可以通过以下步骤完成:
安装Remi仓库
sudo yum install epel-release
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
启用Remi仓库
sudo yum-config-manager --enable remi-php74
这里的php74
是你想要安装的PHP版本号,你可以根据需要更改为其他版本,如php80
。
更新PHP及相关模块
sudo yum update php\*
验证安装
php -v
如果你需要特定版本的PHP或者Remi仓库中没有你需要的版本,可以手动编译安装:
安装依赖包
sudo yum install -y gcc make autoconf libc-dev zlib-devel libxml2-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel autoconf213 php-pear php-mbstring php-xmlrpc php-snmp php-soap php-zip
下载并解压PHP源码
wget https://www.php.net/distributions/php-7.4.33.tar.gz
tar -zxvf php-7.4.33.tar.gz
cd php-7.4.33
配置编译选项
./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 --enable-zip
编译并安装
make && sudo make install
配置PHP 将编译安装的PHP配置文件复制到系统默认位置:
sudo cp php.ini-production /usr/local/php/etc/php.ini
更新环境变量
编辑~/.bashrc
或/etc/profile
文件,添加以下行:
export PATH=/usr/local/php/bin:$PATH
然后使更改生效:
source ~/.bashrc
验证安装
php -v
通过以上步骤,你应该能够在CentOS系统上成功升级PHP版本。