Set up a Windows test server using XAMPP

Last modified: February 12, 2009 - 23:57

XAMPP for Windows makes setting up a local test server on your computer very easy. As well as providing the WAMP stack (Windows, Apache, MySQL and PHP) it includes both PHP versions 4.x and 5.x which you can easily switch between. It also includes PHPMyAdmin which is very useful for dealing with your MySQL databases.

(NOTE: XAMPP is only intended for use as a local test server which is available on your own computer. It has been created for ease-of-use, but not for production level security. If you want to tinker with security here is a guide about making XAMPP secure.)

Installation

The installation of XAMPP is very straightforward. Rather than repeat the installation instructions here, just follow the instructions on the XAMPP site

Once you have downloaded and installed the package you may like to do some further configuration...

Configuring XAMPP

Creating virtual hosts

If you do not want to keep your files in the xampp/htdocs directory and type in a long URL for every page load, you can create virtual hosts for each of your sites instead. For example, you may like to keep all your sites in your My Documents folder for easy backup. Or you could create a root directory on your hard drive such as c:/sites/example/ which will make using shell commands easier. Wherever you choose to store your sites, you can always easily move them at a later date.

With XAMPP you set up virtual hosts in the following file:

\xampp\apache\conf\extra\httpd-vhost.conf

Open up that document in your text editor and append the following information to the bottom:

NameVirtualHost 127.0.0.1:80

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

The above only needs to be added once and you don't need to change any details to the above.

The next step, however, needs to be carried out for each site. Copy the code below and add it to the bottom of the file.

<VirtualHost example.local>
  DocumentRoot "C:\path\to\your\site"
  ServerName example.local

  CustomLog "C:\path\to\your\site\logs\example.local.access.log" combined
  ErrorLog "C:\path\to\your\site\logs\example.local.error.log"

  <Directory "C:\path\to\your\site">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

You will need to makes some alterations for your personal setup.

Where it says example.local put the URL you would like to type into your browser to find your site. You can call this what you like, but make sure it relates to the site you are creating and is not a real URL that you may like to access on the Internet otherwise you will get a namespace clash. Using the production site's URL but replacing .com or whatever with .local works well.

Where it says "C:\path\to\your\site" add the directory where your site is going to be stored on your local drive. Note that you should NOT include a slash on the end of the path. You can also set up a place to keep error and access logs for these sites. You will need to create the directory structure for these, but not the individual files (i.e. create the directory structure C:\path\to\your\site\logs but Apache will create the example.local.error.log file for you).

Finally you must include the domain names in your Windows host file. This file can be found at:

C:\WINDOWS\system32\drivers\etc\hosts

open this file in your text editor and add:

127.0.0.1 example.local

You can repeat this procedure for as many sites as you wish.

When you are done, restart Apache.

Clean URLs

You will also probably want to enable clean urls. To do this in XAMPP, open up xampp\apache\conf\httpd.conf and find this line:

#LoadModule rewrite_module modules/mod_rewrite.so

and uncomment it by deleting the hash (#) so that it reads:

LoadModule rewrite_module modules/mod_rewrite.so
Restart Apache and test that clean URLs work on your site. If this doesn't work for some reason, follow the instructions on this handbook page

Xampp Portable without need for editing hosts file.

knseibert - December 1, 2007 - 12:46

Hi all,
i recently changed my setup from a VM to PortableApps. Now i have everything running form a portable usb drive. I found the Firefox Addon FoxyProxy (http://foxyproxy.mozdev.org/) very useful. Installed on my portable Firefox i simply created a new proxy which redirects all *.local request to 127.0.0.1.
With this setup i can still use Firefox for browsing the internet as well as browsing my local drupal dev site without the need to edit the hosts file on every PC i'm working on.

saving over hosts in Windows Vista

erniem - December 20, 2007 - 21:58

Vista does not let you save over the hosts file unless you're running your text editor as Administrator. This page explains how to save over hosts in Vista

http://www.gauteweb.net/?p=204

re: troubleshooting Apache and virtual hosts - n00b tip

aneymeyr - March 13, 2008 - 01:41

A tip for newbies such as myself who might have trouble getting virtual hosts to work:

I noticed that once I attempted to use a virtual host, Apache was not starting correctly via the XAMPP Control Panel. (I would click Start and the message window would say, Apache service started but I never got the green bar that said "Running".)

If this happens to you, you might be able to find a useful clue in the xampp/apache/logs/error.txt file. I realized after looking in there that I'm a total dodo and forgot to create a logs/ directory in my virtual host space (even though the directions above clearly state to do this). Without the error log file, though, I would've been changing the http-vhosts config randomly trying to solve my non-starting Apache problem.

A. Neymeyr
"sometimes you're the windshield, sometimes you're the bug"

the correct php.ini file

ajayg - March 16, 2008 - 05:19

for xampp default installation, the php settings are NOT loaded from /xampp/php.ini file

They are loaded from /xampp/apache/bin/php.ini file. Just found after banging my head several time, trying to up the max_file_uplod size. You will need to restart apache for any change to take effect.

As of xampp 1.7.1 the correct

SameerJ - June 13, 2009 - 02:33

As of xampp 1.7.1 the correct php file seems to be \xampp\php\php.ini

You can check via the phpinfo() link on http://localhost/xampp/

VirtualHost Tag

silid - May 13, 2008 - 10:07

For me I had to put

<VirtualHost 127.0.0.1:80>
  DocumentRoot "/path/to/your/site"
  ServerName example.local
...

...
</VirtualHost>

for each vhost and not put the domain name in the VirtualHost tag.

Also by not putting the disk label in it runs fine with XAMPP Portable.

Allowing Other LAN Users to See Site

mike_tt - July 23, 2008 - 21:38

I followed the above instructions and everything worked perfectly. However, I am at a small business where we have a LAN. When I had drupal installed within XAMPP htdocs, any LAN user could go to http://mycomputer_name/drupal and see the site.

Now that I've moved everything to my My Documents folder and set up the virtual host, I can see the site at http://example.local/ but no one else can.

Do I need to add

127.0.0.1 example.local

to everyone's C:\WINDOWS\system32\drivers\etc\hosts file?

exmaple.local info

rmiddle - December 15, 2008 - 22:36

Do I need to add

127.0.0.1 example.local

to everyone's C:\WINDOWS\system32\drivers\etc\hosts file?

Answer.

You need to find out what your IP address is and replace 127.0.0.1 with it. You shouldn't use this outside a local network behind a firewall as this software setup isn't secure.

Thanks
Robert

log files

joshmccormack - February 23, 2009 - 23:22

If you don't have directories setup for log files and you have these lines in:

CustomLog "C:\path\to\your\site\logs\example.local.access.log" combined
ErrorLog "C:\path\to\your\site\logs\example.local.error.log"

Apache won't start. If you're not sure if it's not restarting because of this, check your Apache error logs here: C:\xampp\apache\logs\error.log

If you want to make sure you didn't put something in wrong in your Apache configuration files, open the Command Prompt, go to c:\xampp\apache\bin and type apache -S for Apache to check your config files.

Thanks you

Sad - March 13, 2009 - 23:49

Hi all,
i recently changed my setup from a VM to PortableApps. Now i have everything running form a portable usb drive. I found the Firefox Addon FoxyProxy (Sohbet muhabbet) very useful. Installed on my portable Firefox i simply created a new proxy which redirects all *.local request to 127.0.0.1.
With this setup i can still use Firefox for browsing the internet as well as browsing my local drupal dev site without the need to edit the hosts file on every PC i'm working on.

FoxyProxy for URL redirection

bhagerty - April 15, 2009 - 05:02

This is a great suggestion, but as someone who had never used FoxyProxy, I had a hard time figuring out how to configure it.

I did figure it out, and I've now posted instructions about how to use FoxyProxy instead of modifying your /etc/hosts file when using XAMPP. Take a look at http://webdev.brianhagerty.com/development-platform/foxyproxy-for-local-... if you need more guidance about using FoxyProxy to make your development environment portable.

thanks.

yunsky - July 3, 2009 - 03:52

thank youHD LCD monitor

hi got works

konusarock - June 18, 2009 - 01:11

so good

yunsky - June 18, 2009 - 15:25

Thanks a lot. keep it up.TV studio film lighting

thank.

yunsky - July 3, 2009 - 03:52

It's nice, I am learning, thank youHD video camera battery

 
 

Drupal is a registered trademark of Dries Buytaert.