Installing and Configuring Apache 2 on a Windows XP Machine

Apache 2 represents quite a change from previous versions. If you have set up a previous version of Apache on a Windows XP PC, you will be interested in setting up the new version. Dan Wellman shows how to set up and configure Apache 2 on a Windows XP PC to give you a development environment that will allow you to test your PHP and other dynamic web technologies before taking them live.

Some time ago, I wrote an article on using Apache on a Windows XP PC in order to set up a development environment in which you could test your PHP and other dynamic web technologies before taking them to the public stage.  Since then, nothing much has changed in the world of web servers and hosting, Linux is still the most popular web OS and Apache is still the most popular (and many would say best) web server in use.   Apache itself however has just changed, or the code for it has anyway; Apache 2 has been completely re-written since the last major release, so I thought an updated article would be in order. 

Since its development in 1995, Apache has gone on to take a massive 69 percent share of the web server market.  The reasons for this are clear; it is fast, reliable, secure (when configured correctly), and open source.  It is continually developed and improved by dedicated professionals around the globe and forms part of the popular LAMP web setup: Linux, Apache, MySql, and PHP.

Apache’s main rival is Microsoft’s Internet Information Services (IIS), and has been since IIS 3 started gaining support back in late 1993.  IIS 6 is bundled with Windows XP Professional, but does not form part of the default install.  The proud owners of Windows XP Home edition may or may not already know that IIS is not included with any install of the OS, default or otherwise.  IIS simply will not run on home edition, therefore anyone that wants to install a web server for development or testing purposes has to look for an alternative to IIS, and Apache is the ideal (and possibly only) candidate.

Some of the updates that form the current release of Apache (2.0) since the last major version (1.3) include: multi-protocol and IPv6 support, multi-language customizable error pages, a new build system and a new API, a simplified configuration scheme and importantly, improved support and performance on non-UNIX systems. 

As I said above, IIS is the only real competitor to Apache at the moment, enjoying a market share of approximately 22 percent.  That doesn’t sound like much compared to Apache’s 69 percent, but it still means literally millions of sites hosted by IIS.  The extended support given to Windows systems is an attempt to prevent that share increasing and consists of a Windows-specific Multi-Processing Module (MPM) and the Apache Portable Runtime (APR).  The MPM is like a module that binds to specific ports on the host OS and accepts requests, but only one runs on the server at any one time to target a specific OS.  The APR is a project in its own right and deals with the creation of platform specific APIs that work in as close a way to each other as possible no matter which host OS the server is running on.

{mospagebreak title=Getting Started}

There is no reason why you cannot implement a WAMP web set up for testing purposes on a development machine.  Yes, Apache is better on a UNIX variant such as LINUX than it is on Windows, but having LINUX is not a pre-requisite to being a web designer.  If you have a Windows machine already, why should you have to either partition your hard drive and install LINUX as part of a dual boot system or use something like VMWare to emulate a similar setup?  The answer is that you don’t.

To begin, you’ll need to install Apache, so go to http://httpd.apache.org and click the download from a mirror link.  This will provide a link to the nearest available download site; the Win32 Binary installer is the quickest and easiest way to get up and running with Apache, being a pre-compiled installation file.  For an installation more tailored to your individual needs, you can download the source files and compile your own installer.

Clearly, installing the server requires nothing more than a double-click and following the on-screen prompts, so I won’t go over this part in too much detail.  You are required to enter your domain name, full server name and administrators email address.  This will all be pre-filled, but you can remove the suggestions and just use ‘localhost’ in the first two and any email address you feel like.  If this is your only web server, select for ‘all users on port 80 as a service.’ 

Unless you are a developer interested in building custom Apache modules, you can safely select the ‘typical’ radio on the next prompt, and the default file location is fine.  Apache should now be installed.

 

If you do get problems during install, this may be because you have downloaded a corrupt file or because you have another application running that may be listening for incoming connections on port 80.  If you get any errors, search for the specific message or different combinations of the key parts of the error message and you are more than likely to find the answer.

If Apache installs, you’ll see a feather in your system tray with a green play logo on it.  When this happens, open a browser and type http://localhost in the address bar, and you should see an Apache page confirming that the install was successful.

 

{mospagebreak title=Configuring}

To make creating a test website easier, you should reconfigure the DocumentRoot to a more accessible folder than the default of C:/Program Files/Apache Group/Apache2/htdocs.  Create a folder on your C drive and call it mysite or something similar.  Within this folder, you can create a sub-folder called documents or something similar.  Web site roots are normally set up so the the HTML files are kept in one folder, the JavaScript files in another, and so on. Stick an HTML file in the folder, just something basic that renders a sentence in the browser.

Now go to the Start menu and select Edit the Apache httpd.conf Configuration File from the Apache program group.  This will open the main configuration file used by Apache.  You’ll need to scroll down to section two and find a directive called DocumentRoot.  Change the value to C:/folderyoujustcreated.  A little bit further down, you’ll see a <directory “C:/Program Files/Apache Group/Apache2/htdocs”> directive which will also need to be changed to whatever the DocumentRoot was set to. 

 

Now save the file, restart the server and open a browser window.  Type http://localhost in the address bar again and the HTML file you just created should be displayed.  If instead, you see a directory style listing with Index of / at the top of the page, it means that you saved the HTML file with a HTM extension.  To correct this, open the httpd.conf file again and scroll down past the changes you just made to the DirectoryIndex directive.  Add index.htm to the end of the line and again save the file and restart the server.  Refresh the page and you will see the proper document.

{mospagebreak title=Getting PHP Working} 

To get PHP working, just visit www.php.net and download the PHP 5.0.4 installer.  Run the installer and keep all of the defaults.  That’s it; PHP is installed as a CGI application.  All you need to do now is tell Apache that PHP is there.  Open the httpd.conf file from the start menu and find the DirectoryIndex directive again.  Add Index.php before index.html, because you’ll want the server to look for an index.php file before it looks for any other file type.

Now scroll down to the ScriptAlias directive and add the following line of code below the existing directive:

ScriptAlias /php/ “c:/php/”

The path is the path to the default PHP folder, which is generated during the installation of PHP.  Change it if you chose to install to a different location.  Next you’ll need to scroll quite a way down until you come to the AddType directives and add the following line of code directly beneath the last one:

AddType application/x-httpd-php .php

This will register files ending with a PHP extension to the list of available media types.  Finally, scroll down to the Actions section.  This section is commented out completely, so just add the following directive to a new line below the comments.  Make sure there is not a hash symbol at the start of the line:

Action application/x-httpd-php “/php/php-cgi.exe”

This will tell Apache how to process the media type that you’ve just registered.  Now save the httpd.conf file and restart Apache.  The customary way to test a PHP installation is to make use of the phpinfo() function, which displays information about PHP and your system.  In Notepad, type the following line of code, then save the file as index.php:

<?phpinfo()?>

Open a browser instance and again type http://localhost.  You should now see the results of the phpinfo() function.  PHP has now been successfully installed and Apache configured correctly for its use.

 

{mospagebreak title=Configuring MySql}

All that remains is to install and configure MySql.  This is probably the trickiest part and involves several steps for success.  First, download the MySql 4.1 installer for Windows from www.mysql.com and run it.  Accept all the defaults and use localhost for the server name.  A guest account will work, but will not be as secure as one with a password. 

Once MySql is installed, go to the System control panel applet, select the Advanced tab and click the Environment Variables button.  Highlight the Path variable and select the Edit button.  Go the very end of the line and add ;C:php then click OK. 

 

You’ll need to restart the machine at this point.  Now go to the find files option in the start menu and do a search for libmysql.dll, then copy this file to your default PHP location (C:php).  Now go back to the find files window, do a search for php.ini and open the file found in Notepad.  Scroll down until you find ;extension=php_mysql.dll and remove the semi-colon from the beginning of the line.  Save this file and restart Apache.  This should work fine, but if you get an error message saying that the libmysql.dll file could not be found, try copying this file to the Apache Bin folder as well.

To test MySql, open Notepad and type the following:

<?php

  $dbServer=’localhost';
  $dbUser=’root';
  $dbPass=’ ‘;
  $dbName=’test';
  $link = mysql_connect(“$dbServer”, “$dbUser”, “$dbPass”) or die
(“Could not connect”);
 
  print “Connected successfully<br>”;
  mysql_select_db(“$dbName”) or die(“Could not select database”);
  print “Database selected successfully<br>”;

mysql_close($link);

?>

This will simply attempt to connect to the server and select the test database that is created during the MySql installation.  Save this file as mysql.php in your web site folder then open a browser and type http://localhost/mysql.php.  You should see a web page displaying:

Connected successfully
Database selected successfully

Your WAMP installation is now complete. You should now be all set to begin creating and testing complex database driven, dynamic web sites.  Please note that the set up described in this article is for closed, development environments only.  This configuration is in no way secure and should not be used for production.

[gp-comments width="770" linklove="off" ]

antalya escort bayan antalya escort bayan Antalya escort diyarbakir escort