最近在完成Linux课程作业:LAMP框架的搭建,遇到了一个困扰了我几天的问题:Apache2.4服务器无法正常启动,经过各种百度和bing搜索,终于解决了问题,感谢这次经历使自己加深了对ubuntu的理解。
1.错误描述:
当我启动或重启Apache2时,
$ systemctl restart apache2
出现如下错误
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
通过help查看错误
apache2 --help
显示错误原因是
(13)Permission denied: AH00072: make_sock: could not bind to address [::]:80
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
大意是说http协议要调用的80端口被占用了,我们可以修改端口为8080。同时我在StackOverflow上查到了一篇解决此问题的文章,感觉答主的回答很有趣,和大家分享一下https://askubuntu.com/questions/338218/why-am-i-getting-permission-denied-make-sock-could-not-bind-to-address-when
解决办法为
sudo vim /etc/apache2/ports.conf
进入设置端口的ports.conf文件,文件内容如下
1# If you just change the port or add more ports here, you will likely also
2 # have to change the VirtualHost statement in
3 # /etc/apache2/sites-enabled/000-default.conf
4
5 Listen 8080 #在此处将原端口80改为了8080
6
7 <IfModule ssl_module>
8 Listen 443
9 </IfModule>
10
11 <IfModule mod_gnutls.c>
12 Listen 443
13 </IfModule>
14
15 # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
保存后重启apache2
sudo /etc/init.d/apache2 start
正常启动
[ ok ] Starting apache2 (via systemctl): apache2.service.