Linux Apache2 升级指南
一 升级前准备
sudo cp -r /etc/apache2 /etc/apache2_backupsudo cp -r /etc/httpd /etc/httpd.bakapachectl -v 或 httpd -v。二 Ubuntu 或 Debian 升级步骤
sudo apt updatesudo apt upgrade apache2sudo apachectl configtestsudo systemctl restart apache2apache2 -vsudo add-apt-repository ppa:ondrej/apache2 -y && sudo apt updatesudo apt upgrade apache2 -ysudo apachectl configtest && sudo systemctl restart apache2apache2 -v三 CentOS 或 RHEL 升级步骤
sudo yum install epel-releasesudo yum updatesudo yum install httpd 或 sudo yum update httpdsudo systemctl start httpd && sudo systemctl enable httpdsudo systemctl status httpd、sudo apachectl configtestsudo systemctl restart httpdhttpd -v四 源码编译安装升级(仅在仓库版本过旧时使用)
sudo yum groupinstall "Development Tools" 与 sudo yum install apr-devel apr-util-devel pcre-develwget https://www.apache.org/dyn/closer.cgi?action=download&filename=httpd-2.4.54.tar.gztar xzvf httpd-2.4.54.tar.gz && cd httpd-2.4.54./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl --with-mpm=preforkmake && sudo make installsudo mv /usr/sbin/apachectl /usr/sbin/apachectl.oldsudo ln -s /usr/local/apache2/bin/apachectl /usr/sbin/apachectl/usr/local/apache2/bin/apachectl start/usr/local/apache2/bin/apachectl -vsudo firewall-cmd --permanent --zone=public --add-service=http && sudo firewall-cmd --permanent --zone=public --add-service=https && sudo firewall-cmd --reload五 验证与回滚
apachectl -v 或 httpd -vsudo apachectl configtestsudo systemctl status apache2 或 sudo systemctl status httpdsudo apt install --reinstall apache2 / sudo yum reinstall httpd,并恢复备份配置。/usr/sbin/apachectl 恢复为旧版本(sudo mv /usr/sbin/apachectl.old /usr/sbin/apachectl),再重启服务。