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

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.

Another way via Winlamp

dudeoflife - July 22, 2009 - 06:18

Hi all

There is yet another way to set up a test server.

I recently wrote a series describing step by step how to install a drupal test site on windows using winlamp.

Easy to follow and current.

http://www.cmstips.org/content/set-free-drupal-test-site-your-pc-winlamp...

Use of forward and backward slash

whstark - August 27, 2009 - 10:03

Hi, I tryed the virtual hosts in your example and clipped right from the page, seemed to work ok, but when I tried to use sub-directories in them and they would not work, I looked and looked around with no answer, then it dawned on me that its the slashes, then looked and most sites with virtual host examples showed using forward slashes, then I findly looked in Apache DOC later by a search on google for apache file name slash problem found the apache doc, and it says:

Note
When entering a file path on non-Unix platforms, care should be taken to make sure that only forward slashed are used even though the platform may allow the use of back slashes. In general it is a good idea to always use forward slashes throughout the configuration files.

Who would Know but them to always use forward slashes on all configuration files. easy mistake to make when you clip paths to config files in windows. So your second example is wrong above, now my sub-directories work
The apache mad slash disease. I guess if I used linux more often id know.

Bill Stark
SPC student

not working

bescio - November 6, 2009 - 14:41

I did exactly this and quadruple checked the code and still the eco.local is sending me to the xampp pages and not to the c:/sites/eco that is defined in all the 3 places

 
 

Drupal is a registered trademark of Dries Buytaert.