Installing an Apache server on Windows

This tutorial will guide you, step by step, through the installation of Apache, along with PHP and MySQL (and phpMyAdmin), under Windows.
For this tutorial, we used apache_2.0.54-win32-x86-no_ssl.msi, php-5.0.4-Win32.zip, mysql-essential-4.1.12a-win32.msi and phpMyAdmin-2.6.3-pl1.zip, on a machine running Windows XP Home SP2 (but this tut works fine with XP Pro, but there is a little problem with Win 2000 - but that won't prevent you from running the full server though).

Warning : in this tutorial, we are configuring a server that will send error and warning messages that will help you for development, but may reveal security breaches to potential hackers. So, DO NOT use this server for hosting purpose, use it only for development (unless you edit the configuration files as appropiate).

Summary

All links

  • Apache HTTP Server (download page). Choose Win32 Binary (MSI Installer).
  • PHP (download page). Choose the zip package in the Windows Binaries section.
  • MySQL (download page). Choose the latest stable version, then choose Windows Essentials (x86).
  • phpMyAdmin (download page). Choose whichever file you want (the zip may be simpler to use though).

Apache

Running the installer

On the Server Information screen :

  • in Network Domain, enter your domain name if you own one, or anything you want (it's not important but this field is mandatory). We entered patheticcockroach.com.
  • in Server Name, enter your domain name with www. before. We entered www.patheticcockroach.com (not important either, but mandatory too).
  • in Administrator's Email Address, enter your e-mail if you want to, or any nospam@IwontgiveMyAddress.com :). We entered our real e-mail (not important either, but mandatory too).
  • check Install Apache HTTP Server 2.0 programs and shortcuts for only for the Current User, on Port 8080, when started Manually.

On the Setup Type screen : choose Custom.

On the Custom Setup screen : choose what you want to install. You can leave all the default values if you want. We left the default component settings (full installation), and changed the install path to C:\Program Files\SERVER\Apache Group\.

Configuring Apache

First, let's remove a useless feature : open the Start menu, go to Programs → Startup and delete Monitor Apache Servers. In the taskbar, you can locate and exit the Apache Monitor if you want. That's what we did.

Then, go to your Apache folder (for us it's C:\Program Files\SERVER\Apache Group\Apache2), and open httpd.conf (located in the conf folder). Here are a few important parameters (there is more help about them in the httpd.conf file itself, so we just list them) :

  • search for Listen 8080 : this is the port listened by Apache.
  • search for ServerAdmin : it is followed by the e-mail you entered during setup.
  • search for ServerName : it is followed by the domain name you entered during setup, and the port : www.domainname.com:port.
  • search for DocumentRoot : change the value to the folder from wich you want to serve your website. We changed it to D:/SERVER/HTTP (note the slash (/) instead of the backslash (\)).
  • search for
    #
    # This should be changed to whatever you set DocumentRoot to.
    #

    and change the value to the same as DocumentRoot's. We changed it to <Directory "D:/SERVER/HTTP">.
    A bit later in this section, replace AllowOverride None with AllowOverride All (this is not mandatory but will be necessary to use .htaccess files, which we'll need later with phpMyAdmin).

  • search for DirectoryIndex : this is the name of the index file that Apache will serve if asked for a directory. We set it to DirectoryIndex index.php index.htm index.html index.html.var
  • search for AccessFileName : this is the name of the file that will let us protect folders with a password. We set it to AccessFileName win.htaccess (we'll need it with phpMyAdmin - we have to change it because Windows refuses filenames starting with a dot).

Result

Congrats, you're done with Apache ! Wanna see the result ? Okay, but not too long, we still have some work to do.
In the Start menu, go to Programs → Apache HTTP Server 2.x → Control Apache Server → Start Apache in Console. Huh ? It's rather raw, isn't it ? Don't worry, that's not your site :).
Put some html pages in the folder you entered in the DocumentRoot field (see above).
Open your favorite browser (I hope it's not MSIE, btw ;)), and in the address bar, type http://127.0.0.1:8080 Here are your pages, and you could share it with anyone on the web, if they had your IP and if you let Apache go through your firewall.

PHP

Close Apache (not mandatory but let's act cleanly).

Unzipping the stuff

Extract your php file (for us it was php-5.0.4-Win32.zip) in some folder. We extracted it in C:\Program Files\SERVER\PHP.

Configuring PHP

Go to your PHP folder (for us it's C:\Program Files\SERVER\PHP). Copy php.ini-dist as php.ini, and open this php.ini.

  • search for extension_dir and set it to the appropriate value : for us, it's C:/Program Files/SERVER/PHP/ext/
  • search for upload_max_filesize : this is the maximum size of uploaded files (uploaded in a form treated with a PHP script). We didn't change it, but we thought it might interest you.
  • search for
    ;;;;;;;;;;;;;;;;;;;;;;
    ; Dynamic Extensions ;
    ;;;;;;;;;;;;;;;;;;;;;;

    this is a list of extensions, that you need to uncomment (remove the ;) in order to load them. We uncommented php_gd2.dll (to create pictures, cf our turing number PHP script), php_mbstring.dll (I don't remember why) and php_mysql.dll (needed for MySQL queries).

  • search for [mail function] and set SMTP to the smtp server of your Internet Service Provider (ISP) (eg, for us it was SMTP = smtp.noos.fr). Uncomment sendmail_from = me@example.com (and replace me@example.com with the address that you want to appear in the From field when your server sends an e-mail)

Configuring Apache to work with PHP

Go to your Apache folder and open httpd.conf (located in the conf folder) :

  • add
    LoadModule php5_module "C:/Program Files/SERVER/PHP/php5apache2.dll"
    PHPIniDir "C:/Program Files/SERVER/PHP"

    at the beginning of the file (of course, replace the path by yours).

  • search for
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    and add AddType application/x-httpd-php .php .phtml after it (needed for PHP).

  • search for
    #
    # Action lets you define media types that will execute a script whenever
    # a matching file is called. This eliminates the need for repeated URL
    # pathnames for oft-used CGI file processors.
    # Format: Action media/type /cgi-script/location
    # Format: Action handler-name /cgi-script/location
    #

    and add Action application/x-httpd-php "C:/Program Files/SERVER/PHP/php.exe" after it (needed for PHP, replace the path by yours).

In your PHP directory (for us, C:\Program Files\SERVER\PHP), copy the file libmysql.dll and paste it into the bin directory of your Apache folder (ie, for us C:\Program Files\SERVER\Apache Group\Apache2\bin).

Hello World

Well, time for another break. With notepad, create a file named somename.php, containing :

<?php phpinfo(); ?>

Save it into your server directory (for us it's C:/SERVER/HTTP). Now launch Apache. With your browser go to http://127.0.0.1:8080/somename.php. You should see a page listing a lot of things about your server :)

MySQL

Close Apache (not mandatory but...)

Running the installer

On the Setup Type screen : choose Custom.

On the Custom Setup screen : choose what you want to install. You can leave all the default values if you want. We left the default component settings (full installation), and changed the install path to C:\Program Files\SERVER\MySQL\MySQL Server 4.1\.

On the MySQL.com Sign-Up screen : do whatever you want... we chose Skip Sign-Up.

On the Wizard Completed screen : leave the Configure the MySQL server now checkbox ckecked. This opens the MySQL Server Instance Configuration Wizard.

Configuring MySQL

If it isn't already opened, launch the MySQL Server Instance Configuration Wizard (In the Start menu, go to Programs → MySQL → MySQL Server 4.1 → MySQL Server Instance Config Wizard).

On the Please select a configuration type screen : choose Standard Configuration.

On the Please set the Windows options screen : uncheck Install As Windows Service.

Creating the links to launch and close MySQL

Go to the bin folder in your MySQL folder (for us it's C:\Program Files\SERVER\MySQL\MySQL Server 4.1\bin).
Create a file called MySQL_launch.bat (you can choose another name, but the extension must be .bat), right-click on it and choose Edit. In the notepad windows that appear, type

mysqld-nt.exe

and save and close the file.
Create a file called MySQL_stop.bat right-click on it and choose Edit. In the notepad windows that appear :

  • If you are on windows XP Pro, type
    taskkill /F /IM mysqld-nt.exe

    and save and close the file.

  • If you are on Windows XP Home, you need either to download taskkill.exe and put it in your system32 folder (probably located in C:\windows\system32\) and do the same .bat file as above, or you don't need to download taskill.exe if you put this in the .bat file :
    tskill mysqld-nt

Now, to launch the MySQL Server, all you have to do is run MySQL_launch.bat. To close the MySQL Server, run MySQL_stop.bat. You can create a link to these batch files and put these links in the start menu, but this tut isn't the place to explain this).
If you get stuck because of these files, tell us on the forum : we can send you our batch files.

Result

Sorry, nothing new to see here. Move on to the next section, there'll be much more things to see.

phpMyAdmin

Unzipping the stuff

Extract your phpMyAdmin file (for us it was phpMyAdmin-2.6.3-pl1.zip) in a folder within your server's folder. We extracted it in D:\SERVER\HTTP\Restricted\phpMyAdmin. Move all the files and folders into D:\SERVER\HTTP\Restricted\phpMyAdmin (instead of leaving them in the original D:\SERVER\HTTP\Restricted\phpMyAdmin\phpMyAdmin-2.6.3-pl1).

Configuring phpMyAdmin

Open config.inc.php (in your phpMyAdmin directory) with Wordpad (it contains caracters not compatible with notepad) :

  • search for $cfg['PmaAbsoluteUri'] and indicate here your phpMyAdmin path, using your domain name or IP. Eg :
    - you can use 127.0.0.1 (this is how your PC refers to himself, but if you use it, you won't be able to access phpMyAdmin from another computer)
    - you can use 70.225.165.170 (your IP, then you'll be able to access phpMyAdmin from anywhere on the internet, provided that your firewall or your network is properly configured and that you have a constant IP)
    - you can use your local IP if you have a local network (then you will be able to access phpMyAdmin only from a computer on this network)
    - you can use your domain name, if you have one and know how to configure it to work with your Apache installation (I don't know how to do).
    We set this to http://192.168.1.104:8080/Restricted/phpMyAdmin/, which is our IP on our local network.

Launch Apache, and with your browser, go to http://127.0.0.1:8080/Restricted/phpMyAdmin/ (or to wherever you installed phpMyAdmin).
Click on Privileges, then edit the root account to add it a password. Then, you'll be kicked from phpMyAdmin, since you set a new password :).
Open config.inc.php again, search for $cfg['Servers'][$i]['password'] and enter your password there.
In your browser, hit F5 to reload phpMyAdmin. Click on Privileges, then Edit the Any account and remove all privilieges.
Here you are, phpMyAdmin is configured.

Just a last security feature

You probably noticed that you don't need any password to use phpMyAdmin, which means that virtually anyone can access your database through phpMyAdmin. Let's add some protection.

  • In your phpMyAdmin folder (or higher if you want to protect other folders : all folder below this folder will be protected), create a folder named, for instance, pass.
  • In this folder, create a file named win.htaccess with the following content :
    deny from all
  • Always in this folder, create a file named, for instance pass.txt with the following content (for instance too) :
    username:password
    anotherusername:anotherpassword

    This file contains informations about users (username) linked to their password.

  • In the folder above pass (pass's parent folder), create a file named win.htaccess with the following content :
    AuthType Basic
    AuthName "Please log in"
    AuthUserFile D:/SERVER/HTTP/Restricted/pass/pass.txt
    require valid-user

    (replace D:/SERVER/HTTP/Restricted/pass/pass.txt with the full path to the password file)

To sum up : for instance, we have 3 files :

  • D:\SERVER\HTTP\Restricted\win.htaccess
    AuthType Basic
    AuthName "Please log in"
    AuthUserFile D:/SERVER/HTTP/Restricted/pass/pass.txt
    require valid-user
  • D:\SERVER\HTTP\Restricted\pass\win.htaccess
    deny from all
  • D:\SERVER\HTTP\Restricted\pass\pass.txt
    patheticcockroach:mypassword

Now go back to your browser, to http://127.0.0.1:8080/Restricted/phpMyAdmin/ : it asks for a username and a passord, for us it's patheticcockroach and mypassword.

Finally

Congrats, you now have a brand new Apache HTTP Server with PHP and MySQL support, running phpMyAdmin as a database administration tool.
What's more they won't launch by themselves, since we remove their startup entries as they added them. And your phpMyAdmin folder (and perhaps other folders, or even your whole server) is secured by a password.
Do not forget to keep links to Apache.exe (in the bin folder of Apache), MySQL_launch.bat and MySQL_stop.bat (in the bin folder of MySQL).

©2005-2006 PatheticCockroach.com

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.