Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual hosts not working with install of macOS Sierra

I recently updated my work machine to macOS Sierra and now none of my virtual host configurations are working. I need to reconfigure all of these which is a huge pain.

I am wondering - is it normal for this to happen? Is there a way to prevent this from happening in the future when I update my operating system?

Additionally, it appears that my virtual host configuration is not working. Please see below.

I have edited /etc/apache2/extra/httpd-vhosts.conf to include:

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/Users/splashnw/Sites/tm-charts"
ServerName tm-charts.dev
ErrorLog "/private/var/log/apache2/tm-charts.dev-error_log"
CustomLog "/private/var/log/apache2/tm-charts.dev-access_log" common
</VirtualHost>

And, my /etc/hosts file has:

127.0.0.1 tm-charts.dev

When I navigate to tm-charts.dev in my browser, there is simply a message: "It works!" Not my project that I originally saw at that URL prior to installing macOS Sierra.

Can you tell me what is going wrong here? Thank you!

like image 439
Liz Avatar asked Sep 22 '16 23:09

Liz


People also ask

Where is Vhost file in Mac?

By default, the Apache Virtual Host configuration on Mac OS X is located in a single file: /etc/apache2/extra/httpd-vhosts.


2 Answers

When you updated to macOS it overwrote your "httpd.conf" file in the /etc/apache2/ folder. It also overwrote your "http-vhost.conf" file as well in the /etc/apache2/extra folder.

You need to see if you have a backup file in those directories to uncomment the lines or use this as an example to help restore your settings: http://digitalshore.io/local-web-development-environment-apache-macos-sierra-10-12/

Check both the "/etc/apache2" and "/etc/apache2/extra" folder for the http-conf~previous and http-vhost.conf~previous files to put your previous settings back

When you are done be sure to run sudo apachectl restart for the new settings to take effect.

like image 114
Chris Holcomb Avatar answered Nov 11 '22 01:11

Chris Holcomb


Also after you are done with the instructions provided by @chris-holcomb , 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

uncomment line 509:

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

to

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

as a precaution, clear your dns cache with the following command using terminal:

sudo killall -HUP mDNSResponder

Finally, restart apache:

sudo apachectl restart

Source: Apple Stack Exchange

like image 36
Ahmad Mushtaq Avatar answered Nov 11 '22 00:11

Ahmad Mushtaq