简体   繁体   English

Apache配置,无法连接到本地主机

[英]Apache Configuration, Cannot Connect to Localhost

I'm running into an issue with Apache 2.4.18 (on OS X El Capitan 10.11.6), and I cannot pinpoint what the cause is. 我在Apache 2.4.18(在OS X El Capitan 10.11.6上)遇到问题,我无法查明原因是什么。 I've spent 4 days trying to resolve this (including searching here), but I'm throwing in the towel and just asking. 我花了4天的时间来解决这个问题(包括在此处搜索),但我只是想问问。

I have little experience here. 我在这里经验很少。 Following a few guides last weekend, I attempted to set up my system to allow me to develop a site as I work on learning HTML/Javascript/PHP. 在上周末遵循了一些指南之后,我尝试设置系统,以便在学习HTML / Javascript / PHP时开发一个站点。 Following a few guides, I installed dnsmasq and attempted to configure httpd.conf and httpd-vhosts.conf. 按照一些指南,我安装了dnsmasq并尝试配置httpd.conf和httpd-vhosts.conf。 Initially, localhost directed me to the "It Works" page, as did my virtual hosts home.dev and sites.dev. 最初,本地主机将我定向到“ It Works”页面,我的虚拟主机home.dev和sites.dev也是如此。 No matter what I did, I couldn't get any *.dev site to direct to my actual index.html file in my virtualdocumentroot. 无论我做什么,我都无法获得任何* .dev站点来定向到我的virtualdocumentroot中的实际index.html文件。

I've tried 我试过了

  • Adding home.dev to /etc/hosts home.dev添加到/etc/hosts
  • Turned on web sharing 开启网络共享
  • Checked firewall - Port 80 is open 检查防火墙-端口80已打开
  • Changed DocumentRoot in httpd.conf to root used in virtual hosts file httpd.conf DocumentRoot更改为虚拟主机文件中使用的根
  • Tried many different httpd-vhosts.conf configurations. 尝试了许多不同的httpd-vhosts.conf配置。
  • Checked quotes around my directory - initially using textedit they were different, changed in sublime 2. 检查目录中的引号-最初使用textedit时它们是不同的,在sublime 2中进行了更改。
  • Run apachectl configtest - Syntax is ok 运行apachectl configtest语法可以

Now the issue has gotten worse. 现在问题变得更糟了。 In working with config files trying to fix this, I've broken something, and I have no idea what. 在使用配置文件尝试解决此问题时,我已经坏了一些东西,我也不知道该怎么办。 Accidentally overwrote the httpd.conf file in originals folder. 意外覆盖了Originals文件夹中的httpd.conf文件。 Attempted to use httpd.conf file I found searching for the default, does not work. 尝试使用我发现搜索默认值的httpd.conf文件不起作用。 At this point, I'd be happy just to see 'It Works' again... 在这一点上,我很高兴再次看到“它起作用” ...

  • Localhost, 127.0.0.1, home.dev, etc all open an 'is not available' or refused connection page. Localhost,127.0.0.1,home.dev等均打开“不可用”或拒绝的连接页面。
  • Running sudo netstat -an | grep ':80' 运行sudo netstat -an | grep ':80' sudo netstat -an | grep ':80' returns nothing, so from the little I understand, it appears apache is not listening on 80, even though there's an explicit statement listen 80 in httpd.conf . sudo netstat -an | grep ':80'返回任何内容,因此,据我所知,即使httpd.conf有一个显式语句listen 80 ,apache也不监听80。
  • Run apachectl configtest - Syntax still ok 运行apachectl configtest语法仍然可以
  • Run sudo apachectl restart - appears to start 运行sudo apachectl restart似乎开始
  • Read somewhere, someone mentioned /var/log/apache2 could be missing and cause error, it's there. 在某处阅读,有人提到/ var / log / apache2可能丢失并导致错误,它在那里。 Error log doesn't have anything 错误日志没有任何内容

Not sure if I should post my .conf here, any suggestions? 不知道我是否应该在此处发布.conf,有什么建议吗?

Thanks! 谢谢!

Update 8/20: 更新8/20:

Still haven't found a solution, but feel like I'm making progress: 仍然没有找到解决方案,但是感觉我正在进步:

  • ping localhost is successful (64 bytes from 127.0.0.1) ping localhost成功(来自127.0.0.1的64个字节)
  • curl -v http://localhost/ returns 'connection refused' on all attempts (::1, fe80::1, 127.0.0.1, etc). curl -v http://localhost/在所有尝试中均返回“拒绝连接”(:: 1,fe80 :: 1、127.0.0.1等)。

Somewhere, it appears apache is running (right??), I just don't understand where or how to figure it out. 某个地方,似乎apache正在运行(对吗?),我只是不知道在哪里或如何弄清楚。

  • sudo lsof -i -P | grep -i "listen" sudo lsof -i -P | grep -i "listen" does not return anything listening on *:80. sudo lsof -i -P | grep -i "listen"不返回任何监听*:80的内容。 Also don't see any processes that sound like apache (only launchd, dnsmasq, mysqld, kdc, and Skype). 也看不到听起来像apache的任何进程(仅启动,dnsmasq,mysqld,kdc和Skype)。

  • my hosts file is set as such: 我的主机文件设置如下:

    127.0.0.1 localhost 127.0.0.1本地主机
    255.255.255.255 broadcasthost 255.255.255.255广播主机
    ::1 localhost :: 1本地主机
    fe80::1%lo0 localhost fe80 :: 1%lo0本地主机

  • httpd.conf (previously Listen 80, this change didn't fix anything) httpd.conf(以前听80,此更改未解决任何问题)

    Listen 0.0.0.0:80

  • No errors in error log since 2 days ago when I accidentally deleted ServerName out of httpd.conf (added it back):) 自从两天前我从httpd.conf中意外删除ServerName以来,错误日志中没有错误(添加回去):)

Is there a netstat/lsof command I can enter and figure out what port apache is listening on? 我可以输入netstat / lsof命令并找出正在监听的端口apache吗? Maybe that will get me started in the right direction here. 也许这会让我朝正确的方向开始。

Update: 更新:

For anyone else who encounters this, hopefully I can save you the week I spent trying to fix this. 对于遇到此问题的其他任何人,希望我可以节省您尝试解决此问题的时间。

Checked Console to find "ReportCrashes" for httpd (even though sudo apachectl start appeared to work,and when running the command again I would get a service already loaded message.) Searching for crumbs I came across https://discussions.apple.com/thread/6602475?tstart=0 . 检查控制台以找到httpd的“ ReportCrashes”(即使sudo apachectl start似乎可以正常工作,并且再次运行该命令时,我会收到service already loaded消息。)搜索碎屑时,我遇到了https://discussions.apple.com / thread / 6602475?tstart = 0

As simple as it sounds, commenting out the load PHP module in httpd.conf LoadModule php5_module libexec/apache2/libphp5.so fixed everything. 听起来很简单,注释掉httpd.conf中的load PHP模块LoadModule php5_module libexec/apache2/libphp5.so修复了所有问题。 I can now access localhost. 我现在可以访问localhost。 In the confusion I created for myself making changes, I assumed it was in the .conf file, but didn't have the original to revert to or see the issue. 在我为自己进行更改而造成的混乱中,我假设它位于.conf文件中,但是没有原始内容可恢复或查看该问题。 Obvious advice - make a backup before you change .conf files. 明显的建议-在更改.conf文件之前进行备份。

Now, of course, I can't use PHP, so if anyone has any tips there, that would be awesome. 现在,当然,我不能使用PHP,因此,如果有人在那里有任何提示,那将很棒。 Libphp5.so exists in /libexec/apache2, but I also found Libphp7.so in /usr/local/php5/ (version issue??) Libphp5.so存在于/ libexec / apache2中,但我还在/ usr / local / php5 /中发现了Libphp7.so(版本问题?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM