Setting up a WAMP Server by hand


This article will step through what you need to do get WAMP (Windows, Apache, mySQL, PHP) running on windows 2000, 98 or XP. (It might work with Vista, ME or 95, but I don’t promise anything)

By the end, you’ll have a versatile tool that will allow you to:

-host your own website (permanent internet connection preferable)
-learn a basic programming language (PHP)
-learn about relational databases (mySQL)
-learn about server config on the industry standard webserver (apache)

all without having to install a new operating system.

If what you’re looking for is the quickest possible way to set up a windows web server then go to WAMPServer and download WAMP Server. It’ll do everything I outline below automatically. So why read on? To learn how to do it yourself of course!

You learn nothing by just pointing and clicking a few times, and the skills you’ll learn are transferrable too. I provided the WAMPServer link just in case you didn’t know about it :)  As a PHP coder, I often find myself needing to tweak apache settings, and this guide can help you learn how everything works. You can apply much of the knowledge here to LAMP servers.

Getting Started

download Apache (website)
download PHP (website)
download mySQL (website)

Note: this guide is designed for mySQL 4.0.21, PHP 5.02, and Apache 1.3.33. Yes it’s an OLD guide. But I don’t think things will have changed that much – comment if you find something that doesn’t work and I’ll work through it with you. I’m nice like that.

If you don’t have something capable of reading zip files (e.g. winzip) then I suggest 7zip, it’s fast and quite a lot free-er than winzip :-).

I also recommend downloading textpad (textpad.com); it’s just a text editor, but it has some nifty features that make coding PHP (or any other language) a lot easier. It’s not free, but the demo lasts forever.

Log in as the administrator.
Disable your firewall (only for the duration of the install)

Installing Apache

Apache is the web server, which processes file requests and sends them back. Apache is generally recognised as the most stable and secure server money can buy. Not that money is an issue, as it’s also totally free, like all the tools we’re using.

I have to say, installing Apache on windows is incredibly simple, a few clicks and it’s done.

First, open the Apache install file you downloaded, click yes and ok and next and so forth until you reach the “Server Information” screen, then, here’s the info you want:

Network Domain: localhost
Server Name: 127.0.0.1
Admin Email: you@yourdomain.com

Choose whether you want Apache running for all users or not.
If you just going to use the server for development, you can just have it run for you, otherwise I’d recommend having it running for all users.

Choose the complete installation (it only takes under 8 meg, so why not?), stick with the default folder for install, and hit the magic button.

This should be it – verify by opening http://localhost/ or http://127.0.0.1/ in your internet browser.

Wasn’t that easy?

Installing mySQL

mySQL is the industry standard database server, which will allow interactivity on your websites. Like Apache, mySQL is free, stable and secure. It lacks only a few of the features of it’s commercial competitors, and is widely used and trusted. With each new version, more features are added to keep mySQL a viable alternative to other closed source products.

Extract everything from the mySQL zip file straight into drive C, a new folder should appear named “mysql-x.y.z-win”, I’d rename it to simply “mysql” for clarity.

mySQL is now installed, but there’s a little configuring you’ll need to do.

Firstly, let’s set a password:
Start a command prompt by going to Start, then Run, and typing “command”, or on win2k, “cmd”

To start the mySQL daemon, type the following:

c:
cd
cd mysql
cd bin
mysqld

exit that command prompt, and start a new one, again navigating to c:mysqlbin and then log in to mySQL by typing:

mysql -u root

it should say something like this:

Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2 to server version: 4.0.21-nt


Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql>

Note: If you get a message saying that you cannot connect, try rebooting and running ‘mysqld’ again.

Now type the following, replacing “flibble” with your desired password for the mySQL server.

USE mysql;
UPDATE user SET Password=PASSWORD("flibble");
FLUSH PRIVILEGES;
exit;

Ok, so now you’ve set the password for all default accounts, all we need to do is get the server to run automatically, on startup (if you don’t want mySQL to run every time you turn on the computer, then skip this step)

To run mySQL for all users:
Create a shortcut to c:mysqlbinmysqld.exe in C:Documents and SettingsAll Users.WINNTStart MenuProgramsStartup

To run mySQL for just you
Create a shortcut to c:mysqlbinmysqld.exe in C:Documents and Settingsyour_username_hereStart MenuProgramsStartup

Installing PHP

This is easy;

Extract the zip file to c:php

Create a folder named “sessiondata” inside c:php

Take “C:phpphp.ini-recommended”, and copy it to “C:WINNTphp.ini” (or C:windowsphp.ini), making the following changes:

Line Old Value New Value
353 display_errors = Off display_errors = On
636 ;extension=php_mysql.dll extension=php_mysql.dll

note that we removed the semi-colon in the “extension” line.

PHP is now installed.

Getting the left hand to know what the right is doing

Firstly, we need to let Apache know that it should process .php files as PHP code:

open C:Program FilesApache GroupApacheconfhttpd.conf in a text editor (eg notepad or textpad)

Scroll to the bottom, and add the following lines:

# add PHP5 as an apache module
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
LoadModule php5_module "c:/php/php5apache.dll"
SetEnv PHPRC C:/php

Note: in this section, you can specify any type of file to be run through PHP, for instance, some servers use:

AddType application/x-httpd-php .htm
AddType application/x-httpd-php .html

as well as .php; this may result in some performance issues, as every html file will be run through PHP to be processed. The benefit is that search engines sometimes (used to) place slightly higher value on html files.

Generally, though, there is no reason to do this. It gets confusing when you’re developing code if you don’t know whether blah.html is a PHP file or not, and if you need to change servers at a later date you’ll need to reconfigure them as well.

Now, to allow Apache to serve index.php as the default page, search for “DirectoryIndex index.html” and edit it to read

DirectoryIndex index.html index.php

Now, to allow PHP to find the mySQL functions, copy the following files:

c:phplibmysql.dll
c:phpextphp_mysql.dll

to c:WINNT (or C:windows, depending on your setup)

Ok, all done, now we need to restart Apache;
Open a command prompt and type:

net stop apache
net start apache

Testing whether it worked

Apache stores the website files in “C:Program FilesApache GroupApachehtdocs”

If you open that directory, you’ll see there’s a bunch of files there, you can delete everything, though you may want to look through the ‘manual’ directory later.

Make sure that windows is set up to show all file exensions (Tools|Folder Options|View, untick “Hide file extensions for known file types”. On windows98, it’s under ‘view’, not ‘tools’.)

Now, to test PHP, create a new text document with the following content, and name it “info.php”:

<?
phpinfo();
?>

open http://localhost/info.php in your browser, and marvel at the wonders of PHP.

you should see the standard phpinfo page, which tells you almost everything you need to know about your install of PHP.

Let’s see if mySQL is working.

Create mysql.php in htdocs, and place this content in it:

<?
// connect to the server:
$cn = mysql_connect("127.0.0.1","root","flibble");
// run a simple query
$sql = "SELECT 'done' as my_field LIMIT 1";
$result = mysql_query($sql,$cn);


if($result)
{
// if it worked, print the result to screen
echo mysql_result($result,"my_field");
} else {
// otherwise, either the server isn't running
// or the username/password are wrong
echo mysql_error()."You should see an error message above you?";
}
?>

Now open http://localhost/mysql.php, and you should see a message saying ‘done’.

You may now delete info.php and mysql.php

Take some time to look through the manual (http://localhost/manual/) there’s some useful stuff in there.

Also, learn to love php.net; their function reference is second to none.

If you get any error messages or problems along the way, email puremango.co.uk@gmail.com with details of your operating system, version of apache, mysql and php and details of the error, include error messages if you get them.

Enjoy working with your shiny new WAMP server!


Related Posts:

, , , , , , , , ,

  1. #1 by Dayal Cooray on May 20, 2009 - 12:23 am

    Good guide. Thanks.
    However, I just had to add another line –
    LoadFile c:/php/php5ts.dll just before
    “LoadModule php5_module “c:/php…….” Line to make it working.

    Regards
    Dayal.

  2. #2 by toivape on July 1, 2009 - 2:06 am

    Apache 2.2 on WinXp or Vista is a bit different:
    Add this to loadmodule section:

    LoadModule php5_module “C:/php/php5apache2_2.dll”

    And then add this to the end of the httpd.conf:

    <IfModule php5_module>
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .php
    </IfModule>

    • #3 by user24 on July 1, 2009 - 3:12 am

      thanks for the update, much appreciated!

  3. #4 by vasu on July 11, 2009 - 7:22 pm

    am beginer in php,i hav a small doubt
    “How to access php application in Lan which is runnin in one system ?”

    • #5 by user24 on July 12, 2009 - 8:16 am

      Sorry, I don’t understand your question. LANs can typically be accessed via an IP addresses in the 192.168.254.X or 10.X.X.X range, but the individual setup may be different.

  4. #6 by speedy18us on July 31, 2009 - 10:48 pm

    for those who don’t whant the trouble of installing apache, php and mysql, you can use wamp http://www.wampserver.com/en/ or xamp http://www.apachefriends.org/en/xampp-windows.html .at home i use wamp and at work i use xamp . one question to the admin: did you make those menu rss efects and others i saw on this website? jquery is awesome, i just started to use it in my projects :)

  5. #7 by croc-pray on October 4, 2009 - 12:05 pm

    I tried to install once apache, php and mysql from setups. it didn’t work. when i tried to start mysql service, it just stoped apache. i think i will try using this tutorial. thanks

  6. #8 by Alan Lilly on February 5, 2010 - 10:57 pm

    As an aid to this post you should also checkout my installation guide for a manual wamp server at panofish.net

  7. #9 by shyam on June 13, 2010 - 8:27 pm

    i ve installed wamp server 2 on windows 2003 server. before installed it i remove iis. everyday when i start server machine wamp database which i created was automatically removed. i have clicked both install services(appache and mysql) and i put it online , set to automatically start with widows startup. why auto remove that created database?

  8. #10 by rack monitor on November 15, 2010 - 1:55 am

    Can you provide me some information about the LAMP. I want to install php, mysql and apache at linux.

  9. #11 by opg31 on November 30, 2010 - 10:57 pm

    Hi, I tried setting up APACHE 2.2.17, mysql 5.1.52 and PHP 5.3.3, I did all the settings as indicated on the text files. I was able to run the phpinof() function and display it on the browser, but I can’t still manage to connect to mysql using the script mentioned on this site. I was able to login to mysql without any problems at all, any idea as to why?.. thanks!

  10. #12 by opg31 on December 1, 2010 - 12:06 am

    darn it! finally made it work, was able to connect now tot he mysql

  11. #13 by Chris on May 1, 2012 - 11:13 am

    I read, your article at puremango.co.uk/2009/01/wamp-97. I tried it. Most things worked e’en tho’ I had a different verion of PHP compare to d one u referenced.

    Now pls, I need help with how 2 get my PHP 5.2.13 to talk to my MySQL 5.5

    Note: Apache and PHP are communicating.
    Thank you so very much.

Comments are closed.