Here are the steps you need to take to get a copy of a Drupal website onto your local computer for development purposes, using the XAMPP stack and a variety of tools. Many of the steps taken here have been made so that you can keep your PHP files outside the standard htdocs DocumentRoot directory of the Apache server while maintaining whatever else you have running on your XAMPP installation. A mirror of this article is located here.

1) Install XAMPP software. This gets you Apache + MySQL all set up in a few clicks. Skip this step if you have both already set up (Drupal needs things like php and mod_rewrite in your Apache build.)

2) Download a copy of your production 'drupal' database to your local MySql server. I suggest using a program like Navicat MySQL since it handles UTF-8 data properly (unfortunately my favorite free MySQL client, SQLyog, seems to lack proper UTF-8 support).

3) Create a user on your local mysql database to match the remote connection settings and give them full permissions:
% mysql> GRANT ALL PRIVILEGES ON drupal.* TO 'drupaluser'@'localhost' IDENTIFIED BY 'drupalpassword' WITH GRANT OPTION; FLUSH PRIVILEGES;

4) Get a copy of the website's PHP files for your Drupal installation (In my case, use a source control system client like Perforce) and copy them to a location you want to do your work in. An example: C:/p4/atlas-drupal/drupal. I will call this location %your_drupal_files% from here out.

5) Edit %your_drupal_files%/sites/default/settings.php and change the base URL to $base_url = 'http://localhost/drupal'; You should still be able to leave the $db_url connection setting alone.

6) Edit %your_xampp_location%\apache\conf\extra\httpd-xampp.conf and add the following lines according to where your copy of drupal lives on your computer:

     Alias /drupal "%your_drupal_files%/"
    <directory "%your_drupal_files%">
        AllowOverride AuthConfig FileInfo
        Order allow,deny
        Allow from all
    </directory>

You'll need that "FileInfo" directive if you are getting 500 errors in your Apache error log like "RewriteEngine not allowed here". You could also add these lines in standard httpd.conf if you are not using XAMPP but just plain Apache.

7) (Skip this step if you are using regular Apache and not XAMPP)
Edit %your_xampp_location%\apache\conf\httpd.conf and uncomment out the line LoadModule rewrite_module modules/mod_rewrite.so You need this so Drupal can have "clean links".

8) Edit %your_drupal_files%/.htaccess and change the RewriteBase to /drupal.

9) Restart the Apache service (with the XAMPP control panel if you are using XAMPP)

You now should be able to navigate to your sandbox development copy of the site via http://localhost/drupal

Comments

mikeatlas’s picture

Where in the handbook should this go?

sepeck’s picture

Child page here: http://drupal.org/node/22282
for now. If we can get some more articles we can make a section for test sites.

I should probably update and transfer my stuff from here: http://www.blkmtn.org/book/drupal

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

mikeatlas’s picture

done!

http://drupal.org/node/75545

Feel free to add your book pages as child pages I guess?

dbuchan’s picture

I've installed drupal 5.x in wampserver not in xamp but the problem many modules such like cck, views do not run properly, it was gone error !! my question, does xamp server get same problem just like wampserver ?

jeffrey.dalton’s picture

I found that when I put in the above mentioned line of " AllowOverride AuthConfig FileInfo" in %your_xampp_location%\apache\conf\extra\httpd-xampp.conf I get 500 errors. I removed it and put in "AllowOverride All" in its place like this:

Alias /hd4l "C:\Documents and Settings\Jeffrey\My Documents\CLIENTS\peace\site"
<directory "C:\Documents and Settings\Jeffrey\My Documents\CLIENTS\peace\site">
AllowOverride All
Order allow,deny
Allow from all
</directory>

This combined with uncommenting and moving the
LoadModule rewrite_module modules/mod_rewrite.so
in http.conf will get drupal working in a custom directory with clean urls on XAMPP : Here is the node with more to help get URL rewriting to work with XAMPP. - http://drupal.org/node/43545

Jeffrey Dalton
Creative Director & Founding Partner
BKJ Digital
https://bkjdigital.com

Aethuriel’s picture

The original doesn't work for me either, so I got it to work with

AllowOverride FileInfo Limit Options Indexes

on that line instead of All, as well.

(upon seeing http://devtime.blogspot.com/2008/02/htaccess-order-not-allowed-here.html )

druvision’s picture

I tried running multiple sites from a single codebase under xampp.

My tips:
1. It's also possible to add sites as subdomains of localhost. Configuration is similar. Advantage: it's easier to distinguish between the local and the remote site if they have the same name.

For this, the hosts file should contain definitions such as

127.0.0.1 localhost
127.0.0.1 testsite1.localhost
127.0.0.1 testsite2.localhost

2. I used the following apache virtual hosts configuration (in C:\program files\xampp\apache\conf\extra\httpd-vhosts.conf):

NameVirtualHost *:80

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

<VirtualHost *:80>
DocumentRoot "C:/Program Files/xampp/htdocs/testsite1/www/"
ServerName testsite1.localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "C:/Program Files/xampp/htdocs/testsite2/www/"
ServerName testsite2.localhost
</VirtualHost>

3. I tried to put files in different locations but got 500 errors. Instead, I used the Junction utility (http://drupal.org/node/31489) and created a symbolic link from C:\www to c:\program files\xampp\htdocs - much easier.

Amnon
-
Drupal Focused Search Engine | Drupal Israel
Personal: Hitech Dolphin: Regain Simple Joy :)

Miss Essence’s picture

Hi. I see you just successfully got a multi sites set-up working.

I have been trying to get one working for 24 hours now and still haven't succeeded. Could you please check out my post and see if you can point out where I'm going wrong?

http://drupal.org/node/111866

Duplika’s picture

This is awesome to make tests and work on a website before uploading it.
--
Duplika | http://www.duplika.net

Carlos Miranda Levy’s picture

I just wanted to clarify that the above instructions are for those wanting to set up a local test/development environment for Drupal, but not necessary if you are installing Drupal on a live server.

I just set up XAMPP on a Win2003 server, configured Apache for name-based virtual hosting by editing httpd-vhosts.conf and enabled the rewrite module in httpd.conf. I set up the virtual hosts under htdocs and everything worked smoothly.

I'm using subdomains of one of my domains to access the virtual hosts (site1.mydomain.com, site2.mydomain.com, etc.) and pointing them to the server's IP visible on the Internet.

Everything worked smoothly, no 500 errors or problems of any kind.

The instructions above, although quite useful, may confuse those wanting to do a fresh install of Drupal on a live server running XAMPP.

------
Con paciencia y calma,
sube un burro a una palma

GiorgosK’s picture

Just making a note here for others,

I needed also RewriteBase uncommented in my .htaccess file before clean url's were working
(I was getting 400 and 404 errors)

take a look at this thread > http://drupal.org/node/43545

GiorgosK
------
Web development/design blog part of the world experts network

------
GiorgosK
Web Development

Steve Halleman’s picture

I tried the steps above but am having a problem. Things were going fine until I copied the .htaccess file from my server to my local computer. Then the C:/drupal directory became hidden. I don't know if this is the root of my problem. I have followed all the steps and re-checked several times to make sure that I applied the changes as indicated. When I try to go to http://localhost/drupal the browser attempts to load www.localhost.com and times out.

I am probably doing something simple wrong, but am not familiar with the inner workings of apache to readily identify where I went astray.

Any suggestions?

Steve Halleman

joachim’s picture

Great stuff!
I set up drupal on XAMPP but I hadn't managed to get clean URLs.

We seem to have two similar pages on this topic though:
http://drupal.org/node/161975
http://drupal.org/node/75545

Keith Hurst’s picture

Hi people,

thanks for submitting this article to assist people like myself.

I have downloaded and installed XAMPP, my root installation folder being D:\Develop\XAMPP.

MySQL, Apache and PHP are fully functional. I can browse and manipulate tables in my test schema using MySQL Visual Query Browser. If I enter localhost into my browser ( firefox ) I get a redirection form the index.php file so all 3 certainly working.

I copy my Drupal download into htdocs but when I enter localhost/drupal into firefox I get...

"Access Forbidden !

You don't have permission to access the requested object. It is either read-protected or not readable by the server. yada yada yada.

Error 403"

Tearing my hair out here trying to figure out what this might be and how to correct it. I don't have a lot of hair to begin with so any help appreciated getting what seems to be a fantastic framework up and running.

Thanks
Keith

pauldawg’s picture

Thanks so much for the helpful article. For everyone else's benefit I wanted to share some findings for anyone else who is about to get started with the process.

  1. First of all, I couldn't get XAMPP to work at all. The PHP to MySQL connection was broken and I got into an endless loop with an error dialog -- right out of the box. I uninstalled XAMPP and all other applications which had a copy of libmysql.dll -- based on the desire to avoid the hell so many people have gone through trying to configure PHP to connect with MySQL -- and then installed WAMPServer instead. This worked right out of the box and I've got a nice system tray menu with links to all of my important configs and apps. Adding the Alias was a breeze, and all of the above configurations were basically the same -- with some minor differences. Anyway this is the second time I have come to this conclusion that WAMPServer is superior. I would strongly recommend it over XAMPP if you are using Windows and haven't yet installed XAMPP.
  2. The next biggest problem I had was actually downloading my monster size database backup created with phpMyAdmin-->Export. None of my locally installed MySQL Administrator apps could handle the output format or size. Luckily WAMPServer comes with phpMyAdmin installed so all I had to do next was to manually split the backup into 2 backups by exporting tables starting with A-M letters in one file and N-Z in another file. I had to do this to get past the 8 MB file upload limit -- this was the easiest method. From what I can tell there were no issues with UTF8 support in phpMyAdmin. Lastly in order to get the database to restore I had to increase the maximum packet size on my MySQL environment which was easy to do via the MySQL Console.
  3. Creating the user was ultimately easy to do as well. Although of course I forgot to update the reference to drupal.* and later wondered why the user had no access to the database -- you need to give the actual name of your database here, of course!
  4. The files transferred from my site via FTP -- not a problem there.
  5. Of course, I did have to edit both the $base_url and $db_url settings -- since GoDaddy uses an absolute URL to a different domain address (secureserver.net) and I am actually installing this on localhost. But that's a no-brainer, really.
  6. In WAMPServer adding an Alias is actually easier, it is just a popup menu in the System Tray. It doesn't let you adjust the settings though, so you'll need to open up the file that was created by adding the alias (e.g. mywebsite.conf) in the wamp/alias folder. Like everyone else above, I used the AllowOverride all option instead and this worked.
  7. The reset of the steps are all just the same in WAMPServer. Of course, unlike me, you will remember to change the "drupal" references above to the appropriate strings for your environment. Oh yeah and also, don't accidentally put a leading space at the beginning of your new local MySQL database and spend hours trying to research why you are getting the "unknown database" error when trying to run Drupal.
  8. Lastly, I would add that right away I noticed that the images I had put in my content using IMCE and TinyMCE were not showing. This is because they were added to my hosted site using a subdomain in the address, but locally I am not using a subdomain, so the references do not work. Not sure if there may be a little bit of a bug in IMCE, Image or File Upload modules which would account for this, but in any case it should be easy enough to work around.

In summary I just want to thank the writers and commentators for all of your help. Although it took me 2 days to navigate through the issues with XAMPP and my backup database, ultimately I am pretty sure I could do this from start to finish in about an hour or two now that I've been through it once. Now I can focus on more useful matters like coding and performance tuning...

And speaking of performance tuning -- I am a relative newbie to PHP, Apache, MySQL and Drupal and I have been noticing that my site which is running on my shared hosting is quite slow, and had assumed it had something to do with demand for resources from other people using the hardware -- I was wrong! From running this application locally I can see now that the main bottleneck is the CPU (specifically the cycles taken by Apache httpd.exe). Not sure if the culprit is Apache, Zend/PHP or MySQL, but the CPU is running quite heavy in a Drupal site that has a decent bunch of plugins installed. The system memory and the browser memory and performance were all fine (using an old HP Pavilion with 256 MB RAM, 2 GB virtual RAM, and a single 2.3 GHz processor) but the CPU was running close to 100% during a simple query such as "show recent posts" on a site that actually only has a total of 10 nodes, or so. It was also running heavy attempting to display uploaded images. This actually shouldn't surprise me since the phpMyAdmin installation on my hosted web site had shown me that the SQL queries were not built well or running well. My guess is that this is just making the query processing code too intensive. But who knows...

Anyway, I hope my experiences will help guide you in figuring out how to navigate these tools.

Lufferov’s picture

Don't waste your time following this guide, you will screw up your configuration and it will not work. The instructions are unclear and assume too much knowledge for a guide.

I wasted about 2 weeks trying and failing to get drupal running on XAMPP using this guide. Even with the help of Drupal experts they couldn't get it functioning. It still doesn't work now, I'm never going near another guide like this. Might as well have spent my time scratching my a**e for all the good it did me!

sepeck’s picture

You are angry over a two year old forum post?

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide