Categories
Tools

Setting up Apache, PHP, MySQL, PHPMyAdmin Server on Windows XP

Click to rate this tutorial!
[Total: 1 Average: 5]

The goal today is to set up a web server on Windows where you can upload your PHP code, serve it with Apache, tie it in to a MySQL database, and administer MySQL with PHPMyAdmin.

Let’s start by setting up Apache.

A Bunch of Downloads

Here’s what you need to download (along with the version numbers I’m using):
Apache Web Server (v 2.2.14) – get the Win32 binary (msi installer) from the official site . You can decide between the one that comes with SSL and the one that comes without – either will work for this tutorial.
PHP (v 5.3.1)- we’ll download the Windows binary here. This is the PHP interpreter; when Apache needs to serve a PHP script, it will hand it off to the PHP interpreter to deal with the PHP code before it sends HTML to the client. Get the zip file labeled “VC6 x86 Thread Safe”.
MySQL (5.1.42) – Go here and get the “Windows (x86, 32-bit), MSI Installer” –
PHPMyAdmin (3.2.4) – get the zip file here
phpmyadmin.sql – tables for some of PHPMyAdmin’s advanced features (more on this later)

Setting up Apache

Run the executable you downloaded above. Other than setting your network and server name (I used ‘localhost’) and your administrator email address, you can just click “Next” through the whole installation. Choose “Typical” when asked for a setup type.

When setup is done, Apache is installed as a service on your machine. (If you right-click My Computer and choose Manage, then click > Services and Applications > Services, you can see all the services running on your machine.)

You can verify that this was successful by opening a browser and going to http://localhost.

Installing PHP

Extract the PHP zip file to your c:\ drive and rename the folder from “c:\php-5.3.1-Win32-VC6-x86” (or whatever) to simply “c:\php.”

Now, to keep things clean so that you don’t have to drop anything PHP-related into the Windows folder, you’ll need to add c:\php to the Windows system path. Essentially, that means that when Apache says “I need to run php.exe,” Windows will know that c:\php is one of the places where it can look for that.

To add something to the Windows path, right-click My Computer and choose Properties, then go to the Advanced tab.

Click on the “Environment Variables” button near the bottom, then scroll down in the bottom panel until you see “Path.”

Click to highlight it, then click “Edit.”

Go to the end of that line and add (without the quotes) “C:\php;”, then click OK. Restart your machine so that this change will take effect.

Configuring PHP

Once you’ve rebooted, browse to c:\php. Copy either php.ini-production or php.ini-development, depending on the purpose of this server setup[1], to simply c:\php.ini. Then copy that file to c:\php.ini-original before you start making any changes, so you can always go back and see what you did by diffing your current config with the original one. (WinMerge is a good Windows-based program to do that.)

Now that you’ve got a backup, open php.ini in a text editor and make the following changes:

Optionally, set short_open_tag = On. This is not considered best practice, but it allows you to start PHP code blocks with just < ? instead of to point to the same folder. Like this:
Set DirectoryIndex index.php index.html. This controls which file will be displayed if someone requests a folder. For example, if they browse to www.yoursite.com/foo, with this setting, the server will first look in the foo folder for ‘index.php.’ If it finds it, it will display it; otherwise, it will proceed to look for ‘index.html.’ You can add more alternatives to the end of the line or change the order as you like.
Set EnableSendfile Off to prevent some page requests from hanging. (This is a Windows-specific configuration that took me a few days to to learn about)
Finally, add the following lines to the end of the file

#Enable PHP processing
LoadModule php5_module "c:/php/php5apache2_2.dll"
#.php files should be processed as PHP
AddType application/x-httpd-php .php
#Where to find php.ini
PHPiniDir "C:\php"

Whew! That’s it for Apache and PHP. Restart Apache, and create a simple page called ‘index.html’ in your designated web root folder (like “C:\www”, or whatever you chose). Now visit http://localhost,

Now create a simple php script called ‘index.php’. With the DirectoryIndex setting I used above, it will now take precedence over ‘index.html’ and be displayed when you reload.

Installing MySQL

This is the easiest part yet. Run the installer and use all the default options.

Note: The “Typical” installation option puts the database data in “C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1”. If you ever need to completely remove MySQL and reinstall, if you don’t delete this folder along with the program’s folder, you’ll reinstall and open your database to find that it already has data in it.

Setting Up PHPMyAdmin

This is also pretty simple. For the most basic case, all you need to do is this:

Unzip the phpmyadmin file into your web root folder
Rename its folder to simply ‘phpmyadmin’ (so that you can browse to ‘localhost/phpmyadmin’ to see it)
Create a config file in that folder, called config.inc.php

A very simple config file (taken from the docs)a looks like this:

<?php
$cfg['blowfish_secret'] = 'gtqw0282bg7130jhga7d'; // change to random string of your choice
$i=0;
$i++;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
?>

That’s it! PHPMyAdmin should work.

Making PHPMyAdmin better

If you’ve got previous experience with XAMPP, you’ll be accustomed to some nice little configuration features for PHPMyAdmin. For example, you can bookmark queries, and have your foreign keys display as hyperlinks to the associated record.

Fortunately, we can all get those features working, too. First, add the following lines to config.inc.php:

$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';
$cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';

/*Personal Tweaks */

$cfg['MaxRows'] = 500; /* Show 500 rows of a table by default */

Done!
Thanks To SleeplessGeek

Click to rate this tutorial!
[Total: 1 Average: 5]

Leave a Reply

Your email address will not be published.