0

I am a developer and I am typically developing more than one web app at a time on my PC. I have Vista and XAMPP. How do I have multiple "localhosts" on my PC at once?

Andrew Koper
  • 6,481
  • 6
  • 42
  • 50

1 Answers1

0

Apache supports name-based virtual hosting to host multiple sites. You need to create entries in two files for every site. With XAMPP 1.8.1 and Vista, for example, if you wanted to develop with regular localhost and separately with the Zend 2 framework:

In C:\xampp\apache\conf\extra\httpd-vhosts.conf

##<VirtualHost *:80>
    ##ServerAdmin postmaster@dummy-host.localhost
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.localhost"
    ##ServerName dummy-host.localhost
    ##ServerAlias www.dummy-host.localhost
    ##ErrorLog "logs/dummy-host.localhost-error.log"
    ##CustomLog "logs/dummy-host.localhost-access.log" combined
##</VirtualHost>

##add these two entries

<VirtualHost *:80>
    DocumentRoot "[path to]/xampp/htdocs/"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" combined
</VirtualHost>

<VirtualHost *:80>
    ServerName zf2-tutorial.localhost
    DocumentRoot [path to]\xampp\htdocs\zf2-tutorial\public
    SetEnv APPLICATION_ENV "development"
    <Directory [path to]\xampp\htdocs\zf2-tutorial\public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

In C:\Windows\System32\drivers\etc\hosts

# For example:
#      102.54.94.97     rhino.acme.com          # source server
#      38.25.63.10      x.acme.com              # x client host
#add two entries where name matches ServerName in httpd-vhosts.conf
127.0.0.1       localhost
127.0.0.1       zf2-tutorial.localhost

You will probably need to open the hosts file with a text editor in administrator mode to save changes.

And shut down and restart Apache after you make the changes so they take effect.

Andrew Koper
  • 6,481
  • 6
  • 42
  • 50