在 Debian 上安装 Apache(通常指 Apache HTTP Server,即 apache2)非常简单,下面是常用步骤:
sudo apt update
sudo apt install apache2
安装完成后,Apache 会自动启动。
sudo systemctl status apache2
如果未启动,可手动启动:
sudo systemctl start apache2
设置开机自启(一般默认已开启):
sudo systemctl enable apache2
在浏览器中访问服务器 IP 地址:
http://服务器IP
如果看到 Apache2 Debian Default Page,说明安装成功。
/var/www/html/etc/apache2/apache2.conf/etc/apache2/sites-available/etc/apache2/sites-enabled/etc/apache2/mods-available、mods-enabled例如创建一个站点:
sudo nano /etc/apache2/sites-available/example.conf
示例内容:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example
<Directory /var/www/example>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
启用站点:
sudo a2ensite example.conf
sudo systemctl reload apache2
sudo systemctl start apache2 # 启动
sudo systemctl stop apache2 # 停止
sudo systemctl restart apache2 # 重启
sudo systemctl reload apache2 # 平滑重载配置
如果你需要 配置 HTTPS(SSL)、PHP 支持 或 防火墙(ufw)设置,可以继续告诉我你的 Debian 版本(如 Debian 11 / 12)。