macOS Sierra - localhost stops working when virtual host is enabled I have enabled virtual hosts on my Mac running macOS Sierra.

What I did,


Uncommented Virtual Host line in httpd.conf
Added a virtual host entry from my site in /etc/apache2/extra/httpd-vhosts.conf file.


After which when I try to access http://localhost it gives me a 404.

Initially I faced a 403, so I created a username.conf file in apache users directory and gave AllowOverride All for /

Now to access localhost I need to disable vhost. Any help?
Probably you missed one or more modifications. To enable virtual hosts in macOS 10.12.0 (Client) do the following:


edit the file /etc/apache2/httpd.conf:

uncomment line 160:

#LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so


to

LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so


replace in line 213

#ServerName www.example.com:80


by

ServerName localhost


uncomment line 509:

#Include /private/etc/apache2/extra/httpd-vhosts.conf


to

Include /private/etc/apache2/extra/httpd-vhosts.conf

edit the file /etc/apache2/extra/httpd-vhosts.conf and replace the content by

&lt;VirtualHost *:80&gt;
    ServerName localhost
    DocumentRoot "/path/to/localhost"

    &lt;Directory "/path/to/localhost"&gt;
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    &lt;/Directory&gt;
&lt;/VirtualHost&gt;


Your site has to reside in /path/to/localhost/
Check the apache config with: sudo apachectl -S. The first two lines should yield:

VirtualHost configuration:
*:80                   localhost (/private/etc/apache2/extra/httpd-vhosts.conf:23)

Start apache with sudo apachectl start
Now – after emptying the browser caches – enter localhost in the address bar of your browser.