Thursday, 2 July 2009

Setting up XAMPP local server for working on several sites in a custom directory

  1. Download XAMPP (if you need a portable version, choose zip package).
  2. Double-click on setup_xampp.bat file in the root XAMPP directory (if you have downloaded non-installer version). This should be done only once.
  3. Launch xampp-control.exe. This is the control center for all XAMPP services. Start Apache and check if everything goes fine by pointing your browser to http://localhost.
  4. Now let's assume you have all your sites here: D:\My Documents\Sites, and you need to setup local server for the site which is located in the "Mysite" subfolder. You want it to be accessible in the browser from address mysite.localhost. In the XAMPP folder, go to apache\conf\extra\ and open with a text editor the file httpd-vhosts.conf.
  5. Add this to the end of the file:
    NameVirtualHost 127.0.0.1:80
    <VirtualHost 127.0.0.1:80>
    DocumentRoot "D:\My Documents\Sites\"
    ServerName localhost
    </VirtualHost>
    <VirtualHost mysite.localhost>
    DocumentRoot "D:\My Documents\Sites\Mysite"
    ServerName
    mysite.localhost
    ServerAlias
    mysite.localhost
    <Directory "D:\My Documents\Sites\Mysite">
    Order allow,deny Allow from all
    </Directory> </VirtualHost>
  6. Replace D:\My Documents\Sites, D:\My Documents\Sites\Mysite etc. with the appropriate locations.
  7. Save and close the file.
  8. Now open C:\Windows\System32\drivers\etc\hosts file. Add to it this line:

    127.0.0.1 mysite.localhost

  9. Save and close, start Apache server via xampp-control.exe. now you should see your site at the mysite.localhost address.