2

I have MAMP installed in my mac. Why is it that every time I create a new site, they all go to the same folder? Here is my /etc/hosts file:

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0 localhost
127.0.0.1   localhost.funstuff
127.0.0.1   localhost.mysite
127.0.0.1   localhost.oldmysite

This is my httpd-vhosts.conf

NameVirtualHost *:8888


############ FUN STUFF PAGE##############
<VirtualHost localhost.funstuff:8888>
  ServerName localhost.funstuff
  DocumentRoot "/Applications/MAMP/htdocs/funstuff"
 ServerAlias www.localhost.funstuff

</VirtualHost>



<VirtualHost localhost.mysite:8888>
  ServerName localhost.mysite
  DocumentRoot "/Applications/MAMP/htdocs/mysite"
 ServerAlias www.localhost.mysite

</VirtualHost>

#### oldmysite ####
<VirtualHost localhost.oldmysite:8888>
  ServerName localhost.oldmysite
  DocumentRoot "/Applications/MAMP/htdocs/oldmysite/sites/oldmysite"
 ServerAlias www.localhost.oldmysite

</VirtualHost>

I've restarted the MAMP server and when I type: http://localhost.funstuff:8888/, http://localhost.oldmysite:8888 or http://localhost.mysite:8888, it all goes to the fun stuff folder.

  • Using a Mac for 'normal' use is fine but please don't use it as a web server :C – William Edwards Sep 13 '14 at 9:49
  • its for local... – gerl Sep 15 '14 at 14:43
  • How are you resolving localhost.mysite to 127.0.0.1? Did you add it to /etc/hosts? – Stephen Ostermiller Oct 11 '14 at 12:36
1

Apache doesn't recommend using domains in the <VirtualHost> declaration, I have found from experience that you will have far less trouble using an asterisk here (*) and just let the domain be matched against the ServerName value.

Also, the first virtual host site behaves as a default for whenever the name does not exactly match one of the defined virtual hosts. Therefore I would recommend if you do not want the fun stuff page to be your default site, try adding a new default VirtualHost and corresponding blank page website to your httpd.conf file.

NameVirtualHost *:8888

# Default Virtual Host Site - Blank
<VirtualHost *.8888>
 ServerName localhost
 DocumentRoot /Applications/MAMP/htdocs/default
</VirtualHost>

# Fun Stuff Page
<VirtualHost *:8888>
 ServerName localhost.funstuff
 ServerAlias www.localhost.funstuff
 DocumentRoot /Applications/MAMP/htdocs/funstuff
</VirtualHost>

# My Site    
<VirtualHost *:8888>
 ServerName localhost.mysite
 ServerAlias www.localhost.mysite
 DocumentRoot /Applications/MAMP/htdocs/mysite
</VirtualHost>

# My Old Site
<VirtualHost *:8888>
 ServerName localhost.oldmysite
 ServerAlias www.localhost.oldmysite
 DocumentRoot /Applications/MAMP/htdocs/oldmysite/sites/oldmysite
</VirtualHost>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.