在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 # 替换为你想要的PHP版本,例如php74, php80等 更新PHP:
sudo yum update php\* 重启Web服务器: 如果你使用的是Apache:
sudo systemctl restart httpd 如果你使用的是Nginx和PHP-FPM:
sudo systemctl restart nginx sudo systemctl restart php-fpm 安装依赖包:
sudo yum install -y gcc make autoconf libc-dev zlib-devel libxml2-dev bzip2-dev curl-devel libjpeg-devel libpng-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel autoconf 下载PHP源码:
wget https://www.php.net/distributions/php-7.4.33.tar.gz # 替换为你想要的PHP版本 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-gettext \ --with-openssl \ --with-xsl \ --enable-zip 编译并安装:
make && sudo make install 配置PHP: 将/usr/local/php/etc/php.ini-production复制到/usr/local/php/etc/php.ini:
cp /usr/local/php/etc/php.ini-production /usr/local/php/etc/php.ini 更新环境变量: 编辑~/.bashrc或/etc/profile,添加以下行:
export PATH=/usr/local/php/bin:$PATH 然后使其生效:
source ~/.bashrc # 或 source /etc/profile 重启Web服务器: 同方法一中的步骤。
通过以上步骤,你应该能够在CentOS上成功升级PHP版本。