Setting Up A Local Drupal Development Environment

Skill

Setting Up A Local Drupal Development Environment

Posted in:

Soon, well eventually, the blog is going to get a refresh - and we are currently building that refresh in Drupal, which is an open source CMS. To that end, getting Drupal setup on my machine wasn't particularly a hard procedure, but is slightly complex if you aren't used to setting up a local server and database. So if you fall under that category than this tutorial is for you. First you must know that this tutorial is aimed for Windows users and Drupal 6.X. Some basic Linux and Mac OS instructions can be found in the references section of the page.

Drupal Local Install Running

We are going to start by installing a local server using XAMPP which takes care of handling Apache, Mysql, PHP, and various other development tools. You can download it here. Once it is downloaded run the installer. The first option when installing is the installation folder which defaults to C:\xampp, at least on Vista, which is just fine. The second screen is a set of options, which include a desktop icon (which I never choose), a start menu folder, and a couple of Windows service options. The screenshot below shows these settings. The only thing left to do is click the install button.

XAMPP Install Options

Now we get to handle a few items which will make Drupal happy and our lives easier. The first is setting up our Apache install to handle virtual hosts. This will allow us to put our Drupal wherever we want on our computer and will also allow us to give it a nice short domain name such as sotc.local. XAMPP stores the virtual host file, httpd-vhost.conf, at C:\xampp\apache\conf\extra. Now open this file with Notepad - I prefer Notepad++ - and we are going to add some configuration information to it. The following piece needs to be added to the end of the file. This will enable virtual hosting for 127.0.0.1 on port 80 and setup the default host. The default host is where your browser will go if you type in localhost or 127.0.0.1 and this is set by being the first virtual host in the file.

NameVirtualHost 127.0.0.1:80

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

Setting up a Virtual Host

Next we need to add the virtual host entry for our site. This is going to look similar to the one above except we are going to change the name and add a few more options. The first thing we will notice in the below host entry is in the opening tag where we get the domain name we are going to use. This can be anything as we are going to add it to our Windows host file - well it shouldn't be anything that will conflict with an existing Internet site. The DocumentRoot is where we are going setup our site and is the root directory. The ServerName is the same domain we put in the VirtualHost tag. Next we add an option to keep log information and provide a place to store them. One item to note is that the directories already need to exist. Apache will not create the directory. It will only create the log file, also the CustomLog and ErrorLog need to have be on single line each, see comment from kudrixa for more details. Lastly we have the directory options, which defines the directory, which is again pointed to our root, and adds particular options for it. These options are necessary but would take a lot to explain them fully so I will point you to Apache's documentation instead.

<VirtualHost sotc.local>
  DocumentRoot "C:\........\Drupal Local"
  ServerName sotc.local

  CustomLog
    "C:\........\Drupal Local\logs\example.local.access.log"
  combined
  ErrorLog
    "C:\.........\Drupal Local\logs\example.local.error.log"

  <Directory "C:\........\Drupal Local">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

This completes our virtual host, leaving us with a file like the one below. I have cut out some of the comments for shortness sake.

NameVirtualHost 127.0.0.1:80

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

<VirtualHost sotc.local>
  DocumentRoot "C:\.........\Drupal Local"
  ServerName sotc.local

  CustomLog
    "C:\........\Drupal Local\logs\example.local.access.log"
  combined
  ErrorLog
    "C:\.........\Drupal Local\logs\example.local.error.log"

  <Directory "C:\..........\Drupal Local">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

Now we need to tell our computer that we have setup another host on our machine. This can be done by modifying the host file. You can find this file at C:\WINDOWS\system32\drivers\etc\hosts and again I opened it with Notepad++. Inside this file I added a new entry for my local setup which looks like the following:

127.0.0.1        sotc.local

Now when I type sotc.local in the browser my local Apache server will show me the web content at C:\........\Drupal Local. Now my windows host file will look like the below, again I taken out some of the comments to shorten it.

# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.

127.0.0.1       localhost
::1              localhost
127.0.0.1       sotc.local

Enabling mod_rewrite

The next item we are going to take care of is adding the ability for clean urls, these are nice looking urls (like the one currently being used on this blog) instead of bad nondescript urls - for instance http://blog.paranoidferret.com/?p=25. In order to have this feature in Drupal we need to enable the Apache module, mod_rewrite, which allows Apache to do some url magic. You can learn more about this magic here.
So in order to get this done we need to edit the Apache configuration file, also known as httpd.conf. You can get this file at C:\xampp\apache\conf\httpd.conf as long as you installed XAMPP to C:\xampp\. Break out notepad again and open the file. We need to find the following line (search works well here):

#LoadModule rewrite_module modules/mod_rewrite.so

Once you have found it take out the pound sign (#) which will uncomment the line of code. This line will now read:

LoadModule rewrite_module modules/mod_rewrite.so

Okay, next we restart Apache which can be done using the XAMPP control panel. You can open the control panel by clicking the orange X symbol in your task tray. From the control panel you can also modify your XAMPP install. Now just stop and start Apache. The control panel will look something like the below picture.

XAMPP Control Panel

Setting up Drupal Database

One of the nice things about XAMPP is that it automatically adds phpMyAdmin (a simple way to administer MySQL) to our local server when installed. This will give us easy access to our MySQL install and allow us to add a database for Drupal. Drupal requires a database to be created before you install it. You should be able to go your phpMyAdmin install by clicking this link. You should see something very similar to the following image.

phpMyAdmin Main Screen

Next we add the database, this is very simple - just type the name into the "Create new database" text input. Now just press the "Create" button to the right of the text input and viola we have our database. Picture reference below.

phpMyAdmin Adding a Database

Installing Drupal

The final task for this tutorial is getting Drupal installed correctly. The first step in this process is downloading it from here. Downloading... downloading... downloading... done. Okay, next we extract the contents of the first folder in the .tar into our local root. So in my case my Drupal Local folder looks like:

My Local Drupal Folder

Now open up a browser window and go to your local domain that we created earlier - in my case sotc.local. This will start the installation process. First we choose a language:

Drupal Installation Language Selection

The second screen we get to is the database setup screen. We have already done all the leg work here in creating our database. So in the "Database name" box we will put drupalDB (unless you named yours differently) and in the "Database user" box we put root. By default there is no password for our local server, and this is fine since only your local machine can access it. Just click the continue button and lets keep moving. NOTE: I do not recommend using the root user or blank passwords in production environments.

Drupal Installation Database Setup

The next section is for configuring our Drupal install. The first part is the site name and site email address - you can choose whatever you like here. Next we have to put in the user information for the administrator account. I personally use very simple things here for ease of testing and development. For the username I always choose admin and the same for the password. Also don't forget to drop an email address here. The last small piece is for time zone settings and clean urls, this is what we setup mod_rewrite for. You should see a message that says the server was successfully tested for these. Finally you can decide whether to check for auto updates. Click "Save and Continue" and everything will finish up.

Drupal Installation Configuration

If all has gone well you will now have a clean local install of Drupal 6.1. I have noticed every now and then that the install process will hang after clicking the continue button on the last screen. I always let it run but open a new tab in my browser and go to sotc.local to see if it has finished. After a couple minutes most likely you will get a page like the very first image in this tutorial. Now just have some fun and get to setting up your CMS. All questions, concerns, and complaints are always welcome.

The Reddest
07/19/2008 - 14:39

Everything worked perfectly. The only glitch was that I had to create an empty settings.php file in the folder .sites/default, but the installer let me know before it would continue. Thanks for the tutorial!

reply

Tapas Chandra
03/17/2009 - 07:21

Is it php framework. What is the utility of Drupal? Did you work on it?

reply

The Reddest
03/17/2009 - 08:40

Drupal is a content management system. Kind of like Wordpress, but more powerful. This site was built with Drupal.

reply

Tapas Chandra
03/18/2009 - 00:12

How can I start with Drupal? Can you give me the details for that?

reply

The Fattest
03/18/2009 - 08:48

To get started with drupal I would suggest checking out drupal's website. Then really you could do this tutorial to get you setup locally to play around with it. From there it's up to you what direction you want to take, you can start playing around with the code, theming, or just about anything else. Also feel free to ask any questions and we will try to help out.

reply

Smita
03/17/2009 - 07:25

I will help you.... Please tell me your problem ...if you face any problem with it

reply

Tapas Chandra
03/18/2009 - 00:13

Thanks.....

reply

Anonymous
04/16/2009 - 10:26

When I type in the address of the local domain I created, I keep getting the "It Works!" message instead of the Drupal installation page. Any idea what I'm doing wrong?

reply

The Fattest
04/16/2009 - 10:36

Did you make sure to restart the apache server?

reply

Anonymous
04/16/2009 - 11:48

Yes. I just tried again and it's the same thing. I'm not sure if it's relevant, but I'm not using XAMP (I adjusted the file paths and found the files to change accordingly) because I have to run MySQL 4.1 for another application. I manually installed PHP and Apache, but both are running fine, as is MySQL 4.1. Could this have anything to do with it?

reply

The Fattest
04/16/2009 - 12:23

As long as you have the correct virtual host information in your httpd.conf file for apache things still should be fine. What does your virtual host declaration look like?

reply

kudrixa
04/16/2009 - 12:44

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

I didn't realize I needed to do something with this. I just tried to un-comment it and then Apache failed when I tried to restart.

reply

The Fattest
04/16/2009 - 13:18

yeah open up that file (the included one), it should include a bunch of junk for now. You need to put something similar to below in there. Replace the "C:\..." areas with the location of your install and then the sotc.local with what ever you put in your windows hosts file.

<VirtualHost sotc.local>
  DocumentRoot "C:\........\Drupal Local"
  ServerName sotc.local

  CustomLog
    "C:\........\Drupal Local\logs\example.local.access.log"
  combined
  ErrorLog
    "C:\.........\Drupal Local\logs\example.local.error.log"

  <Directory "C:\........\Drupal Local">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

reply

kudrixa
04/17/2009 - 07:27

Yes, I did have that in httpd.conf. I must be doing something else wrong. Is that virtual host line supposed to stay commented out in httpd-vhosts.conf?

reply

kudrixa
04/17/2009 - 13:13

I found out what it was and just wanted to share in case anyone else has this trouble. I had the CustomLog command and path on different lines and the same with the ErrorLog. Once I made each of these confined to one line, the error was fixed. Thanks for your help!

reply

The Fattest
04/17/2009 - 15:51

Glad to hear you found out what the issue was. I will update the tutorial to mention that these items need to be on a single line.

reply

dev
04/23/2009 - 03:12

Hi,

When you say
"Installing Drupal

The final task for this tutorial is getting Drupal installed correctly. The first step in this process is downloading it from here. Downloading... downloading... downloading... done. Okay, next we extract the contents of the first folder in the .tar into our local root."

What is local root here.

In httpd-vhosts.conf file I replaced your "........" with drupal. So is my local root will be
c:\drupal

After doing all this when I open a browser with sotc.local , it does not give me drupal installation as shown above. My browder leads me to http://sotc.local/xampp/

Can you let me know what to do ?

reply

Ben
08/09/2009 - 08:45

Hi,

Everything was going great until i went to restart Apache in the control panel. I click on start but it won't start running. I've done all the port checks and port 80 is free.

I went into the XAMPP folder and went to start it via the apache_start MS-DOS batch file and the DOS screen came up and said:

"Syntax error on line 55.
CustomLog takes two or three arguments , a file name, a custom log format string or format name, and an optional "env=" clause"

Now all i did was copy the code from this article and replace the C:.... bits with where i had put the Drupal folder locally:

NameVirtualHost 127.0.0.1:80

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

<VirtualHost sotc.local>
  DocumentRoot "E:\Documents and Settings\Administrator\My Documents\Drupal Local"
  ServerName sotc.local

  CustomLog
        "E:\Documents and Settings\Administrator\My Documents\Drupal Local\logs\example.local.access.log"
  combined
  ErrorLog
        "E:\Documents and Settings\Administrator\My Documents\Drupal Local\logs\example.local.error.log"

  <Directory "E:\Documents and Settings\Administrator\My Documents\Drupal Local">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

I really don't know what's wrong. Anyone got any ideas?

Many thanks,

Ben

reply

The Fattest
08/11/2009 - 22:56

Make sure that the CustomLog is all one line, same thing for ErrorLog and any other lines that break onto multiple.

reply

MaryNZ
09/10/2009 - 21:52

Hi

wondering if anyone can help, im trying to follow the instructions above, im stuck at the Restart Apache. I can click the start button, it does not turn into a stop button, the message says "Apache services started" but no green "running" appears.

If i move on and click the database link, my browser (Firefox) takes me a blank page - nothing on it.

when i was installing XAMPP right at the end an error message appeared which said:

XAMPP 1.6.6a win32 (Basic Package)
Ports 80 or 443 (SSL)already in use, installing Apache 2.2 service failed

i have run XAMPP portcheck and the status for port 80, 81 and 443 is all saying FREE

Any suggestions?

thanks :)

reply

The Fattest
09/11/2009 - 10:05

It sounds like there is an error in the apache config. I would closely check the config file, especially to make sure all commands are on a single line. Some of the commenters have had this issue.

reply

MaryNZ
09/11/2009 - 22:43

I have checked very carefully, the lines are definitely not broken:

CustomLog
    "C:\DrupalLocal\logs\example.local.access.log"
  combined
  ErrorLog
    "C:\DrupalLocal\logs\example.local.error.log"

I also went into the XAMPP folder and started via the apache_start MS-DOS batch file and the DOS screen reported:

"Syntax error on line 56.
CustomLog takes two or three arguments , a file name, a custom log format string or format name, and an optional "env=" clause"

is there anything else in the conf file that i should be checking?

reply

YuvalW
11/06/2009 - 08:54

did it as shown and ecoos.local is sending me to the xampp page saying it was installed successfully as well as localhost

reply

YuvalW
11/06/2009 - 08:57

(I changed the name to ecoos.local in all the three places)

reply

discostews
12/30/2009 - 18:58

Very good tutorial, I got my drupal installation working on the virtual server with only a little tweaking. I think there are only two points missing from the tutorial:

1.) you seem to need to use '/' instead of '\' when specifying paths in httpd-vhosts.conf.

2.) As per the questions above - to put the lines for CustomLog and ErrorLog on the one line - the word "combined" is an argument to the "CustomLog" statement - and hence should be on the same line. So the lines read:
CustomLog "path" combined
ErrorLog "path"

Hope this helps someone out!

reply

Stewy
01/04/2010 - 10:57

Hello

I would like to thanks everyone, in particular discotews for pointing out the '\' '/' issue...
I had the same problem like everyone else and I couldn't get the service to restart 'till i switched \/...
unfortunately many windows OS user (like me) are not very familiar with Unix-Linux like sintax.

Thanks again. great tutorial and great community

reply

Shay
01/18/2010 - 20:31

What a great tutorial !
Such a great time saver! Well done!

reply

Add Comment

Put code snippets inside language tags:
[language] [/language]

Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]

See here for supported languages.

Javascript must be enabled to submit anonymous comments - or you can login.

Sponsors