如何在Ubuntu 20.04上安装Apache

通过APT包管理器安装Apache。

$ sudo apt update
$ sudo apt install apache2

我们可以使用SystemD的SystemCtl命令来控制服务。

在系统启动时启用或者禁用Apache:

$ sudo systemctl enable apache2
OR
$ sudo systemctl disable apache2

启动或者停止Apache Web服务器:

$ sudo systemctl start apache2
OR
$ sudo systemctl stop apache2

重启或者重新加载Apache Web服务:

$ sudo systemctl restart apache2
OR
$ sudo systemctl reload apache2

如果使用了UFW防火墙,则开放80(http) 和443 (https)端口

$ sudo ufw allow http
AND (if applicable)
$ sudo ufw allow https

使用浏览器打开 http://localhost,将可以看到默认apache页面

在ubuntu中,apache的默认的站点根目录为/var/www/html

我们可以创建新的index.html:

$ echo Apache on Ubuntu 20.04 > index.html
$ sudo mv index.html /var/www/html

重新访问 http://localhost

要使用Let’s Encrypt设置SSL加密,安装CERTBOT实用程序:

$ sudo apt install certbot python3-certbot-apache

为站点配置SSL证书:

$ sudo certbot --apache
日期:2020-07-07 20:55:21 来源:oir作者:oir