How to set up Apache, Php and MySQL on Windows for development.

This is part of a collection of Information, tips and shortcuts for Windows,
which is part of my web collection of information.


An easy-to-use, concise guide to setting up Apache/Php/MySQL on Windows

So you want to do some web development and you want to be able to do it locally on your machine? Great! You have come to the right place to find information and easy instructions to get you going. After reading this page, you should be able to easily install Apache, Php and MySQL on your Windows box and away you go with your php development, experimenting with Php/MySQL web applications and whatever other web development/experimentation you want.

NOTE: I have added the installation of PhpMyAdmin to this page, because now that you have Php and MySQL, you might as well use one of the best web interfaces to MySQL - PhpMyAdmin. PhpMyAdmin is itself a Php/MySQL web application that allows you to easily administrate your MySQL server and/or databases.

SECONDARY NOTE: This installation of Webserver/Php will not be very secure. Do not use these instructions to set up a production server. This information is intended to allow you to easily set up a server for your own use to practice, experiment and develop your web applications.

Now you decide if you want to install all four of the programs that I've got listed here or not. If you only want to develop HTML, you don't need anything more than a browser to test it. (Most browsers can read straigt from a file). If you want to learn Php, download and install Apache and Php. If you want to use the combination of Php and MySQL for developing web apps, (Php to process info and generate HTML and MySQL for storage/retrieval of info), then install all four programs. (PhpMyAdmin will make your life a lot easier when it comes to managing MySQL - you won't have to muck around with command line programs as much).

Step 1 - Download Apache, Php, MySQL and PhpMyAdmin

It might seem like a lot of work to download these four programs, but you can just start the downloads now and keep reading this page.

1. Download the programs you need.
Apache's HTTP WebserverGo to httpd.apache.org (Click here to open httpd.apache.org in a new window), look for the download link and download the latest windows installer for Apache 2.x. Apache 1.3.x is more secure for a production server, but 2.x is easier to install and configure on the Windows platform, and that's what we're aiming for.
The download looked like this in November of 2004: apache_2.0.52-win32-x86-no_ssl.msi (6.39 MB)
PhpGo to www.php.net (Click here to open www.php.net in a new window), look for the downloads link and download the latest version. (I grabbed the 5.x.x version instead of 4.x.x, but these installation instructions shouldn't be too different if you want to go with 4.x.x.) See note below on MySQL/Php compatibility
The download looked like this in November of 2004: php-5.0.2-installer.exe (2.2 MB)
The MySQL RDBMS*Go to www.mysql.com (Click here to open www.mysql.com in a new window). Find the downloads page and scroll down until you find the Windows binaries. Download the the Windows installer (I downloaded the Windows "essentials" installer - just look at the size of the other download!) Also, see note below on MySQL/Php compatibility
The download looked like this in November of 2004: mysql-4.1.7-essential-win.msi (13.4 MB)
and last but not least...
PhpMyAdmin - MySQL Management SoftwareGo to www.phpmyadmin.net (Click here to open www.phpmyadmin.net in a new window). Find the downloads page and download the latest stable version of PhpMyAdmin. I grabbed the b-zipped tarball because it was the smallest, but if don't have the capablity to uncompress the .tar.bz2 file, you can d/l the *larger* .zip file. (Sidenote: Check out the free, open-source file compression/uncompression utility from 7-zip)
The download looked like this in November of 2004: phpMyAdmin-2.6.0-pl3.tar.bz2 (1.21 MB)

*RDBMS - Relational database management system.

Note on MySQL and Php compatibility
If you have preferences as to what version of MySQL or Php you are going to use, be sure they will be compatible. If you are going to use the 4.0.x version of MySQL or lower, you will be fine with the 4.x.x version of Php. If you want to go with a newer version of MySQL (4.1.x or above, including 5.x.x), then you will have to use Php 5.x.x.
MySQl 4.0.x or lower -> Php 4.x.x is adequate
MySQL 4.1.x or higher -> Php 5.x.x is needed

Now that you have downloaded Apache, Php and MySQL, you are ready to start installing. Or if you have Apache the other can continue to download while you install the webserver.

Step 2 - Install Apache's Webserver

2. Install Apache
 A. Double-click the file you downloaded (something like apache_2.0.52-win32-x86-no_ssl.msi) to start the installer.
 B. When it asks for Network Domain enter localhost.
 C. When it asks for Server Name enter localhost again.
 D. When it asks for Administrator's Email Address enter one of your email addresses or something ficticious (you can't leave it blank).
 E. When you have the option, install for all users, port 80, as a service. This is much easier, as the webserver will automatically start with Windows and you won't have to start it manually, although you can choose the other option (port 8080, must start manually) if you want :) (This can be re-configured later as well.)
 F. Choose the Typical Setup type and click "Next".
 G. Let it install in the default folder C:\Program Files\Apache Group\ Just click "Next" and then "Install"
 H. That's about it! An icon for Apache should be in the system tray, which lets you start and stop the server. There should be a program group in your Start -> Programs menu as well, which allows you to manage Apache.
 I. To test out your new server, open a browser window and type localhost into the address bar. You should get the "It Worked" Apache page, indicating that the server is up and running and serving web pages. If you installed Apache on port 8080, not as a service, then you must start the server (From the taskbar icon or from the programs menu). Then in your browser, go to localhost:8080 (Type it in just like that- localhostcolon8080)

Let's play around with the server just a little bit

Just so you can see that you have your very own server, go to the following folder C:\Program Files\Apache Group\Apache2\htdocs\, take everything that's in that folder and dump it into a new folder (name it apache if you want) within C:\Program Files\Apache Group\Apache2\htdocs\. Now create a new file called index.html that contains the following code: (Replace the bolded apache with the name of the folder where you put the original stuff from the htdocs folder.)

<html>
    <head>
        <title>Hello World!</title>
    </head>
    <body>
        <h1>Hello World!</h1>
        <a href="apache">Apache "It Worked" Page<a><br />
    </body>
</html>

Now when you go to localhost (or localhost:8080 depending on your installation) in your web browser, you should see:

Hello World!

and a link here to the original Apache "It Worked" page.






Step 3 - Install Php

3. Install Php
 A. Double-click the file you downloaded (something like php-4.3.9-installer.exe) to start the installer.
 B. Choose the Standard installation.
 G. Let it install in the default folder C:\PHP\ Just click "Next".
 D. When it asks for SMTP server and a From email address for the mailto() function, enter real ones if you want to use the mailto() function. (I just put localhost and asdf@localhost)
 E. When it asks you to select your HTTP server, choose apache, although the installer currently doesn't support it.
 F. Now, since the php installer did not automatically configure apache to use php, we will do it manually.
Edit the Apache httpd.conf Configuration File. Go to: Start -> Programs -> Apache HTTP Server -> Configure Apache Server -> Edit the Apache httpd.conf Configuration File
Now add the following lines to the bottom of the httpd.conf file: (Be sure to change C:\PHP to the folder where you installed to, if you installed somewhere else.)
Add this if you installed php4
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php.exe"
Or add this if you installed php5
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php-cgi.exe"
Now, if you specified another directory other than C:\PHP for the installation, Specify it here. Add this as the fourth line, changing C:\PHP to the directory where you installed Php.
SetEnv PHPRC C:/php
Now, the last thing to change in the configuration file is to add the index.php as a valid default document to serve if the user requests a directory. To do this use the (CONTROL + F) Find function of Notepad to find the line that looks like the following:
DirectoryIndex index.html index.html.var
Add a space and index.php to the end of this line so it looks like this:
DirectoryIndex index.html index.html.var index.php
 E. Wait! You're not done yet. After adding the above lines to httpd.conf, Save the file (File -> Save), close it and Restart Apache for this to have any effect.
To Restart Apache, Double-click on the Apache icon in the system tray and click "Restart" or Or look in the programs menu and click Restart Apache Start -> Programs -> Apache HTTP Server -> Control Apache Server -> Restart.

Let's check and see if Apache and Php are getting along

Go to C:\Program Files\Apache Group\Apache2\htdocs\ and create a new file called phpinfo.php that contains the following code:

<?php
    echo phpinfo();
?>

Now you go to localhost/phpinfo.php (or localhost:8080/phpinfo.php) in your web browser. You should see a whole lot of information about the Php installation. If you don't see see anything, something must have gone wrong in the setup.

If you want you can add a link to the php info from you new main page above. The new code would look like this:

<html>
    <head>
        <title>Hello World!</title>
    </head>
    <body>
        <h1>Hello World!</h1>
        <a href="apache">Apache "It Worked" Page<a><br />
        <a href="phpinfo.php">Information about Php<a><br />
    </body>
</html>

At this point, if you only want to work at creating HTML code with Php or creating Php web applications, you're set to go. I suggest you continue and install MySQL. MySQL is a great database that will permit you to make even more powerful web apps.

Step 4 - Install the MySQL database

4. Install MySQL
 A. Double-click the MySQL installation file that you downloaded. (Something like mysql-4.1.7-essential-win.msi.)
 B. When they ask, choose the typical setup. (Unless you want the C libraries for interacting with MySQL from C/C++ & some extra command line tools.)
 C. If you want to sign up with the MySQL website, log in or create a new account. Otherwise choose skip sign-up.
 D. Make sure the Configure the MySQL server now option is checked and click "finish".
 E. Go ahead and choose Standard Configuration for ease of installation. (Detailed Config is great if you need to optimize for a production server).
 F. In the next window, check Install as a Windows Service, leave the Service Name as MySQL and check Launch the MySQL Server automatically
 E. Check Modify Security Settings and create a root password and check the box that says Root may only connect from localhost. Don't create an anonymous account.
 F. Click "Next", "Execute" and "Finish" (or something like that) and you're done!


Now let's confirm that the MySQL Server is up and running

  1. Open a DOS Box  Start -> Run -> Type "cmd" -> Press "Enter" (On WinMe or 98, type "command" instead of "cmd")
  2. In the DOS box type "net start"
You will see a list of all the services running on your machine. Confirm that MySQL is among that list.

Step 5 - Install PhpMyAdmin

5. Install PhpMyAdmin
 A. Unzip the file you downloaded (Something like phpMyAdmin-2.6.0-pl3.tar.bz2.) Lots of people use Winzip (which is not free), I really like the free, open-source 7-zip file compression utility.
 B. After unzipping, look for the file called config.inc.php, open it and look for the following lines:
$cfg['PmaAbsoluteUri'] = '';
$cfg['blowfish_secret'] = '';
$cfg['Servers'][$i]['auth_type']     = 'config';    // Authentication method (config, http or cookie based)?
Change the three lines above to:
$cfg['PmaAbsoluteUri'] = 'http://localhost/pma';    // This can be something other than pma if you want.
$cfg['blowfish_secret'] = 'mycatisblue';            // Any phrase you want will do (it's for encrypting your password)
$cfg['Servers'][$i]['auth_type']     = 'cookie';    // Authentication method (config, http or cookie based)?
Now save and close the file
 C. Now create a new folder in your Apache Document root called pma (The document root would be C:\Program Files\Apache Group\Apache2\htdocs\ unless you have changed it) In the previous step, if you used another folder name instead of pma, create that folder instead.
 D. Move all the files, scripts and folders that you unzipped (including the newly-modified config.inc.php) to the pma folder that you just created.


Ok, let's see if we can use PhpMyAdmin


Contine browsing the collection of Windows tips, hints and shortcuts,
or return to my web collection of information.


This entire website and all contents are copyright 2004 www.reliply.org