15

I am perplexed about the problem I am having and would really appreciate help resolving it.

I have an iMac running Mac OS X Mavericks 10.9.2

I have set up my apache to serve documents from the server root /Volume/sites/

I am using Dynamic Virtual hosts, so just by adding a directory with the *.dev suffix, it becomes a virtual host.

My hosts file is pretty basic:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1         localhost
255.255.255.255   broadcasthost
::1               localhost
fe80::1%lo0       localhost

My httpd-vhosts.conf file is as follows:

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

#allow access to the Hosts directory where your sites are
<Directory "/Volumes/sites">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    #you could configure the following to only allow access from localhost
    Order allow,deny
    Allow from all
</Directory>

#get the server name from the Host: header
UseCanonicalName Off
VirtualDocumentRoot /Volumes/sites/%0/

This all worked. And I have not changed anything in my httpd.conf file.

Yet I can't load localhost

I also cannot load 127.0.0.1

I ran the command sudo lsof -i :80 | egrep "PID|LISTEN" to see if any PID was listening on port 80. The results were empty.

I have tried to restart apache and also to stop and then start apache using

sudo apachectl stop sudo apachectl start

sudo apachectl restart

Nothing works.

I checked if apache was running by issuing the command httpd -v

The return was:

Server version: Apache/2.2.26 (Unix)
Server built:   Dec 10 2013 22:09:38

I tried to connect to localhost and 127.0.0.1 via the command line with the following result:

alisamii at alisamii in ~
$ telnet localhost 80
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
telnet: Unable to connect to remote host
alisamii at alisamii in ~
$ telnet 127.0.0.1 80
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
alisamii at alisamii in ~
$ lynx http://localhost

Looking up localhost
Making HTTP connection to localhost
Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://localhost/
alisamii at alisamii in ~
$ lynx http://127.0.0.1

Looking up 127.0.0.1
Making HTTP connection to 127.0.0.1
Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://127.0.0.1/
alisamii at alisamii in ~

Please help.

  • What did you do with this problem, as I am experiencing exactly the same thing here :( – Pmpr Mar 10 '17 at 21:55
37

Had the same problem. I deleted one of my project's folder and it became broken. In this case the site's configs should be removed from httpd-vhosts.conf and httpd.conf.

Try ping 127.0.0.1

apachectl configtest can help you to detect the problem.

  • 7
    Absolutely correct, apachectl configtest need to be your first try! Thanks. – Lucas Serafim Mar 31 '15 at 15:24
  • Warning: DocumentRoot [/Users/me/blah/blah] does not exist you can quickly find the offending line with sudo cd / && grep -rn "/Users/me/blah/blah" * – Shanimal Jun 25 '16 at 19:53
5

The problem could be that the hosts file might have been corrupted from the original ASCII encoding. I cleared all spaces and put tabs in it, ran sudo killall -HUP mDNSResponder (you can do that instead of rebooting) and after, it worked.

  • 1
    Yes, /etc/hosts was corrupted — duplicate lines, some spaces where there once were tabs... now to figure out how that happened.... – LeeGee Feb 20 '15 at 9:09
3

In my case, the issue was that the folder /private/var/log/apache2/ was gone missing for unknown reasons. Recreating it with

sudo mkdir /private/var/log/apache2

and restarting apache with

sudo apachectl restart

made the trick!

2

Refused connections are most commonly caused by a server that is not listening to the port.

Syntax errors or general config file errors will kill apache at startup (usually without reporting to error logs or terminal).

Try running sudo apachectl configtest and see if it outputs any error messages.

-1

It's Mac specific. First you have to enable Web Sharing. For Maveric it can be done as in this tutorial. https://www.youtube.com/watch?v=TgiZiTU9JVY Second, for Mac the traffic if filtered via pfctl(i.e. man pfctl) in Maveric and ipfw(man ipfw) for older version of Mac OS if you need more than port 80

  • Answers on Ask Different need to be more than just a link. It's okay to include a link, but please summarize or excerpt it in the answer. The idea is to make the answer stand alone. – nohillside Jun 27 '15 at 8:03
-2

This might help with your query. http://mallinson.ca/web-development-with-mavericks/

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • Please try to explain your answer to the query rather than just posting a link. – Jash Jacob Sep 13 '14 at 2:38

You must log in to answer this question.

protected by Community May 6 '16 at 11:13

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .