![]() |
Site Archive (Complete) | |||
|
ABOUT US |
CONTACT |
ADVERTISE |
SUBSCRIBE |
SOURCE CODE |
CURRENT PRINT ISSUE |
NEWSLETTERS
|
RESOURCES
|
BLOGS
|
PODCASTS
|
CAREERS
|
||||
January 01, 2002
Installing PHP/Apache on Your Win98/NT Machine
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:
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.
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.nameChange this to read: ServerName localhostAfter making this modification, save and close this file. Now it's time to start the server! If your platform is Windows 98:
http://localhost/. You should see a default installation page similar to the following:
Installing PHPOk, 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":
Back to httpd.confRemember 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.exeOkay, 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.phpsThe 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:
The php.ini FileMany of the configuration options that you saw when you executed "hello.php" are found within the php.ini file that you placed within theC:\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/offWhen 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 code2. max_execution_time = integerMax_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 noticesAlternatively, 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
4.
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 DirectivesThis 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 RouteAlthough 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.
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|