9

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

user6166
  • 143
  • 1
  • 1
  • 8

8 Answers8

14

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.

Dmitriy Kravchuk
  • 476
  • 4
  • 16
  • 2
    After a MAMP upgrade, the line was indeed commented in `/Applications/MAMP/conf/apache/httpd.conf`. – Anthony Feb 13 '18 at 13:56
12

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!

Ariel guzman
  • 171
  • 1
  • 4
5

Changed the hosts file like this -

NameVirtualHost *:80

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

<VirtualHost *:80>
    DocumentRoot /Applications/MAMP/htdocs
    ServerName localhost
</VirtualHost>
user6166
  • 143
  • 1
  • 1
  • 8
  • 2
    For anyone still looking. According to [this link](http://www.imore.com/how-edit-your-macs-hosts-file-and-why-you-would-want) you could also try clearing the DNS cache: `sudo killall -HUP mDNSResponder return` – DerpyNerd Apr 21 '17 at 06:58
  • @user6166 could you please take a look my question? https://stackoverflow.com/questions/52510110/virtual-host-with-mamp I have a problem when I creating with Vhost. – May Phyu Sep 26 '18 at 04:47
2

Enable virtual host in the right httpd.conf Open MAMP > File > Edit template > Apache > httpd.conf

edit or add:

# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

edit mamp httpd.conf

0

I had a similar issue with MAMP Pro 5 (after updating from version 4). One of my custom host with aliases was returning a 404 NOT FOUND error.

After a LONG troubleshoot, make sure to add the domain in the alias list.

MAMP 4

host:

test.co

alias:

sub.test.co

Becomes in MAMP 5:

host:

test.co

alias:

sub.test.co
test.co

Hope they'll get that fixed and that it helps someone!

2Fwebd
  • 2,005
  • 2
  • 15
  • 17
0

Open the main Apache configuration file, httpd.conf, which is located at

Applications/MAMP/conf/apache/httpd.conf

and Remove the hash (pound) sign from the beginning of the line that begins with Include:

Virtual Hosts

Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
D. Schreier
  • 1,700
  • 1
  • 22
  • 34
0

Try to configure MAMP ports by this way:

  1. MAMP
  2. Preferences
  3. Ports
  4. Apache port: 80 Nginx port: 8888

MAMP ports confi guration

I've had the same port values and after configurating it started working.

0

I'm not an apache expert. But I had the same problem. I think my DNS doesn't resolve my URL. When I ping exampl.dev everything looks fine, but when I enter example.dev in the browser I get an error. I always have to add http:// in front of the url.

BonisTech
  • 342
  • 3
  • 15