启动在Ubuntu上安装的Apache,并显示默认页面
首先
因为在尝试启动通过tasksel安装的Ubuntu上的Apache并显示初始设定的默认页面时遇到了问题,所以我打算记录一下。
环境
Ubuntu 20.04.3 LTS 是一个操作系统版本。Apache 2.4 是一个网页服务器软件。
操作步骤
我会先观察一下情况。
$ sudo systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2021-12-17 08:27:02 JST; 5 days ago
Docs: https://httpd.apache.org/docs/2.4/
apachectl[135474]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, u>
apachectl[135474]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
apachectl[135474]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
apachectl[135474]: no listening sockets available, shutting down
apachectl[135474]: AH00015: Unable to open logs
apachectl[135460]: Action 'start' failed.
apachectl[135460]: The Apache error log may have more information.
systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
systemd[1]: apache2.service: Failed with result 'exit-code'.
systemd[1]: Failed to start The Apache HTTP Server.
AH00558: apache2:由于无法可靠地确定服务器的完全合格域名,因此将以下内容添加到Apache的配置文件中。
ServerName localhost:80
我会再次检查一下状态。
$ sudo systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-12-22 22:33:01 JST; 4s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 183591 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
systemd[1]: Starting The Apache HTTP Server...
apachectl[183604]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
apachectl[183604]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
apachectl[183604]: no listening sockets available, shutting down
apachectl[183604]: AH00015: Unable to open logs
apachectl[183591]: Action 'start' failed.
apachectl[183591]: The Apache error log may have more information.
systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILUREsystemd[1]: apache2.service: Failed with result 'exit-code'.
systemd[1]: Failed to start The Apache HTTP Server.
先前的错误已经解决,但仍无法启动。由于地址已在使用中:AH00072,因此将在以下进行端口检查。
$ sudo lsof -i | grep http
docker-pr 54172 root 4u IPv4 680930 0t0 TCP *:http (LISTEN)
docker-pr 54179 root 4u IPv6 684154 0t0 TCP *:http (LISTEN)
因为之前实行的Docker容器占用了80号端口,导致出现了问题,所以我删除了容器。(此处省略)
启动Apache并检查状态。
$ sudo systemctl start apache2.service
$ sudo systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-12-22 22:50:10 JST; 15s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 185411 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 185428 (apache2)
Tasks: 6 (limit: 9370)
Memory: 18.9M
CGroup: /system.slice/apache2.service
├─185428 /usr/sbin/apache2 -k start
├─185429 /usr/sbin/apache2 -k start
├─185430 /usr/sbin/apache2 -k start
├─185431 /usr/sbin/apache2 -k start
├─185432 /usr/sbin/apache2 -k start
└─185433 /usr/sbin/apache2 -k start
终于启动成功了。然后通过浏览器访问http://localhost,会显示默认页面。