Tutorial: Running a personal website on Apache HTTP server on WinXP
A sanitized version of my own "Running an Apache HTTP Server with PHP, Perl and MySQL (admin: myphpadmin) on WinXP" guide based on internetmaster's original tutorial.
This tutorial is not meant to be a guide to host a fully fledged website but to setup a test platform for a blog on your personal computer. At the end of the tutorial, you should be able to successfully test Wordpress, the best LAMP blogware out there!
Contents
- Version history
- Caveats
- Downloaded Components
- Directory Structure
- Restoring an Installation after a Reformat
- Install Apache
- Install PHP
- Further Editing httpd.conf
- Install Perl
- Install MySQL
- Configure MySQL
- Install MyPHPAdmin
- Install Wordpress
- Extras
- Uninstall
- Credits & Props
- Legal
Version History
- 07.06.2004
- Added instructions to restore an installation after a reformat.
- Revised CSS formatting for easier reading.
- 16.05.2004
- Revamped original txt file to be CSS + XHTML compliant.
- Added revisions for current latest installation packages of Apache HTTP server 2.0.49, MySQL 4.0.18, ActivePerl 5.8.3.809.
- Added screenshots.
- 05.02.2004
- Revised several of the instructions.
- Added additional sections such as Image::Magick installation ect.
- Proposals to convert guide to xhtml strict soon.
- 05.06.2003
- I have tested the tutorial myself running on a WinXP Pro laptop. I realise the importance of FOLLOWING INSTRUCTIONS.
- 04.06.2003
- Started writing this guide using the guide from http://internetmaster.com/installtutorial/ as basic guideline. This tutorial is based on the guide's structure.
- Added Perl installation instructions and a mini tutorial for the installation of myphpadmin.
Caveats
- Be sure to conduct the directions AS SPECIFIED.
- Uninstall IIS if it is already running on your system.
- Make sure your system is *clean* meaning no previous Apache installations have taken place.
- Windows XP Apache Users Read This First
If you will install Apache on Windows XP, you must install the Windows XP Service Pack 1. You may obtain that service pack from;
http://www.microsoft.com/windowsxp/pro/downloads/servicepacks/sp1/default.asp
Additional Warning: we recommend disabling the "Quality of Service" (or QoS) network driver from Microsoft if you are using Apache, since Apache does not support the QoS extensions to the WinSock API.The original distribution of Windows XP may expose you to a known bug, reported by users of Apache 1.3 and 2.0 on Windows XP. The effects of this bug are particularly observed in conjunction with https SSL/TLS connections, but also occurs in other contexts.
It appears the combination of duplicating file handles between and parent and child process, in conjunction with blocking sends to the http client may result in corrupted output. You may not see corruption in MSIE, which tends to throw any error in the 'Cannot find server or DNS Error' category, rather than explaining the real error or display the corruption. You will only see this corruption over slower links, testing the local loopback (localhost) generally reveals no corruption. This is a potential security risk, since the random, corrupt data served may come from anywhere, such as the cache of buffered file pages containing sensitive data.
If you receive such errors on Windows XP using SSI scripting or PHP scripts, but not static pages, you are probably a victim of this bug. Microsoft initially released a hotfix for the issue, that has been superceeded by the Service Pack 1 release. MSKB article Q317949 addresses this bug.
Alert from http://www.apache.org/dist/httpd/binaries/win32/#xpbug [17.05.2004]
Downloaded Components
The components I downloaded and their versions are in square brackets "[xxx]". It would be best to download the whole list first and put them into one folder for easy reference later.
- Apache HTTP Server Project - Win32 binary [2.0.46]
- PHP installer [4.3.6]
- MySQL Windows Download for Windows 95/98/NT/2000/XP/2003 [4.0.18]
- ActiveStatePerl - Win32 binary [5.6.1.630]
- MyPHPAdmin zip [2.5.6]
- Wordpress [1.2 RC1]
- http://www.wordpress.org
- You are advised to check on the WP website often as it offers bleeding edge code - the nightly updates are very frequent!
Directory Structure
I use the following directory structure for the purposes of this tutorial. This ensures that all the files necessary to run the website are located on a different partition than my WinXP system files (c:\) so that they may be saved in light of a reformat. You will just need to restart Apache and MySQL as services after a reformat instead of reconfiguring everything and redoing this tutorial over again. It is perfectly alright for you to install Apache & friends on the C:\ drive if you choose to. Just remember to substitute the D:\ drive letter for C:\ or wherever you decided to install the packages.
- D:\
- websites
- _phpmyadmin
- _server
- wordpress
Restoring an Installation after a reformat
The following FAQs are for installing Apache2 and MySQL as services after a reformat of your WinXP system. You can skip the rest of the tutorial and follow the instructions that follow the FAQ links if this section does not concern you.
Installation Apache as a service
You can install Apache as a WinXP service as follows from the command prompt at the Apache bin subdirectory. If you had religiously followed the instructions in this tutorial, the Apache bin subdirectory would be d:\websites\_server\Apache2\bin
Open the command prompt by accessing Start > Run > cmd > OK > d: > cd websites\_server\apache2\bin Then input:
apache -k install
If you need to specify the name of the service you want to install, use the following command where MyServiceName is the name of the service name you want to give to Apache. You have to do this if you have several different service installations of Apache on your computer.
apache -k install -n "MyServiceName"
If you need to have specifically named configuration files for different services, you must use this:
apache -k install -n "MyServiceName" -f "c:\files\my.conf"
If you use the first command without any special parameters except -k install , the service will be called Apache2 and the configuration will be assumed to be conf\httpd.conf .
Removing an Apache service is easy. Just use:
apache -k uninstall
The specific Apache service to be uninstalled can be specified by using:
apache -k uninstall -n "MyServiceName"
Taken from FAQ: Running Apache HTTP server 2.0 as a service [Apache.org]
To install a MySQL server as a service under Windows XP, invoke it with the --install option from the command line. Navigate to your MySQL installation bin via the command prompt. Again, if you religiously followed the tutorial, it would be: d:\websites\_server\mysql\bin
For example, to install mysqld-nt this way, use the following commands:
mysqld-nt --install
followed by
NET START MySql
The first command installs the server and sets it to run at the next system restart and each restart thereafter. However, it does not cause the service to start immediately. The NET START command accomplishes that without a machine restart. The argument to NET START is the service name, which is "MySql" no matter which of the MySQL servers you install. (The service name is not case sensitive, so you can specify it in any lettercase.)
If you decide you no longer want to run MySQL as a service, remove it by invoking the server with the --remove option. However, before you do this, you should stop the server if it's currently running. For example, if you installed mysqld-nt , stop it and remove it like this also at MySQL bin command prompt:
NET STOP MySql
to stop the MySql service, followed by
mysqld-nt --remove
Extracted from FAQ: Installing MySQL as a service [Paul DuBois paul@kitebird.com]
Install Apache
- Locate the Apache Installer file and run it. Read the Licence Agreement :) and keep pressing Next.
- Server Information:
- Network Domain = Domain Name, else "User" where "User" is your computer name.
- To find out your computer name, right click My Computer > Properties > Computer Name > "Full Computer Name" (without the dot!)
- Server Name = localhost
- Admin Email = youremail@someplace.com
- Install on Port 80 as a service
- Select Custom installation > Next
- Install under the d:\websites\_server directory > Install Watch the show :)
- If everything was setup properly, Apache would run automatically and now be running in the background. Yippie!
- You may start/stop Apache by accessing the panel on the taskbar. Right Click > Open Apache Monitor > Start/Stop/Restart
Testing Apache
- Now that Apache is running access http://localhost/ in your browser. I would heavily recommend Mozilla Firefox.
- You should see this screen and the message below:
"If you can see this, it means that the installation of the Apache web server software on this system was successful. You may now add content to this directory and replace this page."
Tweaking Apache
- Edit the httpd.conf file by using the shortcut Start > Programs > Apache HTTP Server > Configure Apache HTTP Server > Edit the httpd Configuration File
- Find:
DocumentRoot
Replace with:
DocumentRoot "d:\websites"
where d:\websites is where your website files are.
- Also a little bit lower down, find:
<Directory />
[The option says "# This should be changed to whatever you set DocumentRoot to."]
Replace with:
<Directory "d:\websites">
where d:\websites is where your website files are.
- Look further down for the following and ensure the Directory directive reads as below:
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "D:/Websites">
- Find:
AllowOverride None
[Under the htaccess heading]
Replace with:
AllowOverride All
This will allow .htaccess files to override default settings in the directories.
Install PHP
- Unzip the files to d:\websites\_server\php
Configure PHP
- Copy php4ts.dll from PHP's root directory to d:/websites/_server/php/sapi/
- Open the httpd.conf file: Start > Programs > Apache HTTP Server > Configure Apache HTTP Server > Edit the httpd Configuration File
- Add the following lines to the bottom of the file:
LoadModule php4_module d:/websites/_server/php/sapi/php4apache2.dll
AddType application/x-httpd-php .php
- Restart Apache: Start > Programs > Apache > Control > Restart
Test PHP
- Create a file phpinfo.php in d:\websites
- Type the following code in the file:
<?php phpinfo() ?>
- Save the file and open it in your browser. You should be able to view the following:
Further editing httpd.conf
- Edit the httpd.conf file by using the shortcut Start > Programs > Apache HTTP Server > Configure Apache HTTP Server > Edit the httpd Configuration File
- Find:
DirectoryIndex index.htm
Replace with:
DirectoryIndex index.htm index.html index.php index.php3 index.phtml index.shtml index.cgi index.pl
to recognize popular web file types.
- Find:
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml
Replace with:
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
to enable SSI inclusion in .shtml files
- Thats it for now. Save the file! You can always go back and edit it for more custom functionality like custom error pages.
- To enable these changes Restart Apache: Start > Programs > Apache > Control > Restart
Install Perl
This PERL installation is OPTIONAL if you are looking to install your WordPress testblog on your WinXP box. Use it to try out MovableType or your own PERL scripts if you wish.
- Install Perl using the installer you just downloaded. You do remember where you put it don't you?
- Install it into the d:\websites\_server\perl directory.
- Your path to perl will now be:
#!d:\websites\_server\perl\bin\perl.exe Note that the path to perl points to perl.exe!
- Also, remember to create the folder d:\websites\cgi-bin where you will keep your scripts.
Configuring httpd.conf to handle CGI Scripts
- Find:
Options Indexes FollowSymLinks
Replace with:
Options Indexes FollowSymLinks Includes ExecCGI
to enable Apache to run cgi files. Also do the following:
- Find:
ScriptAlias /cgi-bin/ "d:/websites/_server/Apache2/cgi-bin/"
Replace with:
ScriptAlias /cgi-bin/ "d:/websites/cgi-bin/"
And don't forget to create the cgi-bin directory!
- Find:
<Directory "d:/websites/_server/Apache2/cgi-bin">
Replace with:
<Directory "d:/websites/cgi-bin">
- Also, on the line that starts with
Options None
replace it with
Options +ExecCGI
- Find
#AddHandler cgi-script .cgi
Replace with:
AddHandler cgi-script cgi pl
- Add
ScriptInterpreterSource Registry
right at the bottom to enable registry association with .pl and .cgi files
Notes:
- With the defaults set above, cgi scripts can only be run from off the /cgi-bin directory.
- Permissions can be set in XP by enabling complex NTFS file sharing options:
Start > Run > Explorer > Tools > Folder Options > View > Turn OFF Simple File Sharing
You can now tweak permissions by Right Clicking a folder > Properties > Security
- Consult the individual script permissions (CHMOD) for details on what sort of permissions to apply.
- Running CGI scripts from outside the cgi-bin directory requires you to do one of the following:
- Explicitly use the Options directive, inside your main server configuration file (httpd.conf), to specify that CGI execution was permitted in a particular directory.
- A .htaccess file is a way to set configuration directives on a per-directory basis. When Apache serves a resource, it looks in the directory from which it is serving a file for a file called .htaccess, and, if it finds it, it will apply directives found therein. .htaccess files can be permitted with the AllowOverride directive, which specifies what types of directives can appear in these files, or if they are not allowed at all.
- To permit the directive we will need for this purpose, the following configuration will be needed in your main server configuration, which we have already done in Step 5 of Configuring Apache.
AllowOverride All
In the .htaccess file, you'll need the following directive:
Options +ExecCGI
- which tells Apache that execution of CGI programs is permitted in this directory.
(taken from the Apache help website at http://www.apache.org - full URL below)
For further reference:
Note to self: List down CHMOD "translations" e.g. What is CHMOD 777 in WinXP? Read, Write, Execute ALL ect... Since this is a personal test server, it wouldn't hurt to set Read/Write/Execute for all users ("Everybody"). Since this is a personal webserver, permissions aren't 'important'. Pseudo-CHMODding will require the NTFS file system and simple file sharing disabled. In Start > Run > explorer > Tools > Folder Options > View > UNTICK Simple File Sharing
Test Perl
- Test your installation by putting these lines into a text file saved as d:\websites\cgi-bin\test.pl
#!d:\websites\_server\Perl\bin\perl.exe
print "Content-type: text/html\n\n";
print "Hello, World.";
- Go to the page at http://localhost/cgi-bin/test.pl to see if it works!
Installing MySQL
- This one is a piece of cake! Unzip the contents of the folder and run setup.exe
- Install it to your d:\websites\_server\mysql folder (Next > Next > Next > Install > Finish)
Testing MySQL
- Run winmysqladmin at d:\websites\_server\mysql\bin\winmysqladmin.exe and input your username and password. Then close.
- Copy the following and create the file test.php inside of the d:\websites directory
<?php
// open the connection
$conn = mysql_connect("localhost", "your_username", "your_password");
// pick the database to use
mysql_select_db("your_database",$conn);
// create the SQL statement
$sql = "CREATE TABLE testTable (id int not null primary key auto_increment,
testField varchar (75))";
// execute the SQL statement
$result = mysql_query($sql, $conn) or die(mysql_error());
// echo the result identifier
echo $result;
?>
- your_username = username
your_password = password
your_database = test

- This is a personal test server so security settings aren't priority. If you want to create a more secure environment, you might want to tweak the root settings of mysql from within phpmyadmin later.
- Running the script once will give you the number 1. Running it twice will give an error telling you a table "testtable" already exists.
Install phpmyadmin
- Unzip the contents of the package to d:\websites\phpmyadmin
- Open the file config.inc.php in your favorite editor and change the values for host, user, password and authentication mode to fit your environment.
- Here, "host" means the MySQL server. Also insert the correct value for $cfg['PmaAbsoluteUri'].
- In other words:
Find:
$cfg['PmaAbsoluteUri'] = '';
Replace with:
$cfg['PmaAbsoluteUri'] = 'http://localhost/phpmyadmin/';
- For the relevant entries under 'controluser' and 'user' input -> username
- Use the same password that you did last time in 'controlpass' and 'password' -> password
- Go to http://localhost/phpmyadmin/index.php and you're off! Now you can add your own databases, and run sql queries in an easier manner. Woot!
- You can add more users per database on the phpmyadmin menu interface.
Install Wordpress
- Unzip the contents into d:\websites\wordpress
- You might want to create a seperate database for wordpress first using phpmyadmin:
- Creating a database is a simple task of entering the name of the database you want created then clicking on "create".
- In this case, create the database "wordpress".
- By default, the username and password assigned to this database will be the username/password you submitted when you first ran winmysqladmin.
- Changing this username/password combination will be a matter of clicking on privileges > Edit under the "action" row of the corresponding username > enter new password under change password.
- Edit wp-config-sample.php and enter the corresponding data for db_name, db_user, db_password and db_host to read wordpress, username, password & localhost.

- Fire up install.php at localhost/wordpress/wp-admin/install.php in your browser and you are good to go!

- A successful install nets you:
Extras
DBD::mysql
- If you are interested in testing the MovableType software (http://www.movabletype.org) from your computer, you may need to install the DBD::mysql module
- First with ActivePerl already installed, run PPM (Start > Programs > ActivePerl > Perl Package Manager)
Then at the prompt type [press the Enter key after each line]:
ppm > install DBI
ppm > install DBD::mysql
- This will automatically download and install the modules for you. Read up more at http://search.cpan.org/src/RUDY/DBD-mysql-2.9003/INSTALL.html
Image::Magick
- Similarly, you may want to install the Perl module above.
- The most simple way to go about it is to run PPM (Start > Programs > ActivePerl > Perl Package Manager)
Then at the prompt type [press the Enter key after each line]:
ppm > rep add beau http://ppm.beaucox.com
ppm > i Image-Magick-Full
ppm > quit
- This installs ImageMagick 5.5.7 by Kyle Shorter <magick@wizards.dupont.com>, compiled by Beau E. Cox <beau@beaucox.com> http://beaucox.com
- Further reference can be made at http://ppm.beaucox.com/Magick.html
- A guide to a manual installation can be found at http://www.dylanbeattie.net/magick/howto.html
Uninstall Instructions
- _BACKUP_ all your files on the /localhost folder. This includes the databases via phpmyadmin
- STOP mysql from running via winmysqladmin.exe
- STOP Apache from running via the Apache Server Monitor or the Start Menu
- Uninstall Apache, MySql and Perl via their uninstallers using "Add or Remove Programs" in the Control Panel.
- Delete the directories:
C:\apache
C:\PHP
C:\Perl
C:\mysql
- Tadah! you're done. Oh, you should still have the files in your d:\websites folder. You might want to delete these too if you want.
Props
- The creators for all the fantastic programs above!
- The guy from http://internetmaster.com/ for a great tutorial as reference.
Legal
- This guide © 2003-04, Reza Baharin @ Zaaba
- Email: zaaba_at_fastmail_dot_fm
- Website: http://www.truedeath.com
- Please respect others' work. Give credit where it is due.
If you wish to use part of this guide, adapt it, translate it and such, please include links/props to the original authors.
- CSS + XHTML valid
