温馨提示×

如何在Debian上装Apache

小樊
44
2026-07-10 01:43:49
栏目: 智能运维

在 Debian 上安装 Apache(通常指 Apache HTTP Server)非常简单,以下是标准步骤(适用于 Debian 10/11/12 等主流版本):


一、更新软件包索引

sudo apt update

二、安装 Apache

sudo apt install apache2

安装完成后,Apache 会自动:

  • 安装服务
  • 启动服务
  • 配置开机自启

三、检查 Apache 状态

sudo systemctl status apache2

如果看到 active (running) 表示运行正常。

常用命令:

sudo systemctl start apache2    # 启动
sudo systemctl stop apache2     # 停止
sudo systemctl restart apache2  # 重启
sudo systemctl reload apache2   # 重新加载配置

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

sudo ufw allow 'Apache Full'

查看规则:

sudo ufw status

五、测试 Apache 是否成功

在浏览器中访问:

http://服务器IP

或本地:

http://localhost

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


六、网站目录与配置文件

默认网站目录

/var/www/html

常用配置文件

/etc/apache2/apache2.conf        # 主配置
/etc/apache2/sites-available/   # 可用站点
/etc/apache2/sites-enabled/     # 已启用站点
/etc/apache2/mods-available/    # 可用模块

七、启用/禁用站点(示例)

sudo a2ensite 000-default.conf   # 启用站点
sudo a2dissite 000-default.conf  # 禁用站点
sudo systemctl reload apache2

八、启用常用模块(可选)

sudo a2enmod rewrite
sudo systemctl restart apache2

九、常见问题检查

  • 端口 80 是否被占用
  • 是否安装并启动了防火墙
  • 是否修改了配置但未 reload

如果你需要:

  • 配置 虚拟主机
  • 开启 HTTPS(Let’s Encrypt)
  • 部署 PHP / Python / 反向代理
  • Debian 最小安装 / 云服务器 上配置

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

0