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

  1. Version history
  2. Caveats
  3. Downloaded Components
  4. Directory Structure
  5. Restoring an Installation after a Reformat
  6. Install Apache
  7. Install PHP
  8. Further Editing httpd.conf
  9. Install Perl
  10. Install MySQL
  11. Configure MySQL
  12. Install MyPHPAdmin
  13. Install Wordpress
  14. Extras
  15. Uninstall
  16. Credits & Props
  17. Legal

Version History

Caveats

  1. Be sure to conduct the directions AS SPECIFIED.
  2. Uninstall IIS if it is already running on your system.
  3. Make sure your system is *clean* meaning no previous Apache installations have taken place.
  4. 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.

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.


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]

Installing MySQL as a Service

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

  1. Locate the Apache Installer file and run it. Read the Licence Agreement :) and keep pressing Next.
  2. Server Information:
  3. Select Custom installation > Next
  4. Install under the d:\websites\_server directory > Install Watch the show :)

Testing Apache

  1. Now that Apache is running access http://localhost/ in your browser. I would heavily recommend Mozilla Firefox.
  2. You should see this screen and the message below:
  3. "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

  1. Edit the httpd.conf file by using the shortcut Start > Programs > Apache HTTP Server > Configure Apache HTTP Server > Edit the httpd Configuration File
  2. Find:
    DocumentRoot
    Replace with:
    DocumentRoot "d:\websites"
    where d:\websites is where your website files are.
  3. 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.
  4. 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">
  5. 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

  1. Unzip the files to d:\websites\_server\php

Configure PHP

  1. Copy php4ts.dll from PHP's root directory to d:/websites/_server/php/sapi/
  2. Open the httpd.conf file: Start > Programs > Apache HTTP Server > Configure Apache HTTP Server > Edit the httpd Configuration File
  3. 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
  4. Restart Apache: Start > Programs > Apache > Control > Restart

Test PHP

  1. Create a file phpinfo.php in d:\websites
  2. Type the following code in the file:
    <?php phpinfo() ?>
  3. Save the file and open it in your browser. You should be able to view the following:

Further editing httpd.conf

  1. Edit the httpd.conf file by using the shortcut Start > Programs > Apache HTTP Server > Configure Apache HTTP Server > Edit the httpd Configuration File
  2. 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.
  3. Find:
    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml
    Replace with:
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
    to enable SSI inclusion in .shtml files
  4. Thats it for now. Save the file! You can always go back and edit it for more custom functionality like custom error pages.
  5. 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.

  1. Install Perl using the installer you just downloaded. You do remember where you put it don't you?
  2. Install it into the d:\websites\_server\perl directory.
  3. Your path to perl will now be: #!d:\websites\_server\perl\bin\perl.exe Note that the path to perl points to perl.exe!
  4. Also, remember to create the folder d:\websites\cgi-bin where you will keep your scripts.

Configuring httpd.conf to handle CGI Scripts

  1. Find:
    Options Indexes FollowSymLinks
    Replace with:
    Options Indexes FollowSymLinks Includes ExecCGI
    to enable Apache to run cgi files. Also do the following:
  2. 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!
  3. Find:
    <Directory "d:/websites/_server/Apache2/cgi-bin">
    Replace with:
    <Directory "d:/websites/cgi-bin">
  4. Also, on the line that starts with
    Options None
    replace it with
    Options +ExecCGI
  5. Find
    #AddHandler cgi-script .cgi
    Replace with:
    AddHandler cgi-script cgi pl
  6. Add
    ScriptInterpreterSource Registry
    right at the bottom to enable registry association with .pl and .cgi files

Notes:

  1. With the defaults set above, cgi scripts can only be run from off the /cgi-bin directory.
  2. 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
  3. Consult the individual script permissions (CHMOD) for details on what sort of permissions to apply.
  4. Running CGI scripts from outside the cgi-bin directory requires you to do one of the following:

(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

  1. 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.";
  2. Go to the page at http://localhost/cgi-bin/test.pl to see if it works!

Installing MySQL

  1. This one is a piece of cake! Unzip the contents of the folder and run setup.exe
  2. Install it to your d:\websites\_server\mysql folder (Next > Next > Next > Install > Finish)

Testing MySQL

  1. Run winmysqladmin at d:\websites\_server\mysql\bin\winmysqladmin.exe and input your username and password. Then close.
  2. 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;
    ?>
  3. your_username = username
    your_password = password
    your_database = test
  4. 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.
  5. 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

  1. Unzip the contents of the package to d:\websites\phpmyadmin
  2. 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.
  3. Here, "host" means the MySQL server. Also insert the correct value for $cfg['PmaAbsoluteUri'].
  4. In other words:
    Find:
    $cfg['PmaAbsoluteUri'] = '';
    Replace with:
    $cfg['PmaAbsoluteUri'] = 'http://localhost/phpmyadmin/';
  5. For the relevant entries under 'controluser' and 'user' input -> username
  6. Use the same password that you did last time in 'controlpass' and 'password' -> password
  7. 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!
  8. You can add more users per database on the phpmyadmin menu interface.

Install Wordpress

  1. Unzip the contents into d:\websites\wordpress
  2. You might want to create a seperate database for wordpress first using phpmyadmin:
    1. Creating a database is a simple task of entering the name of the database you want created then clicking on "create".
    2. In this case, create the database "wordpress".
    3. By default, the username and password assigned to this database will be the username/password you submitted when you first ran winmysqladmin.
    4. 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.
  3. 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.
  4. Fire up install.php at localhost/wordpress/wp-admin/install.php in your browser and you are good to go!
  5. A successful install nets you:

Extras

DBD::mysql

  1. 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
  2. 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
  3. 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

  1. Similarly, you may want to install the Perl module above.
  2. 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
  3. This installs ImageMagick 5.5.7 by Kyle Shorter <magick@wizards.dupont.com>, compiled by Beau E. Cox <beau@beaucox.com> http://beaucox.com
  4. Further reference can be made at http://ppm.beaucox.com/Magick.html
  5. A guide to a manual installation can be found at http://www.dylanbeattie.net/magick/howto.html

Uninstall Instructions

  1. _BACKUP_ all your files on the /localhost folder. This includes the databases via phpmyadmin
  2. STOP mysql from running via winmysqladmin.exe
  3. STOP Apache from running via the Apache Server Monitor or the Start Menu
  4. Uninstall Apache, MySql and Perl via their uninstallers using "Add or Remove Programs" in the Control Panel.
  5. Delete the directories:
    C:\apache
    C:\PHP
    C:\Perl
    C:\mysql
  6. 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

  1. The creators for all the fantastic programs above!
  2. The guy from http://internetmaster.com/ for a great tutorial as reference.

Legal