One of the most commonly asked questions on the PHP3 mailing list is "How do I set up PHP on my Windows machine?" Well, hopefully, I can help answer this question. When done properly, using Windows to develop PHP3 sites can be very advantageous. This tutorial is meant to show you how to use Apache and Windows for developing. It in no way tries to show how to set up a production web server using Windows and Apache.
Installing Apache
First you need a web server. I recommend Apache. I know they say it is not entirely stable on Windows, but really what Windows app is? It is the easiest to set up and can do some neat things with virtual directories to make your life easier. So, go to http://www.apache.org/dist/ and get the latest Win32 build. There is a link at the top of the page for world wide mirrors. Mirrors are good, use them. The file will be called something like apache_1_3_6_win32.exe. Download that and run it. Apache has done a good job on their installation. It is very easy. It will ask you for an install directory. don't make it too hard to get to, because you will want to play with your configuration files and drilling down through 5 folders is no fun. For this example, I will use 'c:\apache'. Assuming you get no errors during install, Apache is probably ready. You will want to read the readme files. There are several. There is one for Win32 specifically which is somewhat misnamed readme-NT.txt. It applies to both Windows 9* and NT.
Installing PHP3
Ok, if you search the PHP3 mailing list on this you may get confused. First you need to install the latest PHP for windows. If you want you can compile PHP on windows, but I will not cover that as it is not necessary for a simple development workstation. Go to your favorite PHP mirror and go to the downloads section. Select 'Source code and Windows distribution'. The direct URL is http://your.mirror/download-php.php3. Download the 'Windows binary'. It is my understanding that the PHP3 guys are working on a better install. However, for now you will have to simply unzip the zip file. Unzip the file to a directory of your choice. For this we will use 'c:\php306'. I recommend using the version number in the folder name. This will enable you to try new versions without killing an old working one.
Setting Up PHP3
There is a readme that comes with PHP3 on doing this. I will however walk through it here as well. There is a file called php3.ini-dist that came in the zip file. Copy that file to your 'windows' or 'winnt' folder. Rename it php3.ini. You will need to edit this file. The main thing is to load any modules that you want to use in PHP3 such as mysql. To do this, find the section in the .ini file that reads like:

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; if you wish to have an extension loaded automatically, use the
; following syntax:  extension=modulename.extension
; for example, on windows,
; extension=msql.dll
; or under UNIX,
; extension=msql.so

Following that will be several commented out lines. For example:


;Windows Extensions
;extension=php3_mysql.dll
;extension=php3_nsmail.dll
;extension=php3_calendar.dll
;extension=php3_dbase.dll


More than likely, all you need to do is uncomment the ones that you need. In my case, I needed mysql enabled. So, I removed the ; from the line ;extension=php3_mysql.dll. If for some reason there is a dll that you need to load that is not listed, simply put it in here like:

extension=mydll.dll

Ok, so PHP3 is now ready to go.
Setting Up Apache To Use PHP3
Remember I told you that you would need to get to the folder where you installed Apache? Well, it is now time. Open up your favorite text editor. The open the file called httpd.conf. It will be in the conf folder under the folder in which you installed Apache. In our case it will be at 'c:\apache\conf\httpd.conf'. For a full determination of what all this stuff does, see the Apache documentation. You need to add 3 lines to this file:

ScriptAlias /php3/ "c:/php306/"
Action application/x-httpd-php3 "/php3/php.exe"
AddType application/x-httpd-php3 .php3

You can copy and paste the last two. In the first one you will need to put the actual path to the folder where you installed PHP3. Save this file and you are ready to try it out.
Running Apache on NT
If you are on NT you will want to install Apache as a service. To do this select Start, Programs, Apache, Install Apache As Service. Now Apache can be started and stopped using the 'Services' Control Panel Applet. Unless you have a good reason, I would suggest setting this to be started manually. To do this go to Control Panel and select Services. Select the Apache service and click 'Startup'. Set 'Start Up Type' to 'Manual'. This will make you have to start Apache when you need it. The good thing is that it will shut down when NT does. You will not see any Apache windows with this setup.
Running Apache on Windows 9x
If you are using Windows 9x, I would suggest downloading the Apache Manager for Windows from my website (http://brian.threadnet.com/apmgr.html). It stays in the system tray and hides all the console windows that Apache creates. It will allow you to start, stop and restart Apache without worrying about command line mess. If you do not want to use Apache Manager, you can start Apache by selecting Start, Programs, Apache Web Server, Apache Server. This will create a console (MS-DOS) window. DO NOT CLOSE THIS WINDOW. To stop Apache you will need to open an MS-DOS window, switch to your Apache folder ('c:\apache') and type:
apache -k shutdown
It may take a moment for the Apache console window to close. This ensures a proper shutdown of all all the threads and properly closes all the .conf and .log files. Now you know why I wrote Apache Manager.
Testing The System
I do recommend you to run the console version of Apache at least once to be sure all is running well. The only way to get output from Apache is through the console window or the error.log file. The error log can be found under the logs folder in the Apache install folder. In our case 'c:\apache\logs\error.log'.
Ok, start Apache by selecting Start, Programs, Apache Web Server, Apache Server. If all is ok, you will see something like the following in the console window:

Apache/1.3.4 (Win32) running...

If you do not see that and the window disappears quickly you will need to run it from an MS-DOS window. You will need to open an MS-DOS window, switch to your Apache folder ('c:\apache') and type 'apache'. See what error message is given. If it a parse error in the conf file, you will need to correct it by editing httpd.conf and running Apache again.
So, now it is all running. To test your system, open a browser and type: http://localhost/. You should see a page from Apache congratulating you. If you do not, one thing to check is that you have a file in your windows directory called hosts.sam. If it is not there, create it. In that file put:

localhost 127.0.0.1
Now, let's try a PHP3 file. With your favorite text editor, create a file called phpinfo.php3 and put it in your htdocs folder in the Apache install folder ('c:\apache\htdocs\'). In that file put:

<?php 
phpinfo
(); 
?>

Now point your browser at http://localhost/phpinfo.php3. You should see a big table of information on PHP3 and its settings. If you do not, something is not done correctly. Be sure you have entered the lines into the conf file correctly.
Using Directory Aliases
You do not need to go moving all your stuff under the htdocs folder. If you are like me, you have a very picky way that all of your web files are laid out on your hard drive. To get Apache to point at that stuff, you need to use the Alias directive in your httpd.conf file. This is neat, but simple. All you need to do is enter something like:

Alias /mysite/ "C:/path/to/my/web/files/"

Now to have Apache server up those files, point your browser to http://localhost/mysite/. Of course you can replace 'mysite' and that path with what ever you want. So, now instead of having to move all your files, you can simply create a link to that URL and view your files that way.
A Tip For Homesite Users
This is a little off topic, but is one of the nicest features I have seen. With Homesite (I use 4.0) from Allaire you can map directories to URLs. Example. While in Homesite, select Options, Settings. Select the Browse tab. At the bottom of the dialog there is a section for server mappings. Select 'Add'. Type or browse to the path where your web files are (this is the same as the path in the Alias directive). Then enter the URL path for that mapping ('http://localhost/mysite/'). Now hit OK and OK again. Now when you click browse or launch external browsers from Homesite it will map it through Apache.
There may be other editors that will do this. If you are aware of any, let me know and I will add them to the tutorial.

A Tip For Database Users
All this is fine and good if all you do is put together pages with PHP. But what if you need to access a database, such as MySQL, that is on a server on the internet somewhere. Well, if you have remote connections allowed, you can connect to them from your local box. I created a single file to include in all my MySQL operations to handle connecting to the database. It looks like this:

<?php

if (!defined"_DB_INI" ) ) {

  
define("_DB_INI");

  
$dbName "brian";

  if (!
strstr($HTTP_HOST"brian.threadnet.com")) {
    
$dbUser "brian";
    
$dbServer "brian.threadnet.com";
    
$dbPass "password";
  } else {
    
$dbUser "brian";
    
$dbServer "";
    
$dbPass "password";
  }
  
$dbConn mysql_pconnect($dbServer$dbUser$dbPass);
}

?>

As you can see, I have a section of connecting locally (files on the server) and remotely (files on my machine). This allows me to have different passwords or even usernames for connecting locally and remotely. So, now I can develop with database connectivity and still not have to upload to the server.
Well, that should get you going. Using Windows as a development environment can be very nice. It seems some think it is a sin to use Open Source software on the Windows platform. Don't listen to them.
--Brian