下面以 Debian 11 / 12 为例,介绍如何安装和部署 Apache HTTP Server。
sudo apt update
sudo apt upgrade -y
sudo apt install apache2 -y
安装完成后,Apache 会自动启动。
sudo systemctl status apache2
如果看到 active (running) 说明运行正常。
常用命令:
sudo systemctl start apache2 # 启动
sudo systemctl stop apache2 # 停止
sudo systemctl restart apache2 # 重启
sudo systemctl enable apache2 # 开机自启
如果使用了 ufw:
sudo ufw allow 80
sudo ufw allow 443
放行后测试:
sudo ufw status
在浏览器中访问:
http://服务器IP
看到 Apache2 Debian Default Page 即部署成功。
/var/www/html
/etc/apache2/sites-available/000-default.conf
sudo rm /var/www/html/index.html
sudo cp -r your_project/* /var/www/html/
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.conf
sudo nano /etc/apache2/sites-available/example.conf
示例:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example
<Directory /var/www/example>
AllowOverride All
</Directory>
</VirtualHost>
启用站点:
sudo a2ensite example.conf
sudo systemctl reload apache2
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache
如果你需要:
可以继续告诉我你的具体需求。