Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual hosts not working on MAMP

I am running into virtual hosts setup issues on MAMP. Here is my vhosts config

NameVirtualHost *

<VirtualHost *>
        ServerName dev.local.com
	DocumentRoot “/Applications/MAMP/htdocs/local”
</VirtualHost>

<VirtualHost *>
        DocumentRoot /Applications/MAMP/htdocs
        ServerName localhost
</VirtualHost>

Here is my hosts file

127.0.0.1       localhost
127.0.0.1       dev.local.com

now when visiting localhost and dev.local.com both are pointing to index of local directory. I tried various config setting in vhosts file but none is working. I am on MacBook Pro 10.10

like image 476
user6166 Avatar asked Mar 05 '15 19:03

user6166


2 Answers

I didn't find any of the answers useful, so if other suggestions don't work for you:

Consider that the virtual hosts need to be correctly enabled/included by uncommenting

Include conf/extra/httpd-vhosts.conf in C:\MAMP\conf\apache\httpd.conf and NOT in C:\MAMP\bin\apache\conf or C:\MAMP\bin\apache\conf\original .

There're multiple locations that have MAMP configuration, make sure to uncomment that line in the correctly located file.

like image 107
Dmitriy Kravchuk Avatar answered Oct 08 '22 20:10

Dmitriy Kravchuk


When I first test virtual host (example.dev) I added two slightly different index.php files its directry and to localhost directory (/htdocs). My virtual host would redirect to locahost, I would know because the index.php would be the one in /htdocs. Similar to what user6166 said, I changed the code below to match the 8888 and it worked! I test example.dev:8888 and it works.

 NameVirtualHost *:8888

<VirtualHost *:8888>
    ServerName dev.local.com
    DocumentRoot /Applications/MAMP/htdocs/local
    ServerAlias dev.local.com
</VirtualHost>

<VirtualHost *:8888>
    DocumentRoot /Applications/MAMP/htdocs
    ServerName localhost
</VirtualHost>

Then to remove 8888 change above back to 80 and MAMP preferences to:

Apache Port:80
Nginx Port:8888
mySQL Port:3306

Then inside httpd.conf change below to 80:

Listen 8888
ServerName localhost:8888

Hope that helps someone, it definely fixed my problem!

like image 23
Ariel guzman Avatar answered Oct 08 '22 21:10

Ariel guzman