Blog Entry - 20th February 2008 - Programming - General

Installing Apache, PHP, and MySQL in Vista


Following a recent upgrade to Vista, I have installed the WAMP platform (Windows-Apache-MySQL-PHP), to continue development of my website.

One has to be careful with Vista, because: (a) you can run into compatibility issues - usually solved by switching a program's compatibility to Windows XP - Service Pack 2, and (b) because of Vista's User Account Control security structure - detailed at User Account Control Overview - which seems to create issues when you wish to have a configuration file in the C:\Program Files directory.

I don't pretend to understand it all fully, and this blog entry sets out an installation process which I have gleaned from searching third party blogs and web sites.

I would like to thank everyone who has published assistance on this.


I have installed the following versions of the software:

  • apache_2.2.4-win32-x86-no_ssl.msi
  • php-5.2.1-Win32.exe (self-extracting zip file)
  • mysql-5.0.27-win32 Setup.exe

These are not the latest versions, and it is probably advisable to download the latest, if you are doing it.

For PHP you need to get the zip file rather than the installer.

Installation Location

I chose to install outside the C:\Program Files directory.

I don't quite understand why, but some of the examples I found did this.

I think it is because whenever you chose to install in C:\Program Files the computer creates a vitual folder for you as a user, which is only accessible to you as a user; this may conflict with software which expects configuration and security settings files to be globally available to all users.

Accordingly I installed the software in the following directories:-


I don't know what the security implications are for storing outside C:\Program Files.


Ensure That You Can See File Extensions

For me this helps to see what I am doing.

Go to Start > Documents > Organise > Folder And Search Options > View > Advanced Settings > Hide Extensions For Known File Types and untick the box.

Uninstall Previous Installations

Go to Start > Control Panel > Programs and Features and uninstall the relevant software.

Also manually remove directories containing previous Apache, MySQL and PHP installations

Stop Any Services That Use Port 80

Stop The Internet Information Server Service

For Skype, go to Tools > Options and ensure that the check box Use Port 80 and 443 as alternatives is un-ticked. At the same time, type in 443 for the port in the box above that check box. I have not needed to do this myself, but some blog entries recommend it.

Turn Off User Account Control For A While

Go to Start > Control Panel > User Accounts And Family Safety > User Accounts > Turn User Account Control on or off.

Saves Nagging Alerts.

Restart Vista.

And then proceed to install Apache, PHP, and MySQL in that order.


Get The Most Recent Apache Win 32 .msi File

Save It To User > Downloads

The location isn't important.

Rename It To apache.msi

This just saves time having to type in a long file name.

Run Command Prompt As Administrator

Go to Start > All Programs > Accessories

Right-Click Command Prompt and choose Run as Administrator

At The Prompt Type cd Downloads


At The Prompt Type msiexec /i apache.msi

Runs the installer.

Run Through The Apache Installer
Server Information

Network Domain : localhost

Server Domain : localhost

Email Address : Anything You Like

Check "All Users, Port 80, As A Service"



Installation Folder

Something not in C:\Program Files.

In my case C:\WAMP\Apache

Restart Vista After Install

I am not sure this is required, but do it anyway.

Check It Works

Browse to http://localhost.

It should say It works!

If no joy, check the httpd.conf file

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

Follow the directions for fixing the configuration file.

I Get A Blank Red Error Box

This is a problem with Monitor Apache Servers.

Option 1 is to remove it from Start > All Programs > Startup

Option 2 is to set its compatibility to Windows XP Service Pack 2.

I Cannot Start and Restart Apache Servers

Right Click and Run As Admnistrator on the start and restart commands.


Download The ZIP File For The Latest Release

Do not download the installer.

I used php-5.2.1-Win32.exe which was a self-extracting zip file.

Create A Folder For The Zip

I chose C:\WAMP\PHP

Extract The Zip Into That Folder


Create and Edit php.ini

Look in your PHP directory for php.ini-recommended.

Copy to C:\Windows

Rename to php.ini

Open In Notepad

Change cgi.force_redirect [OPTIONAL]

By default this reads:-

; cgi.force_redirect is necessary to provide security running PHP as a CGI under
; most web servers.  Left undefined, PHP turns this on by default.  You can
; turn it off here AT YOUR OWN RISK
; **You CAN safely turn this off for IIS, in fact, you MUST.**
; cgi.force_redirect = 1

If you have IIS running then remove the ; and change 1 to 0.

Change extension_dir To Point To The PHP Extensions Folder

By default this reads:-

; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"

Change to your directory.

In my case it is extension_dir = "C:\WAMP\PHP\ext"

Change upload_tmp_dir [OPTIONAL]

By default this reads:-

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
;upload_tmp_dir =

Remove ; and point to the windows temp file upload_tmp_dir = "C:\Windows\Temp"

You will probably need to change Temp folder permissions for sessions to work

Change session.save_path

By default this reads:-

; Argument passed to save_handler.  In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this
; variable in order to use PHP's session functions.
; ...
;session.save_path = "/tmp"

Remove ; and change to session.save_path = "C:\Windows\Temp"

Toggle display_errors

Change to display_errors = On

Configure extension settings

This is a section which begins:-

; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.

Remove ; from the extensions you want (and have installed).

Recommended are:-





If you cannot find your extension, add it.

Change the doc_root entry in php.ini to the path to the \htdocs folder

E.g. doc_root = "C:\WAMP\Apache\htdocs"

Give PHP access to MySQL (when it is installed)

Find 2 files in your ..\PHP folder


php4ts.dll or php5ts.dll

Copy both files to your C:\Windows\System32 directory

Tell Apache PHP Exists
Open httpd.conf In A Text Editor

Go to All Programs > Apache > Configure Apache Server > Edit the httpd.conf File

Use the / character in the directory path rather than \ when inserting paths.

Find LoadModule mime_magic_module modules/

There is nothing special about this, it is just the alphabetical position in the list of Loaded Modules after which we are going to insert the php module.

Insert The Following Just After

LoadModule php5_module "C:/WAMP/PHP/php5apache2_2.dll"

Make sure to use the path name for your installation file.

For PHP5 with Apache 2.0 it will be:-

LoadModule php5_module "C:/WAMP/PHP/php5apache2.dll"

For PHP4 with Apache 2.0 it will be:-

LoadModule php4_module "C:/WAMP/PHP/php4apache2.dll"

For PHP4 with Apache 1.0 it will be:-

LoadModule php4_module "C:/WAMP/PHP/php4apache.dll"

Find AddType application/x-gzip .gz .tgz

Again, there is nothing special about this, it is just the alphabetical position.

Insert the PHP type

Insert after AddType application/x-httpd-php .php

Tell Apache About Index Files

Find DirectoryIndex index.html index.html.var

Add index.php to the end.

So you have DirectoryIndex index.html index.html.var index.php

In fact, for later Apache installations, you may find it is already there.

Test Configuration

Go to Start > Programs > Configure Apache Server > Test Configuration

It will show a black window, and vanish if there is no problem.

Restart Apache

Go to All Programs > Apache > Control Apache Server > Restart, right-click, and Run as Administrator.

Test PHP

Create and save <?php phpinfo(); ?> as test.php

Save this file into the \htdocs subdirectory where Apache is installed.

Load Browser and enter http://localhost/test.php


If you are planning to use the php_mysqli.dll extension, then for the PHP5 version I installed, you do not need to look for a libmysqli.dll as both php_mysql.dll and php_mysqli.dll use the same libmysql.dll.

For earlier PHP versions this my not be the case, and so check if libmysqli.dll is included in the distribution, and copy it also to C:\Windows\System32. Otherwise, do not use extension=php_mysqli.dll in the php.ini file.


Configure Firewall

If you install MySQL then it should configure your firewall for you. Certainly Norton 360 was configured.

For Windows Firewall I have seen the following suggested (only, I guess, if you don't have another firewall running):-

Turn Windows Firewall On

If you are using firewall other than windows firewall, turn it off and set windows firewall on. Go to Start > Control Panel > Windows Firewall where you will find

an option Turn Windows Firewall on or off click on it and turn the Windows Firewall on.

Add MySQL Port 3306 to Windows Firewall

Below the Turn Windows Firewall on or off option you will find an option Allow a program through Windows

Firewall - click on it, you will find an option Add Port - click on it and insert MySQL in the Name field and 3306 as Port number

Download the latest installer package from MySQL

I used mysql-5.0.27-win32 Setup.exe from a magazine cover disk, which is a bit out of date.

Save It To User > Downloads

Again, nothing important about this.

Right-Click on it Command Prompt and choose Run as Administrator

If you have a .msi file, then follow the same as for Apache. Rename to mysql5.msi. Open Command Prompt with Run as Administrator. At The Prompt Type cd downloads. At The Prompt Type msiexec /i mysql5.msi

Run Through The MySQL Installer

Choose Custom Install

Chose your Install to folder. In my case C:\WAMP\MySQL.

Proceed to install.

When Installed, click Configure MySQL Server now then Next

Choose Detailed Configuration then Next.

Choose Developer Machine then Next.

Choose Multifunctional Database then Next.

Install InnoDB in the Installation Path and then Next.

Choose 3306 for the network port, then Next.

Choose your preferred text encoding, e.g Best support for Multilingualism then Next.

Select both Install As Windows Service and Include Bin Directory in Windows Path then Next

Then Execute to apply settings.

If you get an error message about connecting to localhost, first click Retry. It seems to work the second time of trying!

If there is a continuing problem with applying security settings, then follow the Access Denied Error point below.

If MySQL starts up restart your PC

Browse again to http://localhost/test.php and check that there is now a box for MySQL for the phpinfo(); function.

Remember to refresh the page, in case your browser is serving up a cached version.

Access Denied Error

If you get the dreaded ERROR 1045: Access denied for user: 'root@localhost' (Using password: YES) then I think it is because MySQL did not save your password correctly when you installed. It saves the password in a user table under a mysql database, and if you did not follow any of the steps above, Windows security settings may prevent you from amending that user table, particularly if it is saved within C:\Program Files.

Assuming you included the binaries in the Windows path on installation, the solution seems to be to right click on Command Prompt, Run as Administrator and login to mysqladmin to create or amend your password for the root user.

If you do not have a password set already:-

>mysqladmin -u root password "mynewpassword"

If you are changing your password, then:-

>mysqladmin -u root --password="myoldpassword" password "mynewpassword"

You can log in to msql using:-

mysql -u root --password="mypassword"


Turn On User Account Control

If you still want it.

Restart Vista

In order to re-assert User Account Control.

Final Test

(copied from

Run the following in the MySQL command-line client:-

use test
create table emp (fname char(10), lname char(10) );
insert into emp(fname, lname) values ('John','Smith');
insert into emp(fname, lname) values('Ed','Jones');
select * from emp;

And create and run the following PHP file:-

    $link = mysqli_connect('localhost','root','password','test');
    if($link == false )

    $querystring = 'Select * from emp';
    $result = mysqli_query($link, $querystring);
    if($result == false )

    echo "Rows retrieved are ".mysqli_num_rows($result)." <br>";

    while( $record = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

        echo "First name is ".$record['fname']."<br>";
        echo "Last name is ".$record['lname']."<br>";




Sorry, comments have been suspended. Too much offensive comment spam is causing the site to be blocked by firewalls (which ironically therefore defeats the point of posting spam in the first place!). I don't get that many comments anyway, so I am going to look at a better way of managing the comment spam before reinstating the comments.

Leave a comment ...

{{PREVIEW}} Comments stopped temporarily due to attack from comment spammers.