Mac os下Apache无法正常启动 localhost无法访问服务器

重启电脑后apache无法正常运行,访问localhost:8080 或127.0.0.1:8080都会无法找到服务器。

探索:问题出现后,由于$ sudo apachectl start不会报任何错,但是访问localhost或127.0.0.1始终失败。

可能情况1:  没有监听8080端口

排除可能1:我的apache,我很清楚我监听了8080端口的。

可能情况2:hosts文件配置有问题

排除可能2:localhost以前就没问题,而且没改过,排除。

怀疑点:8080端口被占用

排除怀疑点:终端运行$ sudo lsof -iTCP:8080 -sTCP:LISTEN,没有发现其他程序占用,排除这个疑点。

这就奇怪了!

$ sudo /usr/sbin/httpd -k start

问题出现了:

AH00557: httpd: apr_sockaddr_info_get() failed for bogon
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName’ directive globally to suppress this message
(2)No such file or directory: AH02291: Cannot access directory ‘/private/var/log/apache2/’ for main error log
AH00014: Configuration check failed

解决方法是:

  1. 在log目录下,新建一个名为apache2的文件夹(终端$ sudo mkdir /private/var/log/apache2),
  2. 然后重启apache(终端$ sudo apachectl restart),会自动在apache2里面重新生成apache需要的日志,便可正常访问和使用apache服务了。

然后重启apache

➜ apache2 sudo apachectl start
/System/Library/LaunchDaemons/org.apache.httpd.plist: service already loaded

发表回复

关闭菜单