PHP as Apache module

This simple extract shows how to run PHP as an Apache module on windows with just 4 lines of code. PHP configuration will be covered in another article. You will need the following set up to try this at home.

Requirements:

  • Windows 2000 or XP
  • Administrator access on said Operating System
  • Apache 2.0x
  • PHP, any version (4x +) but not the installer package


Steps:

  • Download Apache web server for windows (2.0.59 recommended)
  • Follow the default installation steps
  • Download the PHP binaries for Windows
  • Extract all the files into a folder of your choice


Once these tasks have been completed you should have Apache running as a service and all files will be located in X:\Program Files\Apache Group\Apache2 - X being your default hard drive.

You can really extract PHP to any location you wish, but in this example I have extracted php-5.2.0-Win32 to the following directory: X:\Program Files\Apache Group\php\php-5.2.0-Win32.

Next step is to open up your httpd.conf file in a text editor, wordpad or notepad, and add a few lines. The file, from the default installation is found in the X:\Program Files\Apache Group\Apache2\conf folder.

Do a search from "LoadModule" and you will see a list of modules that Apache tries to initiate when starting up. At the foot of this section, add the following 4 derivatives - each on a separate line: LoadModule; PHPIniDir; AddType; second AddType.

LoadModule php5_module "X:/Program Files/Apache Group/php/php-5.2.0-Win32/php5apache2.dll"
PHPIniDir "X:/Program Files/Apache Group/php/php-5.2.0-Win32"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

That's it. Left-click the Apache monitor icon that should be in your task-bar and press restart. You can create a php page to test if the installation has worked. Save the following as info.php in your X:\Program Files\Apache Group\Apache2\htdocs folder assuming you haven't modified your document root.

<?php
phpinfo();

Open up http://localhost/info.php in your favorite web browser. You should now see your PHP information nicely displayed on screen. You will notice some irregularities on the page, but that will be covered in the next article.

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br />
  • Lines and paragraphs break automatically.