Apache VirtualHost and localhost

apachelocalhostvirtualhost

I'm working with XAMPP on Mac OS X.

I'm trying to run a Symfony website properly for a client, and I really don't know Symfony (yet). I just want to install and launch it.

I've changed my /etc/hosts file this way:

127.0.0.1 www.mysite.local

And the httpd.conf file this way:

<VirtualHost *:80>
  ServerName www.mysite.local
  DocumentRoot /Applications/MAMP/htdocs/mysite/web
  DirectoryIndex index.php
  <Directory /Applications/MAMP/htdocs/mysite/web>
    AllowOverride All
    Allow from All
  </Directory>
  Alias /sf /Applications/MAMP/htdocs/mysite/lib/vendor/symfony/data/web/sf
  <Directory "/Applications/MAMP/htdocs/mysite/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

Now, the site is working (yay!), but I can't access any more any of my other local sites because localhost is rendered as www.mysite.local.

Where am I wrong?

Best Answer

This worked for me!

To run projects like http://localhost/projectName:

<VirtualHost localhost:80>
   ServerAdmin localhost
    DocumentRoot path/to/htdocs/
    ServerName localhost
</VirtualHost>

To run projects like http://somewebsite.com locally:

<VirtualHost somewebsite.com:80>
     ServerAdmin webmaster@example.com
     DocumentRoot /path/to/htdocs/somewebsiteFolder
     ServerName www.somewebsite.com
     ServerAlias somewebsite.com
</VirtualHost>

The same for other websites:

<VirtualHost anothersite.local:80>
     ServerAdmin webmaster@example.com
     DocumentRoot /path/to/htdocs/anotherSiteFolder
     ServerName www.anothersite.local
     ServerAlias anothersite.com
</VirtualHost>
Related Topic