Site Archive (Complete)
Architecture & Design
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
January 01, 2002
Installing PHP/Apache on Your Win98/NT Machine

WebReview.com: Installing PHP/Apache on Your Win98/NT Machine

Rank: 3

Helpful Resources

There are several useful online resources regarding the PHP/Apache Windows installation process. Take a moment to check out some of them.

Using Apache with Microsoft Windows

PHP Configuration

PHP Installation on Windows

Remember back in the good old days when Web site development was easy? Just code some HTML, load it into your browser, and continue tweaking it until it looks good. Then scripting languages like PHP and Perl popped into the picture, forcing those of us doing our coding on Windows machines to actually have to FTP the pages up to the server before viewing the latest changes. Oftentimes, this was the most tedious part of the development process: Modify the page, switch to the FTP application, upload the file, wait for the upload to complete, back to the browser, reload, sigh.

Fret no more, distraught Windows developers. Today I'm going to show you how to install Apache and PHP on your very own Windows 98/NT machine, eliminating the need for constant FTPing when testing your scripts! The process is actually rather simple, and takes less than 15 minutes to complete.

Downloading the Necessary Files

Let's begin by downloading the necessary applications. You'll only need two, the Apache and PHP Win32 binaries. These can be found at their respective sites:

Your download time will vary in accordance with your connection speed. Download the distributions to wherever you wish. I generally create a folder on my desktop and download the files there. If you're unfortunate enough to run on a slow connection, go fix yourself a nice lemonade, and play a game of solitaire while you're waiting.

Installing Apache

Okay, I assume that the downloads have completed, and you're ready to continue. The Apache distribution is an executable installation format, so just go ahead and click on the icon. A few things will load, and the installation process will begin. I'll guide you through this process, step-by-step:

  1. You'll be greeted with a Welcome screen. Go ahead and click Next.
  2. You'll then be prompted with the Apache licensing agreement. Take a moment to read through that and click Yes.
  3. Next up is a warning message, informing you of possible security holes within the Windows release. Again, click Next.
  4. Your next screen will be the prompt for the destination installation folder. The default is C:\Program Files\Apache Group\Apache. I personally use this one, but you can change it to whatever you wish.
  5. Next (you're almost finished), you'll be prompted for the type of setup: Typical, Compact, or Custom. This time around, just go with the Typical. It installs everything you will need for proper functioning of the server as it pertains to this article.
  6. Finally, you will be prompted for the program folder name that will appear within the start menu. The default is Apache. Again, choose whatever you wish.

After making these choices, the installation process will begin. When it's completed, you will be prompted to view the Readme file. Check it out if you'd like, or just click Finish.

What is a service?

A service is Window's NT terminology for a process (daemon for you UNIX people). An NT service is an application that runs in the background, executing specified operations at predefined times and in response to particular actions. When a program runs as a service, it will be started automatically every time NT boots.

Now it's time to configure the freshly-installed Apache server. Start your favorite text-editor and open up the file named httpd.conf, found in the conf folder, which is located within the Apache installation directory. If you used the default installation directory in Step 4 of the process, that directory would be "C:\Program Files\Apache Group\Apache\conf\". For testing purposes, there is really only one modification you need to make:

Locate the line:

#ServerName new.host.name
Change this to read:

ServerName localhost
After making this modification, save and close this file. Now it's time to start the server!

If your platform is Windows 98:

  • Go to the Start Menu > Apache, and choose Start Apache. A DOS-style console window will open. Do not close this window!
If your platform is Windows NT:

  • Go to the Start Menu > Apache, and choose Install Apache as a service.
  • Now go to the Services window found within the Control Panel. Select Apache and click the Start button.
Open up your favorite browser, and type http://localhost/. You should see a default installation page similar to the following:

successful install of apache
Figure 1: Successful installation!
If you see that picture, your installation was successfully completed! If by some unknown act of nature you don't see this page, then something has gone awry. I would suggest repeating the process. Check out the Apache documentation for the Windows platform. Also take a moment to read through the general Apache documentation. If you still can't get it working, email me.

Installing PHP

Ok, we're halfway there. Now let's turn our attention to installing and configuring PHP. You'll need to decompress the PHP file, as it is zipped up. I can't imagine that you don't already have some sort of decompression program, but if you don't, I would suggest Winzip. Unzip the file to some directory, "C:\php", for example.

There are three files of importance within this directory: "php.ini-dist", "Msvcrt.dll", and "php4ts.dll":

  • Take these two files ("Msvcrt.dll" and "php4ts.dll") and put them into the folder "C:\WINDOWS\SYSTEM\".
  • Return to the directory "C:\php\"..
  • Copy the file "php.ini-dist" to "C:\WINDOWS\". Rename this file to "php.ini".

Back to httpd.conf

Remember the httpd.conf file that you modified earlier on? Go ahead and open it back up, as there are just a few more modifications that need to be made.

Locate the line:

ScriptAlias /cgi-bin/ "C:/program files/Apache 
Group/Apache/cgi-bin/". 
Go to the line following it and insert this:

ScriptAlias /php/ "C:/php/"
Now locate the line:






Go to the line following it and insert this:

Action application/x-httpd-php /php4/php.exe
Okay, one last modification to make. Find the line:






Go to the line following it and insert these lines:

AddType application/x-httpd-php.php
AddType application/x-httpd-php-source.phps
The first line declares the valid extensions for any PHP scripts. The extension ".php" is the typical extension, although you could change it to anything you want. The second line declares the extension that will allow you to view the PHP code within the browser. This is a pretty cool feature of PHP and can be used for learning or debugging purposes.

Guess what? You're finished! Pat yourself on the back, fix another lemonade, and prepare to have some fun with your very own in-house server! Open your text editor once again and create a file named "hello.php." Enter this text within the file:

<?


phpinfo();


?>
Save this file to "C:/program files/Apache Group/Apache/htdocs/". In order for these changes to be recognized by the Apache server, you need to restart it. Just go back to the Start menu, click on Stop Apache. After a moment the console window will disappear. Go back to the Start menu, this time clicking upon Start Apache. Now for the big moment. Go back to your Web browser and enter: http://localhost/hello.php. You will be greeted with a rather lengthy list of configuration settings, beginning with something very similar to Figure 2:

php configuration info
Figure 2: PHP Configuration Information

The php.ini File

Many of the configuration options that you saw when you executed "hello.php" are found within the php.ini file that you placed within the C:\WINDOWS\ directory during the PHP installation process. If you are using your new server for mere testing purposes, then chances are the php.ini file will not be that much of an issue. But you may find that there are several configuration issues that you should be aware of, and could aid in the efficiency and timeliness of your development process. Although reviewing the entire php.ini file is a little extensive for this tutorial, let's take a moment to check out some of the configuration options that are particularly important. If you would like to open the php.ini file and follow along as I introduce a few of the options, feel free to do so now.

The options are introduced in the order that they appear within the php.ini file.

1. short_open_tag = on/off

When short_open_tag is enabled (set to on), you can use what are known as PHP's short tags to escape to PHP within a Web document. These are the short tags:


<?
// some PHP code
?>
If short_open_tag is disabled (set to off), then only two other escape tags will be recognized. Examples of these tags include:

<?php
// some PHP code
?>


<script language="php">
// some PHP code

 
2. max_execution_time = integer

Max_execution_time determines the number of seconds that a script can run before timing out.

3. error_reporting = string/integer

Error_reporting determines the level of sensitivity for reporting scripting errors within the browser. There are two ways in which this can be set, either via a string description or via a bit setting.

The default setting is:

error_reporting = E_ALL & ~E_NOTICE ;Show 
all errors except for notices
Alternatively, you could achieve the same results by setting error_reporting as follows:

error_reporting = 7

A complete listing of the differing error reporting settings can be found within the php.ini file, directly above the error_reporting directive. The alternative numeric settings are:

Setting Level of Reporting
1 Normal errors
2 Normal warnings
4 parser errors
7 Normal errors, normal warnings, and parser errors
8 Noncritical style warnings

4. display_errors = on/off

Assuming you are interested in viewing the errors as set by error_reporting, then you will want to turn display_errors on. This will display any resulting errors as HTML output.

Various Database Configuration Directives

This is more of a general categorical summary than a specific configuration directive. PHP provides support for a wide-array of databases, some of the more popular include Oracle, MySQL, PostgresSQL, and Sybase. If you are interested in using a database in conjunction with PHP, you may wish to learn more about the relative configuration directives found within the php.ini file.

The above summary was ever-so brief, and intended to give you just a small taste of the various PHP configuration possibilities. If you are interested in learning more about the php.ini file, take a moment to read through the Configuration section of the PHP manual. The link to the manual is found below in the Further Reading section.

The Most Effective Route

Although arguably Apache and PHP are most effective when implemented on a Linux platform, configuring this combination for developmental use can save Windows-based developers significant amounts of time when building dynamic Web sites. If you have any questions regarding the process illustrated in this tutorial, please contact me. Next time, I will introduce one of Apache's most powerful, and confusing, modules: mod_rewrite.


Jason has been an Internet developer since 1995, and is the author of the upcoming Programmer's Introduction to PHP from APress.

TOP 5 ARTICLES
No Top Articles.
DR. DOBB'S CAREER CENTER
Ready to take that job and shove it? open | close
Search jobs on Dr. Dobb's TechCareers
Function:

Keyword(s):

State:  
  • Post Your Resume
  • Employers Area
  • News & Features
  • Blogs & Forums
  • Career Resources

    Browse By:
    Location | Employer | City
  • Most Recent Posts:



    MICROSITES
    FEATURED TOPIC

    ADDITIONAL TOPICS

    INFO-LINK



     



    Related Sites: DotNetJunkies, SD Expo, SqlJunkies