WAMP HOWTO
Author: Troy Wolf (troy@troywolf.com)
Modified Date: 2005-07-11 14:00
WAMP stands for:
- Windows Operating System
- Apache Web Server
- MySQL Database
- PHP Scripting Language
|
|
This document explains how to install, configure, and test a basic setup. I'll
also show you how to install phpMyAdmin which is an excellent browser-based
tool to administrate your MySQL database.
These instructions were designed for Windows XP Pro and Home users although
they should work for Windows 98 and Windows Server 2000/2003 with little
modification.
DISCLAIMER: Use these instructions at your own risk. I do not guarantee
any particular outcome. The basic configuration shown in this document is not
secure. These instructions are not designed to help you setup a production system.
Rather, they are to help newbies setup a basic system to learn about web
development. In this HOWTO, I do not attempt to tell you HOW to use Apache,
MySql, PHP, or phpMyAdmin. Instead, I explain only enough to get it all
downloaded, installed, configured, and tested. As fast as things change, these
instructions may not be accurate in 30 days. PLEASE follow these directions in
the order listed and do not proceed until you have the previous parts tested
and working.
Apache - The Web Server
I am not providing a direct link to a download since the links can change often,
and Apache prefers you use a "local" mirror site to download from. So visit
http://httpd.apache.org/download.cgi
and download the "Win32 Binary (MSI Installer)". The actual file name at time of
this writing is apache_2.0.54-win32-x86-no_ssl.msi.
Run the installer and follow the installation wizard using all the default
options. When asked to provide a domain name, if you are just installing for
personal local development and learning, you can enter anything you want.
Try mydomain.net for example. This same screen will prompt for a server name
and an email address. The server name must include the domain name. So you could
enter www.mydomain.net. (In this case, the name of your computer is "www" and
the full name is "www.mydomain.net". It does not have to match the actual
computer name of your machine.) You can just enter your real email address--it
wont matter.
If everything worked, you should now have Apache installed and configured as a
Windows Service which means it will automatically start when you start Windows.
You should have a new icon in your System Tray that is a little red Apache
feather. The icon shows the status of your web server--green for running and
red for stopped. You can click it to open the Apache Service Monitor. You use
this to Stop, Start, and Restart the service. You will need to restart the
service anytime you make a configuration change---more on that later.
Confirm that the service is running. If not, start it. If it fails, then your
problems are beyond this tutorial. Sorry. Thank you for playing. There is no
need for you to continue beyond this point.
Congratulations! You have a web server! Open a browser and go to
http://localhost. You should see
the Apache default page telling you your server is working. These pages are
being served from the DocumentRoot, which by default is a folder named
htdocs within the location you installed Apache. Default is
C:\Program Files\Apache Group\Apache2\htdocs. I like to leave this folder alone,
and create my own DocumentRoot to build my website in. To do this, create a
folder named www on your C:\ drive. Navigate to your C:\www folder, and create
a new file using Notepad or your favorite text editor. (I recommend
PSPad.) Name it index.html.
Copy and paste the following into c:\www\index.html.
<html>
<head>
<title>My Own Local Web Server</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
Now we need to edit the Apache configuration to point it to our c:\www folder
as the DocumentRoot. To do this, again in your favorite text editor,
open the Apache conf file. By default this is C:\Program Files\Apache Group\Apache2\conf\httpd.conf.
Find the line that looks like this:
DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"
And turn it into this:
DocumentRoot "C:/www"
Save your changes. Using the Apache Service Monitor, Restart the service. Open a browser and go to http://localhost. You should see your new home page which is c:\www\index.html.
Whew! Step 1 complete.
PHP - The Scripting Language
Visit http://www.php.net/downloads.php
and download "PHP 5.0.4 zip package". The actual file name at time of writing
was php-5.0.4-Win32.zip.
Create a folder named php on your C:\ drive. Unzip the file into c:\php.
Make a copy of c:\php\php.ini-recommended and name it c:\php\php.ini
There are lots of values in the php.ini file you may eventually want to modify,
but for now, as you are learning, you want to enable the display of errors and
warnings. Open c:\php\php.ini in
your favorite text editor. Change this line:
display_errors = Off
To:
display_errors = On
While you are in the php.ini file, you'll want to set the extensions path by
changing this line:
extension_dir = "./"
To:
extension_dir = "c:\php\ext\"
You can close the php.ini file now.
Right-click My Computer and choose Properties. Choose the Advanced tab.
Click the Environment Variables button at the bottom. In the System Variables
section, click Path, then the Edit button. At the end of the path value,
add ;C:\php;C:\php\ext Click OK and keep clicking OK until you exit out of the
Properties. Reboot your computer. Grab a drink. Don't worry, I'll wait for you
here.
Welcome back. Now we have to modify the Apache conf so it knows to use the PHP
module. To do this, again in your favorite text editor, open the Apache conf
file. Find the LoadModule section that begins with a comment line that looks
like this:
# Dynamic Shared Object (DSO) Support
At the end of the list of LoadModule lines, add these 4 lines:
# PHP5
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php
PHPIniDir "c:/php/"
Also, find this line:
DirectoryIndex index.html index.html.var
And change it to this:
DirectoryIndex index.html index.html.var index.php
Now, save your changes, and restart Apache. (By now, you should know how to restart Apache.)
Create a new file named c:\www\index.php. Copy these lines into it:
<?php
phpinfo();
?>
Save this file. Rename c:\www\index.html to c:\www\old_index.html.
Open http://localhost in your
browser. You should see the phpinfo page that displays your PHP version at top
and a lot of system and user information tables. (Check out the phpinfo()
function at
http://www.php.net/manual/en/function.phpinfo.php.)
If this did not work for you, your issues are beyond the help of this tutorial. Sorry. Thank you for playing. There is no need to continue beyond this point.
Congratulations! You not only have a web server, you have successfully incorporated the PHP scripting module into Apache.
MySql - The Database
Visit
http://dev.mysql.com/get/Downloads/MySQL-4.1/mysql-essential-4.1.12a-win32.msi/from/pick#mirrors
to download the
MySql 4.1 Windows Essential (x86) package. The actual filename at time of
writing was mysql-essential-4.1.12a-win32.msi.
Run the installer and use all the default values. When prompted for a root password, choose one you can remember. Normally, security is an issue here, but if this is just for you to learn and play, it does not matter much.
Once the installation is complete, MySql should be configured as a Windows
Service which means it will auto start when you start Windows.
You should have a new MySql folder in your Start/All Programs menu.
One of the items in the menu is MySQL Command Line Client. You can use
this to do all your database administration from creating databases and tables
to inserting data, etc. However, most people are not very comfortable using the
command line interface, so later, I'll show you how to setup phpMyAdmin--a
browser-based GUI tool. For now, though, use the MySQL Command Line Client to
test your installation. Open the command line client to see a password prompt.
Enter your root password. If successful, you'll see something like this:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 60 to server version: 4.1.12a-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
If this does not work for you, your issues are beyond this tutorial. Sorry. Thank you for playing. There is no need to continue beyond this point.
Congratulations! You now have a working MySql database server.
Now you need to configure PHP to work with MySql. Open c:\php\php.ini in
your favorite text editor. There are 2 lines you need to uncomment. Change this line:
;extension=php_mbstring.dll
To:
extension=php_mbstring.dll
Change this line:
;extension=php_mysql.dll
To:
extension=php_mysql.dll
Save your changes. Restart the Apache service. (That's right--since we are using php as an Apache module, anytime you change either the Apache conf file or the PHP ini file, you must restart Apache to see your changes.)
To test that you have PHP configured to work with MySql, create a file named c:\www\dbtest.php. Copy and paste the following into it:
<?php
$db_server = "localhost";
$db_user = "root";
$db_pwd = ""; //Enter your root password here.
$db_db = "mysql";
if (!$cnn = mysql_connect($db_server, $db_user, $db_pwd)) {
echo mysql_error();
exit();
}
if (!mysql_select_db($db_db, $cnn)) {
echo mysql_error();
exit();
}
$sql = "select * from help_category";
if (!$res = mysql_query($sql, $cnn)) {
echo mysql_error();
exit();
}
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
$data[] = $row;
}
?>
<html>
<head>
<title>Apache/PHP/MySql Test</title>
</head>
<body>
<h1>Help Categories</h1>
<?
echo "<style>table.dump { font-family:Arial; font-size:8pt; }</style>";
echo "<table class=\"dump\" border=\"1\" cellpadding=\"1\" cellspacing=\"0\">\n";
echo "<tr>";
echo "<th>#</th>";
foreach($data[0] as $key=>$val) {
echo "<th><b>";
echo $key;
echo "</b></th>";
}
echo "</tr>\n";
$row_cnt = 0;
foreach($data as $row) {
$row_cnt++;
echo "<tr align='center'>";
echo "<td>".$row_cnt."</td>";
foreach($row as $val) {
echo "<td>";
echo $val;
echo "</td>";
}
echo"</tr>\n";
}
echo "</table>\n";
?>
</body>
</html>
Be sure to put your mysql root password in the 5th line. Save your changes. Open
http://localhost/dbtest.php
in your browser. You should see the contents of the help_category table in the
database named "mysql". (This is the system database. Normally you won't be working
with this database. Instead, you'll create your own database to add tables and data to.)
phpMyAdmin - Browser-based GUI Admin tool for MySql
Download the latest stable release of phpMyAdmin. You can find this by starting at
http://www.phpmyadmin.net/home_page/index.php.
At time of this writing, the latest stable release was 2.6.3. Pick a download
location from
http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-2.6.3-pl1.zip?download
The actual filename at time of writing was phpMyAdmin-2.6.3-pl1.zip.
Create a folder named c:\www\phpMyAdmin. Unzip the file into this new folder.
Open C:\www\phpMyAdmin\config.inc.php in your favorite text editor. Find this
section, and input your mysql username and password. You should enter 'root'
as the username, and the root password you used when you installed MySql.
$cfg['Servers'][$i]['user'] = ''; // MySQL user
$cfg['Servers'][$i]['password'] = ''; // MySQL password (only needed
Be careful as there are other places in the config file that look like places to put your username and password. Find the lines that look exactly like what I listed above--and only change those 2 lines.
Save your changes. Open http://localhost/phpMyAdmin
in your browser. If you do not see the phpMyAdmin tool, then your issues are
beyond this tutorial. Sorry. Thank you for playing. There is no need to continue
beyond this point.
Congratulations! You now have a WAMP system with phpMyAdmin to administrate your database.
Enjoy the journey.
About the author
Troy Wolf operates
ShinySolutions Webhosting,
and is the author of
SnippetEdit--a PHP application
providing browser-based website editing that even non-technical people can
use. Website editing as easy as it gets. Troy has been a professional
Internet and database application developer for over 12 years. He has many
years' experience with ASP, VBScript, PHP, Javascript, DHTML, CSS, SQL, and
XML on Windows and Linux platforms. Check out
Troy's Code Library.