Hosting multiple local sites with XAMPP

Greg picture Greg · Sep 7, 2010 · Viewed 37.5k times · Source

I'm new to using XAMPP so this may be simple to some people.

I have a few php projects that I would like to be able to debug locally and view in the browser (not concurrently, but without having to change config files/copy project folders each time I want to work on a different project).

On IIS, you could set up multiple sites to serve from your machine, and I'm looking for something similar in XAMPP. When using IIS, I added multiple records to the Windows hosts file so I could access the locally hosted sites by typing friendly web-style addresses (like http://myproject1.dev)

Thanks.

Answer

jbnunn picture jbnunn · Sep 7, 2010

Greg, you're almost there--you need (like Moses said) to setup virtual hosts.

So if your Windows hosts file has

127.0.0.1    localhost
127.0.0.1    mysite-dev.com
127.0.0.1    anothersite-dev.com

Your virtual hosts file (httpd-vhosts.conf) might look like:

<VirtualHost *:80>
  DocumentRoot C:/xampp/htdocs/
  ServerName localhost
</VirtualHost>

<VirtualHost *:80>

    ServerName mysite-dev.com

    DocumentRoot "C:/sites/mysite-dev"

    <Directory "C:/sites/mysite-dev">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

<VirtualHost *:80>

    ServerName anothersite-dev.com

    DocumentRoot "C:/sites/anothersite-dev"

    <Directory "C:/sites/anothersite-dev">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

Don't forget to restart the web server after you make any changes.