在 Ubuntu 上升级 Apache2 通常有两种场景:
下面分别说明。
sudo apt update
sudo apt install --only-upgrade apache2
或升级所有系统软件(包含 Apache):
sudo apt upgrade
apache2 -v
# 或
apachectl -v
示例输出:
Server version: Apache/2.4.52 (Ubuntu)
sudo systemctl restart apache2
如果你使用的是较老 Ubuntu(如 18.04),可以通过升级系统获得更新的 Apache:
sudo do-release-upgrade
⚠️ 操作前请备份数据和配置。
不推荐,除非你需要特定新特性。
sudo apt install build-essential libpcre3-dev libssl-dev
wget https://downloads.apache.org/httpd/httpd-2.4.xx.tar.gz
tar -xzf httpd-2.4.xx.tar.gz
cd httpd-2.4.xx
./configure --prefix=/opt/apache2 --enable-ssl
make
sudo make install
然后手动配置 systemd 服务。
sudo apache2ctl configtest
apache2ctl -M
sudo tail -f /var/log/apache2/error.log
✅ 生产环境:只用 apt 升级
✅ 升级前备份:
sudo cp -r /etc/apache2 /etc/apache2.bak
如果你告诉我:
lsb_release -a)我可以给你更精确的升级方案。