下面是在 Debian 系统上安装 Apache(httpd) 的常用方法,适用于 Debian 10/11/12 等主流版本。
sudo apt update
sudo apt upgrade -y
sudo apt install apache2 -y
安装完成后,Apache 会自动启动。
sudo systemctl status apache2
如果未启动,可手动启动:
sudo systemctl start apache2
设置开机自启:
sudo systemctl enable apache2
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload
在浏览器中访问:
http://服务器IP
看到 Apache2 Debian Default Page 即表示成功。
| 目录 | 说明 |
|---|---|
/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
sudo systemctl start apache2 # 启动
sudo systemctl stop apache2 # 停止
sudo systemctl restart apache2 # 重启
sudo apache2ctl configtest # 检查配置语法
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache
如果你需要:
可以告诉我你的具体使用场景,我可以一步步帮你配置。