Elf Qrin's Lair


Install-a-WAMP(P)
v2.4.2 r11jul2003 fr27feb2002
by Elf Qrin



Let's say you are a Windows user willing to install a webserver on your system. What you need is a WAMP. WAMP stands for Windows, Apache, MySQL, PHP. Such system will allow you to serve documents on the Internet, allowing server side scripting with PHP and database management with MySQL. And the best part is that everything (besides Windows) is free. If you want you may include Perl too, so now we can call this system WAMPP.
This tutorial will show you how to set up such system in easy steps.

Important: this guide will not teach you how to configure each software and fine tune it, but only how to install them properly and make them work together.

I've updated this document for Apache v2.0.x, since now the Apache group is recommending it over v1.3.x for it's much more fast and secure, especially on Windows systems. Note that Apache v2.x requires updated versions of PHP, MySQL, and Perl, since the ones that were working with your old installation of Apache v1.3.x may not work with the latest release of Apache. In particular, you need at least PHP v4.1.2 to work with Apache 2.



WINDOWS

This document supposes you have Windows already installed... in case you need to update parts of your operating system (especially security related patches), you can use Windows Update at http://windowsupdate.microsoft.com/ (requires Internet Explorer 6: http://www.microsoft.com/windows/ie/default.asp )



APACHE Webserver

home page: http://httpd.apache.org/

download page: http://www.apache.org/mirrors/

Go to the Download area and choose the mirror nearest to you. There's no direct download. You'll have to browse through directories, try something like binaries/win32/ and download the one whose description is "Current Release" followed by the release number, however the file should be called something like apache_x.x.xx-win32-x86-no_src.exe where x.x.xx is the version number, win32 the operating system, x86 the CPU, and no_src means there's no source code included in that distribution.

Double click on the program to install it. During the installation you'll have to enter the Network Domain (e.g. example.net), the Server Name (e.g. www.example.net), and the Administrator's e-mail address (e.g. webmaster@example.net). Such data are not vital, but they will be shown on the user's browser when an error occour. You can also modify them later, editing the Apache configuration file.

Then you'll have to choose if you want to Run Apache as a service for all users (i.e. if it should start with Windows) or you want to start it manually double clicking on its icon.

You can choose the complete installation. The custom installation will let you disable the installation of the documentation (which is about 2MB).

The default destination directory is C:\Program Files\Apache Group\Apache and you can leave it unchanged.

Once you've finished, Apache is ready to start, you don't need to reboot Windows.

To configure Apache you have to modify the httpd.conf file in the conf directory.

The first thing to do is to define the Document Root directory. All the documents inside that directory will be accessible through Apache.

Locate the DocumentRoot statement (by default something like DocumentRoot "C:/Program Files/Apache Group/Apache/htdocs") and redefine it as DocumentRoot "C:/Internet/htdocs" or whatever you like. Then place the websites you want to make available through Apache inside this directory. Note that defining DocumentRoot is not enough. There could be further occurrences of the text string "C:/Program Files/Apache Group/Apache/htdocs" (or wherever you've installed Apache) so that you'll have to fix them manually according to your new DocumentRoot directory.

You have to define the port to which Apache will listen. The default HTTP port is 80, but Apache 2 sets it as 8080 if you choose to start the server manually, because it assumes it's a secondary webserver while the primary is launched automatically when the operating system starts. You can change this behavior by modifying the following line:

Listen 80

You can make the webserver listen to more than one port, in case you need it.
On Apache v1.3.x instead you must use the Port directive (example: Port 80 ) to choose the primary port, and Listen to choose additional ports the webserver will listen to.

You may want to enable SSI (Server Side Includes), which will make Apache process .shtml documents.

Add these lines anywhere in the configuration file for Apache v1.3.x:

#ssi

Options +Includes
AddType text/html .shtml
AddHandler server-parsed .shtml

or these lines for Apache v2.x:

#ssi

Options +Includes
AddOutputFilter INCLUDES .shtml

You can enable .htaccess files to set access rules for every directory inserting the AllowOverride All directive within the <Directory "YOUR_ROOT_DIRECTORY"> </Directory> tag pairs.

There could be some problems installing Apache on Windows 2000 Server because Apache and MicroSoft IIS webservers can "fight" for port 80. So you can either assign a different port (like 8080) to Apache using the Listen directive or disable IIS (which is way better... there's no need of IIS if you have Apache). If you use a different port of course users will have to access to your system like this http://your_computers_IP:8080/, but if you are behind a router you can redirect incoming connections to port 80 to port 8080 (which would make the "real" port 80 that could be owned by IIS unavailable).

Further editing of httpd.conf is required after installing PHP and Perl.



PHP

home page: http://www.php.net/

download page: http://www.php.net/downloads.php

Go to the downloads area and get the lastest "zip package" (not the "installer") from the Windows Binaries section. The zip package includes server API versions for Apache, AOLserver, ISAPI and NSAPI. MySQL support built-in, and many extensions.

You may also download Security fixes and Patches for the latest version if available.

Extract the zipped archive to C:\Program Files\PHP Apply fixes/patches if you downloaded them.

Create a PHP configuration file making a copy of php.ini-dist or better php.ini-recommended and renaming it as php.ini (note: php.ini-dist is more tolerant and works with most script, while php.ini-recommended is more strict and secure, but may cause some scripts to don't work properly). You don't need to modify it to make it work, but you'd better open and customize it anyway.

Open the Apache configuration file (httpd.conf) and add these lines:

#php

ScriptAlias /php/ "c:/program files/php/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php.exe"

Note that ScriptAlias must contain the actual path to PHP, so that the above line is correct if you have extracted it to C:\Program Files\PHP

Also add index.php to the DirectoryIndex directive in the Apache configuration file.

If your script doesn't use environment variables as recommended by PHP (example: $_COOKIE["debug"] , instead of simply referring at it as $debug ), you should set these directives in php.ini, although they are deprecated, especially if you have problems when setting cookies:

error_reporting = E_ALL & ~E_NOTICE
variables_order = "EGPCS"
register_globals = On

If you experience further problems with cookies using Internet Explorer, try this: go to Tools:Internet options:Privacy:Advance and check the automatic cookies override box and then allow session cookies.

Further editing of php.ini is required after installing MySQL and the SMTP server.



MySQL

home page: http://www.mysql.com/

download page: http://www.mysql.com/downloads/index.html

In the Downloads area choose the latest stable release of MySQL, and from the Windows downloads section get the Installation files (a .zip file called something like mysql-x.xx.xx-win.zip).
As a side note, MySQL is free and GPL too, but requires a license if you need support. MySQL prices are listed at http://www.mysql.com/support/arrangements/price.html

Open the .zip file and launch SETUP.EXE

The default installation directory is C:\mysql , you may want to change it to C:\Program Files\mysql

You can choose a custom installation, however it's recommended to install all components.

After you've installed MySQL, you have to create its configuration files: my.cnf and my.ini. Into MySQL directory there used to be my-example.cnf now replaced with other example configuration files that assign different resources accordingly to their names: small, medium, large, huge. medium for example is good for systems with 32-64MB RAM. You could copy one of them and rename such copy as my.cnf. This is one of your MySQL configuration files, but MySQL doesn't read them from its own directory. Instead, you'll have to copy them to the root directory (C:\), or to your Windows directory (C:\WINDOWS or C:\WINNT)

Once you have created my.cnf (copying my-medium.cnf for example) and you have copied it into the proper directory, you should edit it with these small changes:

At this point your my.cnf file should look like this one (I've removed comments to keep it shorter here):

# MySQL my.cnf config file [client] password=password port=3306 socket=/tmp/mysql.sock [mysqld] port=3306 socket=/tmp/mysql.sock skip-locking default-character-set=latin1 set-variable= key_buffer=16M set-variable= max_allowed_packet=1M set-variable= thread_stack=128K set-variable= flush_time=1800 set-variable= table_cache=64 set-variable= sort_buffer=512K set-variable= net_buffer_length=8K set-variable= myisam_sort_buffer_size=8M log-bin server-id=1 basedir=C:/Programmi/mysql/ datadir=C:/Programmi/mysql/data/ [mysqldump] quick set-variable= max_allowed_packet=16M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [isamchk] set-variable= key=16M set-variable= key_buffer=20M set-variable= sort_buffer=20M set-variable= read_buffer=2M set-variable= write_buffer=2M [myisamchk] set-variable= key_buffer=20M set-variable= sort_buffer=20M set-variable= read_buffer=2M set-variable= write_buffer=2M [mysqlhotcopy] interactive-timeout [client_fltk] history_length=20

Now create a my.ini file in the same directory where you've put my.cnf and put this text in it:

# MySQL my.ini config file [WinMySQLAdmin] Server=C:/Program Files/mysql/bin/mysqld-opt.exe user=root password=password [mysqld] basedir=C:/Program Files/mysql datadir=C:/Program Files/mysql/data #bind-address=10.10.10.55 #language=C:/Program Files/mysql/share/your language directory #slow query log#= #tmpdir#= #port=3306 #set-variable= key_buffer=16M

The most important thing here is that you have to set a root password for MySQL (password=). Also note that Server, basedir, datadir, and language must reflect the actual directory where you've installed MySQL (in this case C:/Program Files/ ).

Once you've configured MySQL, you'll also have to open the PHP configuration file (php.ini) and add these lines:

[MySQL]
mysql.default_port=3306
mysql.default_host=localhost
mysql.default_user=root

Actually the values above should reflect the ones about port, user, and root defined in MySQL my.cnf configuration file.



phpMyAdmin

home page: http://www.phpmyadmin.net/

download page: http://www.phpmyadmin.net/

Download the .zip file for PHP (not the one for PHP3), then extract the ZIP file in a subdirectory inside your Apache DocumentRoot directory.

Open the file config.inc.php in your favourite editor and change the values for host, port, and authentication mode (normally they should be set as host='localhost' , port='3306' or you can leave it blank as 3306 is the default MySQL port, and auth_type='config'), and then set user and password according to the one you've set in MySQL's my.ini configuration file (normally user should be 'root').
If you want to get a login screen where you're asked for username and password for better security, you have to set auth_type='cookie' and leave user and password blank.
You should insert the correct value for $cfgPmaAbsoluteUri with the HTTP path to your phpMyAdmin directory, although in most cases phpMyAdmin is able to autodetect it.
Have a look at Configuration section in Documentation.txt or Documentation.html for an explanation of all values.

Start index.php to administrate your MySQL databases.



Perl (ActivePerl)

home page: http://www.activeperl.com/Products/ActivePerl/

download page: http://www.activeperl.com/Products/Download/Get.plex?id=ActivePerl

You may want or need to execute CGI/Perl scripts on your system. In this case you'll have to install and configure a Perl interpreter as well, otherwise if your web site is PHP/MySQL based only, you will not need Perl.

The downloading process requires three steps:

  1. Windows user may need to upgrade their Windows Installer as specified in the first download page.
  2. You are supposed to register before to download the software, but you can leave all fields blank, if you want.
  3. In the third step, get the MSI package for Windows (provided you have updated your Windows Installer), otherwise you can get the AS package with no uninstall functionality.
When you install Perl on your Windows system, if you want to maintain a certain portability with Unix/Linux systems, you should install it in C:\usr instead of the default C:\Perl or C:\Program Files\Perl . In fact, in Perl, you can't declare the path to the Perl interpreter in the webserver's configuration file, as you do with PHP, but you have to specify it in every script, so that you install Perl in C:\Program Files\perl, every Perl script running on your server must begin with #!/Program Files/Perl/bin/perl instead of the Unix/Linux standard #!/usr/bin/perl . Actually Apache for Windows has a workaround for this using Registry file types as we'll see later, but it's probably not recommended.

If you allow setup to add the path statement to your AUTOEXEC.BAT or add the path manually adding this line SET PATH=%PATH%;C:\usr\bin (where C:\usr\bin should be the actual location of PERL.EXE), you'll be able to run Perl scripts from the MS-DOS command line from any directory, like in this example: PERL HELLOWORLD.PL

Once you've installed Perl, you have to enable CGI scripts and Perl in Apache, so you have to edit Apache configuration file (httpd.conf) and add Options +ExecCGI , like this:

#cgi

Options +ExecCGI

Then you'll have to decide if CGI/Perl scripts can run in a specific directory only (old-style), or in any directory served by Apache.

Single directory. Note that this option is enabled by default (besides the fact CGIs are not enabled, i.e. there's no option ExecCGI by default), so that you will find these lines already coded in the configuration file, although I've put them all together here for semplicity:

#cgi

Options +ExecCGI
ScriptAlias /cgi-bin/ "C:/Programmi/Apache Group/Apache/cgi-bin/"
<Directory "C:/Programmi/Apache Group/Apache/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

If you want to execute CGI scripts in any directory, not just Apache's default CGI directory cgi-bin, you'll have to use these lines instead (and comment out the above lines coded by default):

#cgi

Options +ExecCGI
AddHandler cgi-script .cgi
AddHandler cgi-script .pl

Moreover, Apache for Windows can use file type associations from the Windows Registry, so that if .cgi and .pl are associated with PERL.EXE, you can use the following lines to override the #! directive at the beginning of every Perl script, and to execute CGI scripts from every directory:

#cgi

Options +ExecCGI
ScriptInterpreterSource registry



FTP server (GuildFTPd)

home page: http://www.guildftpd.com/

download page: http://www.guildftpd.com/download.php

This is not actually part of the "WAMPP" system, but in case you need a good and free (although a donation is appreciated) FTP server for Windows, this is the one you should get.

Installation and configuration are very simple, since it's GUI driven. Install it in C:\Program Files\GuildFTPd then start it. You can create single users within groups of users that share part or all the privileges set for that group. Among other settings, the most important one is that you have to set the available paths for every user (or group, so that it will be available for all the users within). The only fundamental thing is that you have to create a virtual root ( / ) directory for all users, so that you can create it at System level to make sure all groups and users have the virtual root directory set. You could phisically set such virtual root directory as C:\ftp for example, then you can create subdirectories inside C:\ftp like pub (read only) and incoming (read/write) and give different access privileges to every user.



SMTP server (PostCast server)

home page: http://www.postcastserver.com/

download page: http://www.postcastserver.com/html/download.asp

Download the latest version and install it following instructions.

The application is free, but the first time you start it you'll be asked for your name and e-mail that the authors use to know who is using it. You must provide a valid e-mail.

You can configure the SMTP server choosing "Settings..." from the "Tools" menu, or pressing the "Settings" button in the toolbar. You'll probably want to set "Mail sending frequency" to Immediately in the System tab, so that e-mails you send will be forwarded immediately to the recipient(s). In the Security tab you can restrict access to certain IPs/domains only to avoid spam relay. In the Advanced tag you can set the reply to the HELO handshaking command with the welcome message you want.

To send your mail through the SMTP server, you'll have to set "localhost" as SMTP server in your e-mail applications. If this doesn't work (it's the case of the PHP, for example), you have to use the host name as shown in Settings...:System:Host Name (note that the host name is case sensitive).

If you want to use your SMTP server to send online form from PHP script, you have to set these directives in the PHP configuration file (php.ini):

SMTP = host name as shown in Settings...:System:Host Name (note that the host name is case sensitive)
smtp_port = 25 ; if this value is not set, it will be set to 25 by default

You can override these settings in your PHP scripts using the ini_set statement:

ini_set("SMTP","HOST_NAME"); ini_set("smtp_port",PORT_NUMBER);



OTHER USEFUL APPLICATIONS

Other applications you may find useful on your Windows based webserver:



GETTING STARTED

Launch WinMySQLadmin and Apache console and your webserver is ready to run and to process PHP scripts and MySQL databases. If there are problems with the webserver check Apache's Error and Access logs. Note that MySQL's traffic light icon must be green, otherwise it means there's a problem and the database is not running. See Start Check and Err File content from MySQL GUI and try to figure out what's going wrong.

To start the FTP server as well, launch GuildFTPd. Check its log if you experience problems.

To access a webpage on your server from a web browser:

From your local system:

http://localhost/
or the equivalent IP
http://127.0.0.1/

From a remote computer on the Internet:

http://your_computers_IP

To know your IP you can type IPCONFIG from an MS-DOS shell window or launch WINIPCFG either from an MS-DOS window or from START menu/Execute...



SHUT DOWN SERVERS

MySQL:
Close MySQL window, or right click on the systray icon and choose Win9x/ShutDown Both (Tool+Server). If a confirmation box appear reply clicking the "YES" button.

Apache:
Close Apache shell window.

GuildFTPd:
The quick'n'dirty way is to close the application window and if a confirmation box appear reply clicking the "YES" button. Otherwise you can click on the ON button or choose it from the Admin / Allow Logins (keyboard shortcut Ctrl+Enter) and then choose what to do with eventual currently logged users: Don't kick current users (doesn't accept new users and shuts down the FTP server when all current users leave), Kick current users after transfers (doesn't accept new users and kick the current ones when they finished the downloads they have in progress, then shuts down the FTP server), Kick users now (kick all users immediately and shuts down server).

Close the application.



UNINSTALLING

Apache, MySQL, GuildFTPd, and PostCast server can be removed from the Control Panel with Add-Remove Applications (respectively with Apache HTTP Server x.x.xx , MySQL Servers and Clients x.xx.xx , GuildFTPd FTP Deamon), while to remove PHP and phpMyAdmin you'll have to delete manually their directories. Perl can be removed with Add-Remove Applications only if you used the MSI installer, otherwise you'll have to delete manually its directory.



UPGRADING

To upgrade one or more of these products, follow the instructions to uninstall them and then install them as if it was the first time.

Make a back'up of the configuration files, although you will not able to use them with newer version you can still use them to compare and update manually the new configuration files:
the whole conf directory (or at least httpd.conf) for Apache
php.ini for PHP
my.cfg for MySQL

If you've started MySQL you'll have to reboot before to launch the SETUP, after uninstalling.



See also Install-a-LAMP (for Debian GNU/Linux)



Issued on Elf Qrin's Hacking Lab
Legal notices and disclaimer