下面按常见场景给你一套 Debian 上迁移 Apache 的实用步骤。你可以根据实际是同机迁移、跨服务器迁移还是升级 Debian 版本来选择。
apache2 -v
dpkg -l | grep apache
systemctl stop apache2
一般只需要备份这些:
# 配置
tar czf apache-conf.tar.gz /etc/apache2
# 网站数据
tar czf www.tar.gz /var/www
# 可选:日志(通常不需要)
tar czf apache-logs.tar.gz /var/log/apache2
如果是 虚拟主机多,确认:
ls /etc/apache2/sites-enabled
apt update
apt install --reinstall apache2
tar xzf apache-conf.tar.gz -C /
tar xzf www.tar.gz -C /
a2ensite your-site.conf
a2enmod rewrite
apache2ctl configtest
systemctl start apache2
tar czf apache-migration.tar.gz /etc/apache2 /var/www
scp apache-migration.tar.gz user@new-server:/root/
apt update
apt install apache2
tar xzf apache-migration.tar.gz -C /
chown -R www-data:www-data /var/www
a2ensite *
systemctl restart apache2
⚠️ 注意:
Debian 升级(如 10 → 11 → 12):
apt full-upgrade
Apache 会保留 /etc/apache2,但:
升级后:
apache2ctl configtest
systemctl restart apache2
✅ SELinux(Debian 默认无)
✅ 端口冲突(80 / 443)
✅ PHP 版本不一致
✅ 证书路径变化(Let’s Encrypt)
如果你愿意,可以告诉我:
我可以给你更精确的命令。