Wednesday, March 29, 2006

Setting up WAMP

Setting up WAMP

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 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.

Required tools:
a fairly clean basic box, e.g.:
ram: approx 256Mb+
mhz: approx 700+
HDD: approx 200Mb free
Admin access to your box (not required on win98-).

Estimated time: MAX 2 hours.

By ‘fairly clean’, I mean close to it’s original condition; the fewer things installed on it the better. Of significant concern are things like firewalls, almost anything by norton, AOL, third party secuity suites, etc. Ideally, you’ll want to re-install the whole computer from scratch, but this is by no means required.

easy guide to installing WAMP - Windows Apache PHP Mysql Getting Started

Firstly, you may like to print this page, not only will you undoubtably need it at some future point, but also, we’ll be disconnecting from the net while we do the install.

Click here for a printer friendly PDF of this page (thanks to Siv for the PDF), or click here change to the ‘text’ scheme.
Note that the PDF is not updated as often as this page is (like, never), so try the text scheme first and if that won’t work, then use the PDF (or just forget the whole thing)…

Secondly, you’ll need to download all the installers for the programs we’ll be installing;

download Apache 1.3.33 (from www.apache.org)
download PHP 5.02 (from www.php.net)
download mySQL 4.0.21 (from www.mysql.org)

or go to the respective websites and grab the latest versions, but I can’t guarantee that this guide will work with other versions.

Note: this guide is designed for mySQL 4.0.21, however mysql.org no longer distribute that version, hence, the link to mySQL is for 4.0.23. This should not affect the guide. I do plan to host all install files locally at some point.

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

I also recommend downloading textpad (www.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.

Now, reboot your computer. This is important as it will ensure that your system is fresh and ready to kick some ass.

If you’re running win2k, log in as the administrator.
Disconnect from the internet
If you have one, disable your firewall. In fact, disable everything that’s running; no taskbar icons, no extra status bar icons. This will help ensure the install goes smoothly.

easy guide to installing WAMP - Windows Apache PHP Mysql 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?

easy guide to installing WAMP - Windows Apache PHP Mysql Installing mySQL

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

Extract everything from “mysql-4.0.21-win-noinstall.zip” straight into drive C, a new folder should appear named “mysql-4.0.21-win”, you can rename this something else if you want to, it really doesn’t matter (but bear in mind that that’s what I use, so my config examples are tailored to this directory).

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 mysql-4.0.21-win
cd bin
mysqld

exit that command prompt, and start a new one, again navigating to c:mysql-4.0.21-winbin

now type

mysql -u root

to log in to mySQL, it should say

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:mysql-4.0.21-winbinmysqld.exe in C:Documents and SettingsAll Users.WINNTStart MenuProgramsStartup

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

easy guide to installing WAMP - Windows Apache PHP Mysql Installing PHP

This is easy;

Extract php-5.0.2-Win32.zip 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

PHP is now installed.

easy guide to installing WAMP - Windows Apache PHP Mysql 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 place slightly higher value on html files. Also, it makes it ever so slightly harder for hackers to determine which files are PHP.

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, or if you need to change servers at a later date.

Now, to allow Apache to serve index.php as the default page, search for “DirectoryIndex index.html” (line 385), 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

Now to test 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 need 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
with details of your operating system, version of apache, mysql and php and details of the error, include error messages if you get them.

Posted by Babai in 07:44:29 | Permalink | No Comments »