Brought to you by molecularsciences.org.
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
This publication may not be redistributed without this notice.

Setting up drupal on microsoft windows

Since drupal requires Apache, MySQL, and PHP. Most people new to drupal usually do not have Apache, MySQL and PHP installed and properly configured. Therefore, I would cover their installation and configuration as well. So Let's begin:

Setting up Drupal on Windows

You can either install a pre-built package such as the one offered at devside.net or set up your own system. The pre-built versions are usually up an ready in a few minutes but give much less flexibility and you panic every time you encounter even a minor configuration issue. Setting up your own system is much more rewarding as you learn more about your system and also end up with a system which suits your needs better.

If you wish to use the pre-configured package, available at devside.net, go to http://drupal.org/node/195238 for installation instructions.

To build your own system, continue reading.

Installing Apache on Microsoft Windows

Here I describe installation and configuration of Apache 2.2.6. These instructions should be valid for version 2.0.x and above.

Download

1. Go to http://www.apache.org/dist/httpd/binaries/win32/
2. Choose a mirror.
3. Click on the latest MSI Installer Package release. Something like apache_2.2.6-win32-x86-no_ssl.msi

Installation

1. Double-click on the .msi file you downloaded
2. Click on next
3. Accept license and click on next
4. In the Server Information window, input the following:
Network Domain: localhost
Server Name: localhost
Admin Email: admin@localhost
Check for All Users, on Port 80, as a Service and click on next
5. Choose Typical and click on next
6. Click on change and change Installation directory to c:\Apache2.2\
7. Click on next and Install

Starting stopping and restarting Apache

After the installion, Apache2 starts automatically. You should also see the start icon in the system tray. It is composed of a feather and the play symbol. You can click on this icon to start, stop or restart Apache. Alternately you can go to:

Start > All Programs > Apache HTTP Server 2.2.x > Control Apache Server

From here you can choose to start, stop, or restart Apache. Once, you install your server, I recommend that you restart the server to see if there are any errors.

The requested operation has failed!
If you get "The requested operation has failed!" error, then you need go to

Start > All Programs > Apache HTTP Server 2.2.x > Configure Apache Server > Test Configuration

to find the error. If nothing else works, uninstall and reinstall Apache.

Another Apache service is already running
You get this error message when you have multiple installations of apache. Several pre-configured server packages such as the one provided by http://www.devside.net install Apache. The easiest solution is to remove other apache installations. If you, however, wish to have multiple copies, you can go to http://www.heritage-tech.net/336/setting-up-multiple-apache-local-web-si... to get some guidance.

Checking Apache error log

To check Apache error log, you need do the following:

Start > All Programs > Apache HTTP Server 2.2.x > Review Server log File > Review Server Log

All errors generated by Apache are logged in this file.

Testing the installation
Open your browser and type: http://127.0.0.1/ or http://localhost/. If you see the words "It works!", then your server is up and running. If it doesn't, then restart Apache service and try again.

Pointing Apache to your files

By default, Apache points to c:\Apache2_2\htdocs, where c:\Apache2_2 is the installation directory we defined earlier. Suppose we would like to create out website at c:\www, we would have to point Apache to this address. To do so, we need to edit the httpd.conf file. There are two ways to to this. We can either go to:

Start > All Programs > Apache HTTP Server 2.2.x > Configure Apache Server > Edit the httpd.conf Configuration File

or simply open c:\Apache2_2\conf\httpd.conf with notepad.

Before you modify httpd.conf, you MUST create a backup copy of this file.

1. create folder c:\www
2. create an html file called index.html inside c:\www
3. Place the following html inside index.html

<html><body>I see you</body></html>

4. Search for DocumentRoot.
5. Put a '#' symbol in front of DocumentRoot "c:/Apache2_2" to comment it out
6. Type DocumentRoot "c:/www" underneath this line.
7. Search for <Directory "c:\Apache2_2\htdocs">
8. Put a '#' symbol in front of <Directory "c:\Apache2_2\htdocs"> to comment it out
9. Type <Directory "c:\www"> underneath this line.
10. Restart Apache service
11. Type http://localhost.

If you see you "I see you", you are in business. If it didn't work, go back to httpd.conf and make sure that you made the right modifications.

Installing PHP5 on Microsoft Windows

Here I will show how to install PHP and configure it with Apache. I am using Apache 2.2.6 and Windows XP. I would be installing PHP 5.2.5. It is assumed that you have read Installing Apache on Microsoft Windows.

1. Download PHP
PHP can be downloaded from http://www.php.net/downloads.php. Get the latest Windows Binary zip package for Apache. It should be something like php-5.2.x-Win32.zip.

2. Unpack PHP distribution
- Unzip to c:\php.
- Create a copy of c:\php\php.ini-dist and rename it to c:\php\php.ini.

3. Edit php.ini
- Edit php.ini file with notepad
- Comment out doc_root with ;
- Type doc_root = "c:\www" in the line just underneath. This address corresponds to the value of DocumentRoot in httpd.conf file of Apache. If you have set it to another value, use it instead of c:\www.
- Comment out extension_dir with ;
- Type extension_dir = "c:\php\ext" in the line just underneath.

Editing httpd.conf file
httpd.conf file is used to configure Apache. Go to

Start > Apache HTTP Server 2.2.6 > Configure Apache Server > Edit the Apache httpd.conf Configuration File

At the end of the file, type the following:

# Configuring PHP5 for Apache
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "c:/php"

- The first line specifies the location of the .dll file which links Apache to PHP. Depending on your software version the name of the file would be different. However, it should have the format php5apache2_x.dll. Use the filename found inside your c:\php folder.
- The AddType directive specifies which mime type should be used for a given file extension
- PHPIniDir specifies the location of your php.ini file

- Do to DirectoryIndex found inside tag. Add index.php to DirectoryIndex. It should look something like:

<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>

Order matters. Since index.php is placed before index.html, if both files were type, index.php would be displayed by default. So if you just type, http://localhost, index.php would display. If it doesn't exist, index.html will be displayed.
Moment of Truth
Create file c:\www\index.php. Inside write some PHP code such as print "hello"; and save it. Restart Apache. Type http://localhost or http://localhost/index.php to see your file. If you see the code instead of the output, double check your modifications to the .ini files.

Installing MySQL5 on Microsoft Windows

I am using:

- Apache 2.2.6,
- PHP 5.2.5
- Windows XP
- web server root is c:\www

The instructions on this page are valid for MySQL 5.0 and higher.

1. Download MySQL
You can download mysql from http://dev.mysql.com/downloads/mysql/5.0.html#downloads . I have an AMB 64-bit processor but Windows XP is 32bit. So I could not use the 64 bit version. So I downloaded Windows ZIP/Setup.EXE (x86).

2. Unzip Software
Once the software is downloaded, you can unzip it anywhere you want.

3. Install & Configure
- double click the .exe file to start installation
- next
- choose custom
- next
- next
- install
- next
- next
- finish
Installation is complete. The configuration wizard would open automatically.
- next
- choose detailed configuration
- next
- choose developer machine
- next
- choose multifunctional database
- next
- next
- choose manual setting
- choose concurrent connections 10
- next
- next
- choose Best support for multilingualism
- next
- next
- type root password
- next
- execute

Worst Nightmare
Your worst nightmare in MySQL is to get the following error message:

can't connect to MySql server on 'localhost' <10061>

If you check the blogs, you will find hundreds of people crying for help and various different proposed solutions. The reason is the this error can occur due a whole range of problems. Finding out what exactly caused this error can be a challenge. I had to turn off my avast antivirus. Once installation was complete, I turned avast back on and everything worked fine.

Moment of Truth
Go to:

Start > MySQL > MySQL Server 5.0 > MySQL command line client

Type the password you defined. Type show databases;. If you don't get errors, your MySQL is running.

Configuring PHP to communicate with MySQL

Here I would show you how to configure your PHP with MySQL. I am using:

- Apache 2.2.6,
- PHP 5.2.5
- MySQL 5.0.25
- Windows XP
- web server root is c:\www

It is assumed that you have read the previous three articles where I show how to install Apache, install PHP, configure Apache and PHP to communicate with each other and install MySQL.

I have installed PHP on c:\php and the Apache document root is c:\www.

Configuring PHP for MySQL

To configure PHP to communicate with MySQL, we need to edit the php.ini file which, on my computer, is located at c:\php\php.ini.

Edit php.ini
First of all create a backup copy of php.ini. Then edit it to remove the semicolon from

;extension=php_mysql.dll

This would uncomment this line. On my computer, php_mysql.dll file is located at c:\php\ext\php_mysql.dll. This directory is defined in php.ini file:

extension_dir = extension_dir = "c:\php\ext"

Please verify that php_mysql.dll is actually residing at this address. If it is not, then with change this address to where it is located or copy the file to this folder. Otherwise you will get an error like 'cannot connect to mysql_connect()'.

Setting system path
Once you have made this simply but crucial modification, you need to add the php directory to the system path:

Start > Control Panel > Advanced > Environment Variables > System Variables > Path > Edit

Go to the end of the line and append ;c:\php. You need to restart your computer for this to take effect. Once your computer is restarted, go back to verify that the change is permanent.

Testing Configuration

Now we need to test if we can access the database from the web.

Start MySQL client
Start MySQL:

Start > All Programs > MySQL > MySQL Server 5.0 > MySQL Command Line Client

type your password

Create New User
You do not want to give root access to a web client, so we need to create a new user account with limited privileges; select, insert, update, and delete on one database called test.

mysql> create user 'web_user'@'localhost' identified by 'password';
mysql> grant select, insert, update, delete on test.* to web_user identified by 'password';

Create and fill MySQL table
We need to create a table with dummy data to use for testing purposes. First we choose database. Then we create a table. Finally, we fill in some data.

mysql> use test;
mysql> create table person (id int primary key auto_increment, name varchar(30));
mysql> insert into person values (null, 'Alice');
mysql> select * from person;

Write PHP script

<?php
$con = mysql_connect("localhost", "web_user", "password") or die(mysql_error());
mysql_select_db("test",$con) or die(mysql_error());

$q = "SELECT * FROM person";
$rs = mysql_query($q);

while ($field = mysql_fetch_array($rs))
{
$id = $field['id'];
$name = $field['name'];
print 'ID: ' . $field['id'] . ' - Name: ' . $field['name'];
}
}
?>

Save this file as mytest.php inside c:\www\ folder. Reminder c:\www is the Apache document root.

Run the test
Now open your browser and type http://localhost/mytest.php. You should see ID:1 - Name:Alice.

Installing and configuring phpMyAdmin

Using MySQL from a commandline client is often not very convenient. Luckily there are several graphical clients. Perhaps the best one and certainly the most widely used is phpMyAdmin. It is freely available on the Internet. In this article, you would see how to install and configure phpMyAdmin to work with MySQL. If you experience troubles with these instruction, you might want to read the previous few articles. I am using:

- Apache 2.2.6,
- PHP 5.2.5
- MySQL 5.0.25
- Windows XP
- web server root is c:\www

1. Download phpMyAdmin
phpMyAdmin can be downloaded from here. Download the latest stable version without the -rc in the file name. Something like phpMyAdmin-2.11.2.2-english.zip.

2. Unzip inside web root
Unzip inside the web root. My web root, as defined in httpd.conf file, is c:\www. After unpacking, my directory should look like c:\www\phpMyAdmin\contrib\... You would have to rename phpMyAdmin-2.11.2.2-english to phpMyAdmin.

3. Set up config file
If you have a file c:\www\phpMyAdmin\config.inc.php, back it up. If you don't, create a new file with this name. Copy-paste the following code into this file. Add your password in place of PASSWORD. It appears twice in the file.

/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* phpMyAdmin sample configuration, you can use it as base for
* manual configuration. For easier setup you can use scripts/setup.php
*
* All directives are explained in Documentation.html and on phpMyAdmin
* wiki .
*
* @version $Id: config.sample.inc.php 10142 2007-03-20 10:32:13Z cybot_tm $
*/

/*
* This is needed for cookie based authentication to encrypt password in
* cookie
*/
$cfg['blowfish_secret'] = '';

/*
* Servers configuration
*/
$i = 0;

/*
* First server
*/
$i++;

$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'PASSWORD';

/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'config';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';
/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'root';
$cfg['Servers'][$i]['controlpass'] = 'PASSWORD';
/* Advanced phpMyAdmin features */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
$cfg['Servers'][$i]['relation'] = 'pma_relation';
$cfg['Servers'][$i]['table_info'] = 'pma_table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma_column_info';
$cfg['Servers'][$i]['history'] = 'pma_history';

/*
* End of servers configuration
*/

/*
* Directories for saving/loading files from server
*/
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';

Save this file.

Run phpMyAdmin
Open you browser and type http://localhost/phpMyAdmin

Installing Drupal on Microsoft Windows

Here I will show how to install drupal. I am using:

- Apache 2.2.6,
- PHP 5.2.5
- MySQL 5.0.25
- Windows XP
- web server root is c:\www

These instructions are valid for drupal 5.0 and above. I am installing drupal 5.5.

Download and extract drupal

Drupal can be downloaded from drupal.org. Once downloaded, extract the contents of the zip file.

Copy to web server root folder

The web server root is the address where a web server such as Apache look for files it is supposed to show on the Internet. If you do not know your web root, look into your httpd.conf file. It should be inside your Apache installation directory. Open this file and look for a line that looks like:

DocumentRoot "c:\www"

The web server root is c:\www. Create a folder called drupal at this address. Copy the contents of the extracted folder inside this folder. Once done, it should look as follows:

  • c:\www\drupal\modules\
  • c:\www\drupal\themes\

Prepare database for drupal

Create a database called drupal. Create a user called drupal_user. Grant full access on drupal to drupal_user from localhost. Replace xxxxxx on the third line with a password.

mysql> create database drupal;
mysql> create user drupal_user;
mysql> grant all on drupal.* TO 'drupal_user'@'localhost' IDENTIFIED BY 'xxxxxx';
mysql> flush privileges;

Run drupal

In your browser, type http://localhost/drupal/. Your should get a page asking you to type database information. Type in the information you just type in mysql command line.

Installation problems in drupal 5.5

If you get an error message at http://localhost/drupal/, edit your settings.php file. If you still get errors, check the configuration of your Apache. Refer to previous tutorials in this series for more information.

Edit settings.php file

Settings.php file contains installation configuration information. To edit settings.php file open it with notepad. It is located at:

c:\www\drupal\sites\default\settings.php

Change

$db_url = 'mysql://username:password@localhost/databasename';

to

$db_url = 'mysql://drupal_user:password@localhost/drupal';

Replace the password with the password you chose in the previous step.

Notices

Following is a common error message:

Notice: Trying to get property of non-object in C:\www\drupal5\includes\form.inc on line 325
Notice: Undefined variable: redirect in C:\www\drupal5\includes\form.inc on line 268
Notice: Undefined variable: base in C:\www\drupal5\includes\form.inc on line 465
Notice: Undefined index: #value in C:\www\drupal5\includes\form.inc on line 1045
Notice: Undefined index: #value in C:\www\drupal5\includes\form.inc on line 1045
Warning: Cannot modify header information - headers already sent by (output started at C:\www\drupal5\includes\form.inc:325) in C:\www\drupal\includes\common.inc on line 141
Notice: Undefined variable: no_module_preprocess in C:\www\drupal5\includes\common.inc on line 1472
Notice: Undefined variable: no_theme_preprocess in C:\www\drupal5\includes\common.inc on line 1493

These errors are due to php.ini configuration. PHP notices are harmless but they can sometimes generate "headers already sent" errors. These errors would hinder installation of drupal. The solution is to configure PHP to not display notices. Edit your php.ini and set error_reporting to as follows:

error_reporting = E_ALL & ~E_NOTICE

Restart Apache and you should be back in business.