温馨提示×

如何安装Debian Apache

小樊
35
2026-08-20 10:32:25
栏目: 智能运维

下面是在 Debian 系统上安装 Apache(httpd) 的常用方法,适用于 Debian 10/11/12 等主流版本。


一、更新软件源(推荐)

sudo apt update
sudo apt upgrade -y

二、安装 Apache

sudo apt install apache2 -y

安装完成后,Apache 会自动启动。


三、检查 Apache 状态

sudo systemctl status apache2

如果未启动,可手动启动:

sudo systemctl start apache2

设置开机自启:

sudo systemctl enable apache2

四、防火墙放行 HTTP/HTTPS(如有启用 ufw)

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload

五、测试 Apache 是否运行

在浏览器中访问:

http://服务器IP

看到 Apache2 Debian Default Page 即表示成功。


六、Apache 常见目录说明

目录 说明
/var/www/html 默认网站根目录
/etc/apache2 配置文件目录
/etc/apache2/sites-available 虚拟主机配置
/etc/apache2/sites-enabled 启用的虚拟主机
/var/log/apache2 日志目录

七、创建简单测试页面

echo "Hello Apache on Debian" | sudo tee /var/www/html/index.html

八、常用 Apache 命令

sudo systemctl start apache2     # 启动
sudo systemctl stop apache2      # 停止
sudo systemctl restart apache2   # 重启
sudo apache2ctl configtest       # 检查配置语法

九、启用 HTTPS(可选)

sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache

如果你需要:

  • 配置 虚拟主机
  • 部署 PHP / Python / 静态网站
  • 使用 Nginx + Apache
  • 在内网 / 云服务器 / Docker 中部署

可以告诉我你的具体使用场景,我可以一步步帮你配置。

0