Web Services Setup and Configuration Guide

Win9x / NTx Platforms
Revision 7

 

Before You Start

This guide will walk you through the installation of the Apache 2 Web Server and optionally PHP and MySQL Web Services. This guide will refer to several special directories, and will refer to them in a {directory} format. Two of these are Windows directories, and below are listed the default paths depending on your operating system. Your paths may be different, these are only defaults.

This guide will refer to {windows_dir}. This is your Windows directory.

- For Windows 9x/ME, {windows_dir} is C:\WINDOWS
- For Windows NT/2000, {windows_dir} is C:\winnt
- For Windows XP/2003, {windows_dir} is C:\Windows

This guide will refer to {system_dir}. This is your Windows System directory.

- For Windows 9x/ME, {system_dir} is C:\WINDOWS\System
- For Windows NT/2000, {system_dir} is C:\winnt\System32
- For Windows XP/2003, {system_dir} is C:\Windows\System32

 

Apache 2 Web Server
Prerequisites: None

1) Download Software
 

- Download a copy of Apache 2 from www.apache.org. The latest version at the time of writing is 2.0.54.
(http://www.tux.org/pub/net/apache/dist/httpd/binar...-x86-no_ssl.msi)

 

2) Install the Web Server
 

- Run the EXE

- Choose CUSTOM Install

- You don't need to change any of the settings, but this is the place to choose the install destination IF YOU WANT TO. If you don't, just leave it as default and carry on. The install path will be referred to as {apache_dir} from this point forward

- You'll be prompted to fill in three boxes. None of them will have (much) bearing on how the server runs, so their contents are not important. For domain name, put your IP, hostname, ISP, favorite flavor of cheese, or word of the day. Server Name is the name of the computer. If you haven't named your computer, consider it. What you name it is not important. Admin Email should be your email address, or something else if you don't want your email to be displayed on all the 4xx error pages that'll crop up.

- If it's available, select to run the server as a service of port 80. If you can't, make a mental note for later in this guide if you end up having trouble.

- Just keep hitting enter and the server will eventually be installed.

 

3) Configure the Web Server
 

- You'll need to edit apache's httpd.conf. You can get to this by going to Start->Programs->Apache Httpd Server->Configuration->Edit httpd.conf

- There's no settings that need your immediate attention now, but if you chose to install PHP or other web services, several lines will need to be changed or added. Remember how to open and edit the httpd.conf file.

 

4) Controlling the Web Server
 

- If Apache isn't started, start it from your program menu. If it fails to start, there's an error in your httpd.conf that you'll need to correct, or you didn't copy all the files to the right places.

- For Windows NT/2K/XP machines, Apache will try to start every time you boot up. For 9x, if it doesn't start automatically, add a shortcut of it to Startup in your program directory in the start menu.

- To start, stop, or reset the server, there's an icon in your sys_tray where you'll get a console with the control buttons.

 

5) Testing the Web Server
 

- Assuming apache started OK, you should be able to access your web pages from your browser. Type in your IP in the browser address bar (after the http://). If you don't know your IP, you can find it by going to Start->run and typing winipcfg (9x/ME) or Start->run and typing cmd then typing ipconfig at the command prompt (NT/2000/XP). When you type it in your browser, you should get an apache web page. Alternatively, you can type in http://localhost into your address bar, but you won't be able to share that URL with friends.

- If the page came up, congratulations, apache works. If you want to be able to view a page, you need to put it in your htdocs directory. By default, this directory is {apache_dir}/htdocs (C:\Program Files\Apache Group\Apache2\htdocs for default install location).

- Create an html file with the following contents:

Code Snippet:


<b>Hello World</b>

- Save it as test.html, and access it from your browser (http://m.y.i.p/test.html) or (http://localhost/test.html). You should get a bold-faced Hello World.

 

PHP4
Prerequisites: Apache 2 Web Server

1) Download Software
 

- Download a copy of the PHP4 zip package (not installer) from www.php.net The latest version at the time of revision is 4.3.11.
(http://us2.php.net/get/php-4.3.11-Win32.zip...rom/this/mirror)

 

2) Setup PHP
 

Extract the PHP zip file to some place on your hard disk. C:\PHP4 is probably most convenient, but any place will do. The path you extracted the files to will be called {php_dir} from this point forward.

Copy php4apache2.dll from {php_dir}/sapi to {php_dir}

Copy php.ini-dist from {php_dir} to {windows_dir}. Rename it to php.ini

Copy php4ts.dll from {php_dir} to {system_dir}

 

3) Configure Apache
  - Open your httpd.conf file as you did when configuring Apache.

- Add this line:

LoadModule php4_module {php_dir}/php4apache2.dll

(Example: LoadModule php4_module C:/PHP4/php2apache2.dll)
At the bottom of the (lengthy) list of LoadModule lines towards the top of the file.

- Add these lines:

AddType application/x-httpd-php .php .php2 .php3 .php4 .php5 .phtml
AddType application/x-httpd-php-source .phps

Right after the long list of AddCharset lines towards the bottom of the file. It should be inserted directly after a similar AddType line for application/x-tar .tgz.

- Change the DirectoryIndex line, which should be about line 322. Change it to look like the following:

DirectoryIndex index.php index.phtml index.php4 index.php3 index.php2 index.html index.htm

- That completes the necessary configuration of httpd.conf. Save and exit. If apache fails to start after, you made an error.

 
4) Configure PHP
 

- Open the php.ini file you moved to your {windows_dir}. These settings aren't critical to getting PHP to run, but certain features won't work without them. The line numbers may not be exact, depending on your version of PHP and what modifications you have made.

- Near line 438, change the extension_dir line to read

extension_dir = "{php_dir}\extensions"

(Example: extension_dir = "C:\PHP4\extensions")

- Create a new directory called tmp within your {php_dir}

- Near line 824, change the session.save_path line to read

session.save_path = "{php_dir}\tmp"

(Example: session.save_path = "C:\PHP4\tmp")

 

5) Testing PHP
 

- Create a PHP file with the following contents:

Code Snippet:


<?php
$greet = "Hello ";
echo $greet . "World!";
?>

 

- Save it as test.php, and access it similarly to test.html. You should get Hello World, like before (no boldface). If you see the code and not the message, then there's a problem with your PHP setup. Check your httpd.conf and the files you copied. If you see Hello World, then congratulations, you've successfully setup PHP4 on your system

 

6) Optional Configuration
 

- These configurations aren't critical and deal with specific features you may want to enable. This section is last because they pose an unneccesary risk of problem during setup, and if PHP or Apache stops working, you'll know it's directly related to one of the settings you've changed in this section.

- Open the php.ini saved in your {windows_dir}.

- To enable the gd2 library (necessary for PHP's image generation functions),
Near line 550, remove the semicolon (;) before:

extention=php_gd2

 

 

MySQL
Prerequisites: None

1) Download Software
 

- Download the MySQL installer from www.mysql.com. The latest version at the time of writing is 4.1.12a
(http://dev.mysql.com/get/Downloads/...ql.mirrors.pair.com/)

- Download the MySQL Control Center from www.mysql.com. This will be used for administrating your server.
(http://www.mysql.com/get/Downloads/...ql.mirrors.pair.com/)

 

2) Install MySQL Server
 

- Unzip the MySQL installer and run it. The install is strait-forward, this is your chance to change its install location, although it's recommended you install it to its default location (C:\mysql). Chose Typical install and it'll do the rest by itself. Wherever you installed mysql to will now be referred to as {mysql_dir}.

- Open notepad (It's in accessories), and chose to open a file. Browse to your {mysql_dir} and open my-small (or my-small.cnf if your operating system displays the extension - Windows XP does not). This is a basic configuration file, if you changed the install location of MySQL, you'll need to uncomment basedir and datadir and set the paths to {mysql_dir} and {mysql_dir}/data respectively.

- Save my-small as my.cnf in the root of your drive, C:\.

- If you're running Windows NT/2K/XP, open up a command prompt by going to Start->Run and typing cmd. Run the following commands:

CD {mysql_dir}\bin
mysqld --install
NET START MySQL

(Example for CD: CD C:\mysql\bin)
This will install the MySQL server as a Windows Service and start it. This is the most ideal situation. If MySQL fails to start on the NET START command, you likely didn't copy your config file properly in the previous step.

- If you're running Windows 9x/ME instead, Open explorer and browse to your {mysql_dir}. Go into the bin folder, and make a shortcut of mysqld.exe. Put this shortcut into your startup directory, so MySQL starts when you start windows.

 

3) Testing The Setup
 

- Open a command prompt (Start->Run and typing cmd for NT/2K/XP or Start->Run and typing command for 9x/ME).

- Run the following commands

CD {mysql_dir}\bin
mysqlshow

- An ASCII table containing 'mysql' and 'test' should be output. If it is, congratulations, you've successfully installed the MySQL server.

 

4) Seting Up The MySQL Control Center
 

- MySQL Control Center is a convenient administration program for managing your users and databases. Whatever you could do in phpMyAdmin you can do in the Control Center, and it's easier and faster. Unzip the install file and run it. This is your change to change the install path, but it's not significant. You have no significant options to change during install, so just blast right through it.

- Run the Control Center. You'll be asked to register your first server, which will be the MySQL server you just set up. Name and Hostname should be set to localhost, User should be root, and the password should be blank. Here's a screenshot of what it should look like:

- Click Test to make sure you can connect. If the test fails, your server may not be running. If all goes well, Add the server.

- In the server sidebar, double click on localhost. Beneath that, double click User Administration. Select and delete all users listed EXCEPT root@localhost.

- Double click root@localhost to edit the root account. Set a password and save. (The number of asterisks will change after you apply, this is normal).

- In the Server Sidebar, right click localhost and select edit. You'll want to change the password field to the password you just set for your root account. Apply it.

- Back under localhost in the Server Sidebar, double click Databases. In the toolbar, click the New Database Icon. You'll be asked to name your database, you can call it anything except mysql or test. For the purpose of this guide, it will be assumed you called it 'mytest', but you should name it something more meaningful.

- Go into User Administration again, now up in the toolbar click the New User button. This is where you'll create the user you'll be using to connect to your newly created database. You need to give this user access to that database, so check the box in the side. There's no need to change any of the permissions. Here's another image of what it should look like:

- Your username, password, and database will be different, but the rest is the same. If everything looks all right, go ahead and add the user.

- That's all you need to do for now in the Control Center. You can create, modify, or remove users and databases at any time. Just don't remove the mysql database or the root@localhost user. You'll be able to perform other actions such as creating tables, inserting or modifying rows, and any of the other tasks you'd customarily perform in phpMyAdmin. I strongly encourage you to try adding tables and records, but that's beyond the scope of this guide.

 

5) Testing PHP with MySQL
 

- This step is only for those who have setup PHP. By default PHP should already support MySQL, provided you have a database to connect to and a user to connect with, and that the server is running. Save the following script as mysqltest.php into your document root (htdocs in a default Apache install) and run it in your web browser.

Don't forget to change the username and password (currently username and mypassword) in the script to reflect your own server settings. Same goes for the database (currently mytest).

Code Snippit:


<?php
$connection = mysql_connect("localhost", "username", "mypassword");
mysql_select_db("mytest", $connection);
mysql_query("CREATE TABLE pet (name VARCHAR(20), species VARCHAR(20))", $connection);
mysql_query("INSERT INTO pet (name,species) VALUES ('Fourpaws', 'Cat')", $connection);
$result = mysql_query("SELECT * FROM pet", $connection);
$mypet = mysql_fetch_object($result);
echo "One of my pets is a $mypet->species, his name is $mypet->name.";
?>

- This script will create a new table, insert a record, then retrieve the record. If successful, the script should display:

One of my pets is a Cat, his name is Fourpaws.

- If you got that output, congratulations. You're ready to start creating database-driven web applications in PHP right on your own machine.

 

Copyright © 2003-2005 Justin Aquadro