简体   繁体   中英

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. I've spent 4 days trying to resolve this (including searching here), but I'm throwing in the towel and just asking.

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. Following a few guides, I installed dnsmasq and attempted to configure httpd.conf and httpd-vhosts.conf. Initially, localhost directed me to the "It Works" page, as did my virtual hosts home.dev and 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.

I've tried

  • Adding home.dev to /etc/hosts
  • Turned on web sharing
  • Checked firewall - Port 80 is open
  • Changed DocumentRoot in httpd.conf to root used in virtual hosts file
  • Tried many different httpd-vhosts.conf configurations.
  • Checked quotes around my directory - initially using textedit they were different, changed in sublime 2.
  • Run apachectl configtest - Syntax is ok

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. Attempted to use httpd.conf file I found searching for the default, does not work. 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.
  • Running 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 .
  • Run apachectl configtest - Syntax still ok
  • Run sudo apachectl restart - appears to start
  • Read somewhere, someone mentioned /var/log/apache2 could be missing and cause error, it's there. Error log doesn't have anything

Not sure if I should post my .conf here, any suggestions?

Thanks!

Update 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)
  • curl -v http://localhost/ returns 'connection refused' on all attempts (::1, fe80::1, 127.0.0.1, etc).

Somewhere, it appears apache is running (right??), I just don't understand where or how to figure it out.

  • sudo lsof -i -P | grep -i "listen" sudo lsof -i -P | grep -i "listen" does not return anything listening on *:80. Also don't see any processes that sound like apache (only launchd, dnsmasq, mysqld, kdc, and Skype).

  • my hosts file is set as such:

    127.0.0.1 localhost
    255.255.255.255 broadcasthost
    ::1 localhost
    fe80::1%lo0 localhost

  • httpd.conf (previously Listen 80, this change didn't fix anything)

    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):)

Is there a netstat/lsof command I can enter and figure out what port apache is listening on? 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 .

As simple as it sounds, commenting out the load PHP module in httpd.conf LoadModule php5_module libexec/apache2/libphp5.so fixed everything. I can now access 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. Obvious advice - make a backup before you change .conf files.

Now, of course, I can't use PHP, so if anyone has any tips there, that would be awesome. Libphp5.so exists in /libexec/apache2, but I also found Libphp7.so in /usr/local/php5/ (version issue??)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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