Published on 2004-09-02 by John Collins. Socials: YouTube - X - Spotify - Amazon Music - Apple Podcast |
Table of Contents
1. Introduction
2. Installing IIS on Windows 2000
2.1 Installation steps
2.2 Enabling support for detecting usernames
3. Installing MySQL 4.1+
3.1 Installation steps
3.2 Understanding the Windows path environment variable
3.3 Securing the root account and removing anonymous accounts
4. Installing PHP 5
4.1 Installation steps
4.2 Working with the php.ini File
4.3 Enabling e-mail support
4.4 Configuring IIS to use PHP
4.5 Enabling MySQL support
4.6 Enabling GD support for graphics
4.7 Placing FPDF on the Include Path for PDF Support
5. Installing PEAR
5.1 Installation steps
5.2 Installing PEAR::DB database API
6. Installing Aspell for spell-check support
6.1 Installing the Aspell program, english dictionary and Pspell PHP extension
7. Download resources
With the recent release of PHP 5.0, many PHP developers might be thinking about upgrading their existing PHP installations to the new standard. Although PHP 5.0 may not be ready yet for a live environment, this tutorial will show you how to build a PHP 5.0 server on Windows that would be suitable for hosting live applications with future builds of PHP 5.x.
In general, a "dot zero" version of a new system has not been tried and tested enough to be considered safe for production servers. With an application as complex as PHP 5.0, it is an absolute certainty that bugs will be found, and corrected promptly, within the coming months. I would expect a 5.0.1 version to be released shortly, which may prove to be stable enough for live servers.
In the following tutorial, I will be working with the following software:
Windows 2000 Professional: I consider this to be the best version of Windows that MS ever produced, I am using SP 3. These instructions should also be appropriate, with some variations for IIS configurations, for Windows XP Pro, Windows 2000 Server and Windows 2003 Server, but not Windows XP Home that is not a proper network enabled operating system, and should be avoided at all costs! Important Note: It is important to realize that IIS on Windows 2000 Pro has built-in 10 user connection maximum limit; as a result you should use Windows 2000 Server for a live server, but Windows 2000 Pro or Windows XP Pro should work fine for a test server.
IIS 5: This comes on the Windows 2K CD; you can also use 5.1 or 6 depending upon which operating system you are using. I am using IIS rather than Apache 2 because IIS allows us to use pass through authentication in our PHP applications (I will cover this in detail later), and generally believe that Apache belongs on Unix/Linux for production servers; while if you must use Windows for a web server, you might as well use IIS too!
MySQL 4.1.3 Beta: As of writing, this is still beta so should not be used on a live server. I have been using it for the last couple of months, and found it to be quite stable; therefore I believe that MySQL 4.1 will be released as an official version soon. 4.1 provides some major improvements over 4.0.x, such as sub queries, so I would recommend this version strongly.
PHP 5.0.0 Win 32: It goes without saying; you should download the Windows version of PHP. I will be doing a manual build, so download the zip package instead, rather than the Windows installer which only provides a basic install of PHP 5.0.
PEAR::DB 1.6.5: I will be using the version of PEAR that comes with PHP 5.0, and downloading and installing DB 1.6.5, the PEAR database abstraction API (I will explain all this later).
Aspell 0.50.3 and Aspell en 0.50.2: This application, along with the relevant English dictionary (other languages are also available), allow us to use spell checking functions in our PHP 5.x applications.
FPDF 1.52: This is the free PDF generating class that we will use in our PHP 5.x applications to generate PDF document on the fly.
If you have never heard of some of these packages, don't worry I will explain each one in turn before I describe how to install them. In general with these installation tutorials, your system and version numbers will not exactly match mine, so there may be different options or steps required to get your configuration up-and-running, but hopefully these guidelines will provide all the instructions you need.
You will find a section of links at the bottom of this page to the download sites for all of the software you need to setup your server. Download the latest versions of everything you need (I estimate about 50 MB in total for all downloads), save them to a local folder on your C drive, then you are ready to begin.
The first thing we need to do is set up IIS from our Windows 2K CD. IIS (Internet Information Service) is Microsoft's equivalent of Apache, a HTTP server that will run on your PC, listening to a network port (by default port 80) on your machine for HTTP requests, and responding to these requests, normally requests for HTML pages, by sending the HTML page to the client machine looking for the data.
You could use Apache 2.x, or some other web server, for this step instead, but I do not discuss Apache sever configuration options at any stage so you might get lost. I use a LAMP (Linux Apache MySQL PHP) test server at home, and Windows IIS servers in work, so am comfortable with either environment. Therefore, I may publish a tutorial on setting up a LAMP server with PHP 5.0 at a later date, which is a radically different process to the one we are about to follow.
Now to test out IIS, start up Internet Explorer and type in http://localhost/ as the site to visit: you should get the default "Welcome to IIS 5.0" web page.
In my experience building Intranet-based PHP applications, I have found that many users prefer systems that can automatically log them in based on their network credentials. Here we are operating on the principal that if they were able to log onto a network workstation, then they must possess a valid username and password. Rather than asking them to login again to our PHP applications, we can grab the client's network credentials, including the NT username, and login the user automatically, a technique often termed "pass-through authentication".
Pass-through authentication is not possible for Internet-based applications; you will still have to use manual logins and session management. For Internet IIS server set-ups, you can ignore the following steps.
Now when any browser attempts to connect to your default website, it must pass its network credentials to the IIS web server, otherwise the connection will be refused. Later on in this tutorial, I will explain to you how you can access the environment variables containing the NT username in you PHP scripts.
Now that we have a functioning web server installed, we will install the next major component, our MySQL database server. The database server works on a similar principal to the HTTP server; that is it runs on Windows as a background service, while listening on a network port for SQL requests for data, then serving up the results of those queries to the clients that requested them.
As I stated above, I believe it is safe to start using MySQL 4.1.x at this stage, as I do not believe it will remain a beta (test) release for much longer. Installing MySQL is a simple process on Windows, follow the steps below.
Start a DOS prompt, and type C:\mysql\bin\mysql. You should get the following screen:
At the MySQL prompt, type show databases; and press return. By default, you will only have two databases to begin with. Now type exit and return to exit the MySQL client.
Rather than having to type C:\mysql\bin\mysql, it would be nicer to simply have to type mysql like any other DOS command. We can do this by adding the C:\mysql\bin folder to the Path variable in Windows. Do the following:
When installed, MySQL does not set a password for the MySQL root account, which is the administrator account for the entire system. This account needs to be locked down immediately for security reasons. We will also remove the anonymous user accounts from the default install:
Notice how you did not have to give the full path to the mysqladmin program? That is in the C:\mysql\bin folder also, which is now on the system path. Now we will connect to MySQL as the root user, and remove the anonymous access accounts:
Now when you try to access the server by simply typing mysql and no username and password, you will get an access denied error. You must now use the root account, with the password that you have set.
Installing PHP itself is quite straightforward; the difficulty lies in configuring IIS to use it! There are a number of programs contained within the standard Win 32 distribution, for example it contains two versions of the PHP interpreter that we can use with IIS. The first is a DLL (Dynamic Link Library) that contains an ISAPI module for IIS. This module will run as a persistent interpreter in IIS, one that does not need to be called externally, so in theory should provide the best performance.
In reality, I have found the ISAPI module to be unstable with PHP 5 and IIS on Windows, often causing access violations. These issues will most likely be resolved in time, and may be by the time that you are reading this.
The second version, a standard C executable, is the one that we will be using. This runs under IIS as an external CGI (Common Gateway Interface) call, similar to the way Perl/CGI works, so as a result is not as quick as the ISAPI module, but it is very stable. In the trade-off between speed and stability, we should always favour stability for a live production server.
That's it! Now onto configuring PHP 5.
The C:\PHP\php.ini for is the main configuration file for PHP on our server, so we will be spending quite a bit of time working with this file. Open it up now with a text editor, you will find it to be very well commented and easy to work with. This is a good example of the difference between open source software and commercial software, for example IIS uses a difficult-to-navigate tab-based GUI (Graphical User Interface) to configure the server, while Apache uses a text file similar to the one that PHP uses called httpd.conf. Personally, I like this simple no-nonsense approach.
If you have access to a mail sever, for example an Exchange server, then you can instruct PHP to use this server to send mails from its mail() function. Modify the following lines in your php.ini file to pint to the network address of your mail server, where available:
[mail function] ; For Win32 only. SMTP = mailserver.mydomain.com smtp_port = 25
PHP will now route e-mails from the mail() function to this sever.
Now we need to get IIS using PHP 5 to interpret files with the .php file extension. As stated previously, we will be using the CGI executable version of PHP 5 with IIS for stability reasons.
If everything has been setup correctly, you should get a screen similar to the following one:
If you scroll down on this page, you will see that it details everything about your PHP installation, which is a very useful guide for installation purposes. I will refer back to this page frequently throughout the rest of this tutorial as "the PHP info page"; you can take this to mean http://localhost/info.php in your web browser.
You should also be able to find your username stored in an environment variable on this page, normally in something like $_SERVER["AUTH_USER"] or $_SERVER["LOGON_USER"], which you can access from your PHP scripts (assuming you followed the steps to disable anonymous access in IIS).
There are two separate APIs (Application Programmers Interface) available for MySQL with PHP 5.x. The standard MySQL API is the one that came with PHP 4.x, while the new MySQL Improved API (or mysqli) contains all the new PHP functions for accessing the new features of MySQL 4.1 and above, such as stored procedures that will be introduced in MySQL 5.
To summarize, to support legacy PHP applications, we should install the mysql API, while to support future PHP applications, we should install the new mysqli API. The best solution is to install both.
Reload the PHP info page, and scroll down until you find a section on mysql and another on mysqli.
GD 2.x allows us to build PHP applications that can generate PNG and JPEG images on the fly, and send them to the client's Internet browser. This functionality is particularly useful for generating charts based on data stored in our MySQL database.
To enable GD 2.x support:
Replace the line:
;extension=php_gd2.dll
with
extension=php_gd2.dll
(or add it if it doesn't exist) in the extensions section of the php.ini file.
Reload your PHP info page, you should now see an entry for GD 2.x.
FPDF is a PHP class that allows us to generate PDF documents, which is a great file format for saving documents in, or printing documents from. As with GD, the contents of our PDF files can be based upon the contents of our MySQL database.
FPDF does not need to be installed, it simply needs to be extracted from is zip into a suitable location. The best place to put this is on the include path for PHP.
The include path is the first place that PHP will look in for a file that is included without a location being specified, for example:
include('myfile.php');
When this line of code is executed, PHP will look for myfile.php in the current folder, and in the folder(s) specified in the include path directive in the php.ini file. If it cannot find the file, it will throw an error.
To make FPDF available universally on the server:
Now when you want to use FPDF, all you have to do is use:
require_once('fpdf.php');
...to include the class from anywhere on your server.
PEAR (PHP Extension and Application Repository) is an object-oriented (OO) framework used for the distribution of various classes that can be used freely in your PHP applications. One of the most widely used PEAR extensions is DB, the database-independent abstraction layer that provides a common API for use with all of the major database severs, including Oracle, MySQL, PostgreSQL, MS SQL Server 2000 and many more.
Firstly, we will install the PEAR framework, and then we will install the DB extension. The process for installing the extensions from PEAR are all the same, so here we are using DB as an example.
As with FPDF, you can now use:
require_once('DB.php');
From anywhere to start using PEAR::DB in your code, as C:\PHP\PEAR is now also on your include path (this is where PEAR will install all of its PHP class files).
The Aspell application allows you to use spell checking in your applications. Originally only available for Linux, it has been ported over to Windows and PHP support for it is available through the Pspell DLL extension. Installing the Aspell program and English dictionary are easy as they come as standard Windows setup programs:
Here is a collection of URLs for downloading the packages mentioned in this tutorial. As always with the Internet, I cannot provide any guarantee that all of these sites will remain live, or change location, in time; so a bit of searching on Google may be required to find what you need.
Resource | URL | Description |
---|---|---|
PHP | http://www.php.net/ | The home site for PHP, from here you can access the download section, the online manual, and also keep in touch with other PHP-related news. |
PEAR | http://pear.php.net/ | The PEAR home site, where you can browse and download all of the PEAR packages, as well as access the PEAR manual. |
MySQL | http://www.mysql.com/ | The MySQL home site, which contains all of the downloads for MySQL, including various client GUI tools for your databases, as well as the excellent PDF version of the MySQL reference manual. |
Aspell Win 32 Port | http://aspell.net/win32/ | Here is the Windows port for the Aspell GNU distribution; you can also download all of the language dictionaries from this location. |
FPDF | http://www.fpdf.org/ | The home site for the FPDF project, as well as containing the zip file download, it also has an extensive collection of examples of how to use the class in your PHP code. |
Updated 2020 : note that the above post is out-of-date, given this post was originally published in 2004, but is left here for archival purposes.