This tutorial is going to walk you through the basic setups of Apache HTTP Server (web server) and PHP on a Windows workstation/server. The installations will utilize the automatic installation and configuration of Apache, using the MSI executable, and the manual installation of PHP. The versions of Apache and PHP given in this tutorial are the latest stable releases as of this writing.
Installing Apache 2.0.55The first thing we are going to do is install the Apache HTTP Server. On the Apache HTTP Server home page, under the heading Apache 2.0.55 Released, click the Download link (or use the one provided here). The download page has all the versions available but we are only concerned with the latest stable release (2.0.55). Click the link located next to Win32 Binary (MSI Installer) to download the executable that will install the Apache Web Server. The file name is apache_2.0.55-win32-x86-no_ssl.msi and it is approximately 4.3 MB in size.
*Note: Apache 2.0 is designed for Windows NT, 2000, XP and Windows Server 2003. Running Apache on a Windows 9x computer is possible but it is neither recommeded nor tested.
Once the file has finished downloading, browse to the directory (folder) to which you saved the file. Double-click the file to begin the installation.
- Click Next on the first screen to be taken to the Agreement. Choose I accept the terms of this license agreement and click Next.
- Read through the information in the Read this first window and then click Next.
- The Network Domain and Server Name will be populated with information located from your computer. The Administrator's Email Address is populated by adding admin@ to the front of the Network Domain Name. You can leave this to it's default if this is just going to be a local development machine. Otherwise, you will need to modify this information to fit your particular location.
- If you want the Apache Web Server to run as a service, leave the radio button ticked next to for All Users, on Port 80, as a Service under Install Apache HTTP Server 2.0 programs and shortcuts for. Otherwise, click the radio button next to only for the Current user, on Port 8080, when started Manually. Shortcuts are created to start the Apache server manually.
- Click Next to be taken to the Setup Type window. The Typical setup type is ok to use and will setup the main components of Apache for you. Click Next.
- The default destination folder for installation is C:\Program Files\Apache Group\. Unless you have space concerns, and want to install to another drive, click Next. If you want to install to a different directory, click the Change button and browse to the directory into which you want to install the Apache HTTP Server program files.
- This tutorial assumes that you are installing Apache into the C:\Program Files\Apache Group\ directory.
- Click the Install button to begin the installation using the settings you provided in the previous screens.
- Click the Finish button on the Installation Wizard Completed screen.
To see if Apache is working, open your web browser and type http://localhost for the web address. You should see the default Apache Web Server page with the words If you can see this, it means that the installation of the Apache web server software on this system was successful. You may now add content to this directory and replace this page.. If you see the default page, congratulations, the Apache HTTP Server is now installed and running on your computer!
Installing and configuring PHP 5.0.5Manually installing PHP can be tricky but it is easier than some may think. This manual installation and configuration will setup PHP to run as an ISAPI module instead of as a CGI binary. Why should it be done like that? Directly from the PHP user guide:
By using the CGI setup, your server is open to several possible attacks. Please read our CGI security section to learn how to defend yourself from those attacks.You can secure the CGI setup but this tutorial is for a beginner. Security settings for CGI are considered to be more of an intermediate or advanced level. The ISAPI setup will work fine for most of your development needs unless you are sepcifically wanting to develop CGI scripts to run on your web site.
Downloading PHP is easy. Visit the PHP downloads page and look under the heading Windows Binaries for the PHP 5.0.5 zip package link. The file is approximately 7.8 MB in size. The zip package includes all the extensions whereas the executable package does not. Also, the executable install does not configure PHP for use with Apache 2.0.
Once the file has completed downloading, unzip it to C:\PHP. You may have to direct your zip program to create the directory. Inside this directory, you will find a file called php.ini-recommended. Copy this file to your root Windows directory (C:\WINNT or C:\Windows) and rename it to php.ini. Open the INI file and make the following changes:
- doc_root: "C:\Program Files\Apache Group\Apache2\htdocs"
- This sets the document root directory to the location of your web pages. On a default install, Apache reads the htdocs folder when serving web page request.
- extension_dir: "C:\PHP\ext"
- Extensions are used to add aditional functionality to the PHP parser. You enable extensions further down in the php.ini file by removing the semi-colon (;) from the beginning of the line containing the extension you wish to enable (under the section heading Dynamic Extensions).
- Save your changes.
One step that is optional, but helps if you upgrade PHP in the future, is to add the PHP directory to your Windows PATH settings. This is done by going into the Windows Environmental Variables and double-clicking on Path (located under System Variables). Go to the end of the line and type in C:\PHP; (include the semi-colon) after the last semi-colon.
Now, we must configure Apache and point it to the location of the PHP program files. Note that the directory paths in the Apache configuration file use the forward slash (/) instead of the back slash (\). Apache was originally designed for *nix systems and directory paths in *nix use the forward slash. Even on a Windows system, the forward slash must be used in the directory paths or Apache will not read the directory structure correctly.
Browse to the C:\Program Files\Apache Group\Apache2\conf directory and open the httpd.conf file (Notepad works fine). Look (search) for the Dynamic Shared Object (DSO) Support section and add the following line to the end:
LoadModule php5_module "c:/php/php5apache2.dll"Look for the following line:
#AddType application/x-tar .tgzPut your cursor at the end of the line and hit Enter (or Return) to drop to the next line. Enter the following:
AddType application/x-httpd-php .phpGo to the bottom of the httpd.conf file and add the following:
PHPIniDir "C:/Windows"
The last setting points Apache to look in your Windows directory and read the PHP settings from the INI file located there. Be sure that none of the lines you entered begin with a pound (#) sign. The pound sign is used to tell Apache to ignore that configuration line.
After all the changes have been made, you must stop and restart the Apache server.
Testing out your Apache HTTP Server
Now that everything appears to be setup, let's test out the server to see if it will parse PHP pages correctly. Open Notepad (or a text editor of your choice) and type in the following line:
<?php phpinfo() ?>
Save the file into the Apache htdocs directory (C:\Program Files\Apache Group\Apache2\htdocs) as phpinfo.php. Open your web browser of choice and type http://localhost/phpinfo.php for the web address. If everything is setup correctly, you will be given a page showing the complete PHP configuration for your system. The information will include what version of PHP you are using, system name, Apache environment settings, etc. If you get a page just showing the phpinfo string, the file was not parsed correctly and you will need to go back and check all the settings you changed for Apache.
More advanced configuration options for Apache can be found on the Apache HTTP Server 2.0 Documentation site. Advanced configuration options for PHP can be found on the PHP Manual site.
Tech Articles