Configuring Apache, PHP, MySQL and Domino for Windows 2000

Table of Contents
  • Locating The Installation Files
  • Installing Apache
    • Configuring the Apache Server
  • Installing PHP
    • Configuring PHP.ini
    • Testing PHP is Working
  • Installing MySQL
    • Configuring MySQL
  • Installing MySQL Command Centre
    • Configuring MySQL Control Centre
  • Testing the setup
    • Expected Result
  • Configuring Apache and Domino
    • Advanced Apache and Domino Configuration for Authentication
    • Dealing with URLs containing replicaIDs
  • On-line Articles and References


Introduction

This article covers how to configure Apache, PHP, MySQL and Domino to work with each other under Windows 2000.


Locating The Installation Files


Apache v2.0.47
Site: http://httpd.apache.org/
Downloads: http://httpd.apache.org/download.cgi
Download the "Best Available Version" which at time of writing is 2.0.47
Filename: apache_2.0.47-win32-x86-no_ssl.msi

PHP v4.3.3
Site: http://www.php.net
Downloads: http://www.php.net/downloads.php
Filename: php-4.3.3-Win32.zip

MySQL v4.0.15
Site: http://www.mysql.com
Downloads: http://www.mysql.com/downloads/index.html
Filename: mysql-4.0.15-win.zip

MySQL® Control Center v0.9.2
Site: http://www.mysql.com/products/mysqlcc/index.html
Downloads: http://www.mysql.com/downloads/mysqlcc.html
Filename: mysqlcc-0.9.2-win32.zip


Lotus Domino
Version Installed 6.0.2 CF1



Installing Apache


1. Double click the downloaded "apache_2.0.47-win32-x86-no_ssl.msi" file and the install Wizard will be displayed

2. Click Next, then "I accept" and next, next again at the "Read This First" screen. You should then reach the Server Information screen.

3. Server information: It is not essential that the server information is absolutely correct at this stage as it can easily be changed at a later date but it is worth getting it correct if you can to save time later on. When you have entered the information click next.

4. The next screen asks if you want a Typical or Custom installation, choose Typical.

5. You are then asked to enter the installation directory which defaults to c:/Program Files/Apache Group/
The destination directory is your choice and the default is fine, however, for this entire installation I am installing the applications directly off of the root (c:/Apache2, c:/PHP, c:/MySQL etc.) to make configuration easier and consistent, mainly because PHP and MySQL assume they are installed off of the root. So in my installation I clicked the "Change" button and entered C:/, don't worry no actual files are installed in the Root of C, the installation creates an Apache2 directory and puts all files in there.

6. Click install
7. Click Finish



After the install the server should be automatically started for you and the Apache Service Monitor should be visible in the system tray. Double clicking this icon will bring up the Apache Service Monitor which is where you can stop and start the Apache server, which is actually installed as a Windows service.




If you need to access the Monitor yourself you can find it under the program menu
Start/Programs/Apache HTTP Server 2.0.47/Control Apache Server

If you now run a browser to http://localhost you should see the following screen and if you do Apache server is installed and working.




Configuring the Apache Server


Apache has one main configuration file, the httpd.conf file. This file is located in the C:/Apache2/conf directory and can be accessed from your program files menu. You may wish to make a shortcut to this file on your desktop as you are going to be accessing it quite frequently.




1. The first thing you might want to do is change the document root directory which is by default set to C:/Apache2/htdocs in my configuration I can changed it to c:/webroot. Open the httpd.conf file search for the DocumentRoot line and change it or comment it out by putting a # at the start of the line and add your own line. Note the use of forward slashes NOT back slashes.




2. If you change the root directory you have to give Apache permission to that directory. Find
and change to




3. Next you need to set default index file types, the files that will be served by default if no specific file is specified in a URL. You need to search for "DirectoryIndex" and add to the end of the line index.php and optionally index.htm.



4. Add PHP Content types. This will allow Apache to recognise PHP content types when opening files. Search for "AddType application/x-tar" and insert the following lines (you can simply copy and paste from here).

ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .html
AddType application/x-httpd-php .phtml
Action application/x-httpd-php "/php/php.exe"




5. Save and Close the httpd.conf file

6. You can now test these changes. Add an index.htm file to the c:/webroot directory and restart the Apache server by going to the Apache Services Monitor (double clicking the magnifying glass icon in the system tray) and pressing restart. If you now open a browser and go to http://localhost you should see the contents of your index.htm file.


Installing PHP


The version of PHP that we have downloaded (php-4.3.3-Win32.zip) does not have an automated installation wizard, but the installation is very easy.

Extract the contents of the installation ZIP to a temporary directory. The directory structure that has been extracted contains many files for many different scenarios, but for a basic installation ONLY 3 FILES ARE REQUIRED.

Copy the php.exe, php.ini-dist and php4ts.dll to c:/php. keep the distribution zip and/or the extracted files in case you decided to use any of the supplied extensions. The reason I installed PHP in this way is so that only the files and extensions being used will be located in c:/php making it easier to keep track of what is in use.





Configuring PHP.ini


The php.ini file is the file that contains ALL configuration for PHP.

1. In c:/php you have a file called php.ini-dist, this is the php.ini file. First you need to rename it from php.ini-dist to php.ini.

2. Now edit php.ini

3. Search for "doc_root" which is in the "Paths and Directories" section (see below) change it to doc_root = "c:/webroot"
(note the use of back slashes NOT forward slashes)

4. Just below "doc_root" you will find "extension_dir" change this to extension_dir = "c:/php"
(see below)



5. Save and close the file

6. MOVE this file to the c:/WINNT directory

Installation of PHP is now done


Testing PHP is Working


1. Create a PHP file in c:/webroot and call it test.php

2.Place the following in the PHP file



Welcome



echo "Hello PHP world!
";
phpinfo();
?>





3. Restart Apache by opening the Apache Services Monitor (double clicking the magnifying glass icon in the system tray) and pressing restart.

4. Open a browser and type in http://localhost/test.php

5. If the see the following, PHP is working.




Installing MySQL


Installing MySQL is the simplest of all of the installations here and has a simple installer program.

1. Extract the downloaded mysql-4.0.15-win.zip
2. Double click on setup.exe
3. Click Next
4. Click Next
5. Click Next on the destination folder screen, unless you wish to change from the default c:/mysql directory which is not recommended.
6. Choose Typical from the Setup type screen and click Next, the install will begin.
7. Click Finish



Configuring MySQL


There is very little configuration required at this stage

1. Double click the winmysqladmin.exe file from c:/MySQL/bin


2. You will be asked for a username and password


3. Enter "root" (no quotes) and give a password

4. Click OK

4. WinMySQLAdmin will appear as a traffic light icon in your system tray and is added to the start menu automatically so that it starts whenever you login. The MySQL database is also added and set to start automatically.




5. The MySQL Database Server engine is now installed.


Installing MySQL Command Centre


The MySQL command centre is a free Administration utility to mange the MySQL environment and although not essential and is currently only in beta and therefore relatively unstable is difficult to do without.

1. Extract the distribution ZIP file (mysqlcc-0.9.3-win32.zip) to a temporary directory.

2. Double click setup



3. Choose "I Accept" and click Next
4. Click next
5. Destination folder is your choice, the destination folder is not important. Click Next.
6. Click Next
7. Next to install
8. Finish


Configuring MySQL Control Centre


1. Launch the MySQLCC from the programs menu



2. The first time you run the program it will prompt you for the name, server name, user name and password. You must enter this information as the example below, DO NOT ENTER A PASSWORD. We will be setting up a password in a moment. If you do enter a password you will get an error when trying to open the MySQL Database Server, as with screen shot below.




3. When you successfully open MySQLCC you should be able to see the following. under user administration you need to set the permissions and passwords for the administration account. Click root@localhost and choose Edit user.



4. Set the password for this user and tick ALL of the databases it has access to.
5. Right Click MySQL and choose disconnect
6. right Click again and Choose Edit
7. This time in the password box, type the same password you just assigned to root@localhost
8 Click Apply
9. Right Click MySQL icon and choose Connect, you should now have secured the MySQL Database Server with an admin account and password.



10. Remove all other default accounts other than root@localhost by right clicking them one by one and choosing "Delete User". You should be left with just one account.



MySQL is now installed. Any scripts will need to have the admin user name and password in them or you can create other user accounts with specific access to specific databases.


Testing the setup


To test the setup I have created a PHP script which will run via Apache and create a database and table in MySQL, if this is successful everything works fine and you should see a new database and table in MySQLCC.



Save the following in a text file called testmysql.php, don;t forget to edit the code and replace "YOUR_PASSWORD" with your actual root password.




Welcome to PHP/MySQL Test @ notestips.com



$connection = mysql_connect("localhost","root","YOUR_PASSWORD");

if (!$connection){
echo mysql_errno().": ".mysql_error()."
";
exit;
}

if(mysql_select_db("NOTESTIPS_TEST")){
echo("Database NOTESTIPS_TEST already exists
");
mysql_query("DROP DATABASE NOTESTIPS_TEST");
echo("Database NOTESTIPS_TEST removed
");
}


if (mysql_create_db("NOTESTIPS_TEST")){
echo("Database NOTESTIPS_TEST created
");
}

mysql_query("CREATE TABLE person (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id),
firstname VARCHAR(25),
lastname VARCHAR(25))"

);

echo("Database TABLE person created
");



mysql_query("INSERT INTO person (firstname, lastname) VALUES ('Mike', 'Golding')");
mysql_query("INSERT INTO person (firstname, lastname) VALUES ('John', 'Smith')");

echo("TABLE person rows inserted
");
echo("Retriving Rows

");



//RETURN RESULT
$result = mysql_query ("SELECT * FROM person");

// fetch the current row into the array $row
while ($row = mysql_fetch_row($result))
{
// print the values of the attributes
for ($i=0; $iecho $row[$i] . " ";
echo "
";
}


mysql_close();
?>


© Mike Golding 2003






Expected Result





Configuring Apache and Domino


The approach here is to use two HTTP stacks, one for Apache and one for Domino, each running on a different port. Apache will be the "default" server running on port 80 and Domino will run on a different port, in this example I have used port 81.

Firstly we need to change the Domino server to run on Port 81.

1. Open the NAB
2. Open the server document for the server running the HTTP task.
3. Ports/Internet ports
4. Set TCP/IP port number
5. Save and close the server document
6. Restart the HTTP task (tell http restart)




The plan is to use Apache to field requests from browsers and pass the requires for Domino pages over to Domino on port 81. Apache knows nothing about Domino or NSF files etc. so we need to specifically configure Apache to pass any requests for Domino information to another port. For this we need to edit httpd.conf file again.

1. Edit httpd.conf
2. Add the following lines to the end of the file


LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so

RewriteEngine on
RewriteRule ^(.*).nsf(.*) http://localhost:81$1.nsf$2 [P]

3. Save the file
4. Restart Apache
5. Test this by accessing a database such as the example below. The database will be opened.




In this configuration Port 81 can be blocked on your firewall as traffic to port 81 is only carried internally to the server. However this configuration has problems if you want to use it for more than Read Only pages. When you authenticate with the Domino server the server returns you to the URL it authenticated you with, which is the URL that was passed from Apache, which results in the browser displaying the internal port after login (see below), of course if this port is blocked by your firewall you will get a 404, however, as you are now authenticated with Domino we can remove the :81 from the URL (the blocked port) and the page will display fine. This is because at this point Domino is simply serving the page and not authenticating you. This behaviour is "as expected" and Apache has a method of dealing with such returning URLs. For more detail move on to the "Advanced" configuration below.




Advanced Apache and Domino Configuration for Authentication


Apache supports a system known as reverse proxy which takes care of any redirects to the "internal" URL and modifies any responses from the "internal" server so that any URL modifications are reversed (done in reverse order) on the way back to the browser.

N.B. Any settings here should overwrite any settings added from the previous example.


1. Edit httpd.conf
2. Add the following lines to the end of the file

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so

RewriteEngine on

RewriteRule /(.*).nsf(.*) http://localhost:81/$1.nsf$2 [P]
ProxyPass /example1/ http://localhost:81/example1/
ProxyPassReverse /example1/ http://localhost:81/example1/
ProxyPass /example2/ http://localhost:81/example2/
ProxyPassReverse /example2/ http://localhost:81/example2/

3. Save the file
4. Restart Apache
5. Test

You will notice when you do the same test this time around that port is not displayed in the browser as Apache has taken care of the necessary translations to the URLs returned by Domino. The Domino box is now completely hidden from the outside world.

You may notice that in this configuration the ProxyPase and ProxyPassReverse specify example1 and example2, these are directories where databases exist. So each directory you wish to access needs to be listed separately.



Dealing with URLs containing replicaIDs


It might be common that you have a database that is accessed via it's Replica ID or has elements within it that are referenced by ReplicaID. If so Apache will not know it is dealing with a Domino database and think it is opening a file in a directory which does not exist, so you get a 404.



In order to deal with this we have to tell Apache that the weird string of numbers and letters is not a directory. There is no easy way to do this other than add rules for each RepID we want to be able to access, so we have to add the following lines to the httpd.conf file.

RewriteRule /(.*)80256DB2007EC40D(.*) http://localhost:8080/$180256DB2007EC40D$2 [P]
ProxyPass /80256DB2007EC40D/ http://localhost:8080/80256DB2007EC40D/
ProxyPassReverse /80256DB2007EC40D/ http://localhost:8080/80256DB2007EC40D/

Restart Apache and refresh the browsers and the database will load as expected.




End


References


ModRewrite Documentation
http://httpd.apache.org/docs/mod/mod_rewrite.html

Proxy Pass Documentation
http://httpd.apache.org/docs/mod/mod_proxy.html#proxypass

Secure remote data access for Domino
http://www-106.ibm.com/developerworks/web/library/wa-secdomdat/

Port forwarding in apache
http://www.experts-exchange.com/Web/Application_Servers/Q_20709603.html


Mike Golding

Discussion Thread | Add a Comment

:: Configuring Apache, PHP, MySQL and Domino for Wind... ::

. . Yet another great article (Justin Freeman 02/10/2003 22:16)

. . Using Virutal Hosts (Steven Algieri 03/10/2003 08:48)

. . PHP as CGI (Marcin 03/10/2003 00:44)

. . Cool article, but I miss a little bit Tomcat or so... (Ingo Beyer 02/10/2003 07:52)

. . . . Tomcat (Mike Golding 02/10/2003 10:04)

. . . . Tomcat (Marcin 03/10/2003 00:37)

. . Good instructions (Dom 14/10/2003 11:36)

. . Article follow-up Notes (SpzToid 09/11/2003 15:21)

. . . . Also... .PHP scripts from Virtual Directory? (SpzToid 11/11/2003 09:56)

. . Works a treat (Dave Meehan 20/10/2003 17:18)

. . . . Good News (Mike Golding 20/10/2003 17:31)

. . Problems with domblog application (Patrick Kwinten 21/10/2003 16:12)

. . . . replaces ip address into localhost... (Patrick Kwinten 21/10/2003 16:17)

. . . . . . found it (Patrick Kwinten 21/10/2003 16:29)

. . /domjava, action bars and outlines (Keith Strickland 29/03/2004 23:10)

. . . . /domjava applet solution (RaKi 10/07 17:54)

. . Thanks! (Robert Kosa 12/04/2004 09:36)

. . MySQL Testing the setup (Rolf Pfotenhauer 10/11/2004 23:32)

. . Call to undefined function mysql_connect() (azhar 24/10/2004 06:19)

. . . . Some solutions at ... (Luc 11/11/2004 19:22)

. . . . Call to undefined function mysql_connect() by azha... (xu_z 08/01 01:18)

. . . . Fix for the mysql_connect error (Sunnybaba 14/06 08:19)

. . Thank you (Vlad 23/10/2004 17:51)

. . Database as homepage (Sean McKendall 05/02 19:34)

. . . . Apache2 serving nsf homepage (Bill McCuistion 15/04 21:56)

. . . . . . Apache + NSF homepage (Dave Lehman 08/06 22:19)

. . THANK YOU! (Stefan Hägglund 15/05 17:37)

. . Thank You (Manikandan 28/06 11:47)

. . reverse proxy (santhosh 01/07 08:51)

. . Great help (Ricardo Mano 08/03 15:25)

. . . . UPDATE to PHP 5.0.x (Miguel Angel Calvo 27/07 13:36)

. . php script (anat 18/08 07:35)

. . Thank You (Richard 22/09 00:01)

你可能感兴趣的:(Lotus,Notes,apache,mysql,php,windows,database,server)