This blog is subject the DISCLAIMER below.

Saturday, August 18, 2007

Installing Drupal with PHP 5.2, Apache2.2 and MySql 5.0

Drupal is an open source Content management system (CMS) which can create rich content light weight web sites, you can visit for information about drupal.
This post targets the setup process of drupal on a Windows environment. Linux version of this post will be available soon.

Drupal is based on PHP,simply, it is a framework built using php, so in order to get it working you need to setup the environment suitable for PHP to work.

A- You need:
1- A web server (Apache is recommended for drupal however IIS is supported)
2- PHP itself
3- A data base server (Drupal supports both MYSQL 4.1+ and PostgreSql 7.3+)

1- Apache:
# you can get latest version of apache (2.2) from Here
-- Setup:
Apache is very light weight web server with very easy to install procedures.
2- PHP:
# you can download PHP 5.2.3 HERE
-- Setup:
It is recommended to download the Zip package and extract it manually to a folder usually C:\PHP

3- MySql:
# Mysql is a very efficient,light weight and easy to use data base server, currently the lastest version is 5.0 and u can find it HERE also you will find a set of usefull tools for mysql such as GUI admin which is very good instead of mysql command line.

B- Setting up PHP to work with Apache:
you need to configure apache to identify .PHP files and to process them upon request, this can be done by:
1- open the directory named Conf in the installation directory of Apache
2- edit the text file named httpd and:
- look for DirectoryIndex and add index.php so it looks like this:
DirectoryIndex index.html index.html.var index.php

- look for Addtype Section and add after the last sentence these lines
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

3- Now you need to load the php module for the apache to deal with, add these lines to the httpd file after the last LoadModule line:
LoadModule php5_module "C:/php/php5apache2_2.dll"
PHPIniDir "C:/php"
# of course directories here are relative.

What wont work:
1- Opening a .php file directly by left clicking it.
for apache to deal with a php file it has to be located in htdocs folder located in the apache installation directory and you can call a .php file by writing this in the address field of your web browser: http://localhost/"filename".php

C- Back to Drupal:
for druapl to start working you have to copy the folder named drupal-5.1 downloaded from drupal web site to the htdocs folder of apache, and type this in your web browser:
a page may appear with the message saying that your web server does provide any data base supported by drupal. How can this happen? we already installed Mysql!!!
The answer is in PHP itself, at this point you may get confused about the reason of that error and you start going in circles and reinstalling apache and PHP as well as mysql, this is not the error...
the problem is simply that mysql module is not installed in php

D- Installing Mysql to work with PHP
1- make sure that u have the Dll files requried for mysql in the ext folder (php_mysql.dll)
2- make sure that php.ini file is present in the PHP folder, AND NOT PHP.INI.RECOMMENDED, rename this to php.ini.
3- php.ini and look for
extension_dir = ".\" and change it to
extension_dir = ".\ext"
4- look for the line extension=php_mysql.dll in the dynamic extensions sections and uncomment it by removing the ';' on its left.

As a basic test, many sites recommend writing a simple php script file the returns php info on your machine and running it to make sure that everything is fine, however, on some machines - including mine- after setting up the mysql module, this simple script does not work. To test, just point to this in your browser http://localhost/drupal-5.1
it is supposed now that you will see a database configuration page with the drupal logo above, this indicates that we are approaching the last step.

E- Drupal into action:
drupal needs a database with full access permissions to manipulate many aspects for building and managing sites, so we need to create a database in Mysql dedicated to Drupal, this can be done by writing some commands to the command line:
1- create a database in mysql for example named "drupaldb"

  mysqladmin -u username -p create drupaldb
2- manage ur database

mysql -u username -p

3- Setting the permissions to the user u created and logged in with to mysql, as this user
name will be supplied to drupal to work with it


TEMPORARY TABLES, LOCK TABLES ON drupaldb.* TO 'username@localhost' IDENTIFIED BY 'password';

where user name is the drupal user name and password is this user's password.

now, supply the required information to the database configuration page of drupal, and hopefully every thing works now :).


muds said...

Your web server does not appear to support any common database types. Check with your hosting provider to see if they offer any databases that Drupal supports.

muds said...

Followed your steps, but still get the same error at the installation page:

"Your web server does not appear to support any common database types. Check with your hosting provider to see if they offer any databases that Drupal supports."

Anonymous said...

I followed your steps, and fixed my httpd.conf file, but still received the error. I rebooted and then everything worked fine.

Thanks for the fine instructions.

Anonymous said...

I followed these intstructions but I still got the error about PHP not supporting mysql. The problem was that my php.ini file did not have the right permissions and was not being loaded. If you're using NTFS on Windows NT, 2000, XP or 2003, make sure that the user running the web server has read permissions to your php.ini (e.g. make it readable by Everyone).

You can check if php.ini is loaded or not by using "phpinfo();". Pay special attention to the data returned in "Loaded Configuration File". If it does not show a path and the PHP.INI file name, the file is not being loaded, which means that the mysql extension is not loaded either.

xtykc said...

I followed your steps,still get the same error,but I restart my computer,then it works,thank you!