Home arrow PHP arrow Page 2 - Installing PHP under Windows: Further Configuration of WAMP

Installing PHP under Windows: Further Configuration of WAMP

PHPIn his last article, Matthew showed us how to successfully install and configure WAMP (Windows, Apache, MySQL and PHP) to setup a development environment.  In this next piece, learn how to make use of the Apache and PHP configuration files to further enhance your server needs.

Author Info:
By: Matthew Phillips
Rating: 4 stars4 stars4 stars4 stars4 stars / 99
December 11, 2003
  1. · Installing PHP under Windows: Further Configuration of WAMP
  2. · Configuring Apache
  3. · Configuring PHP
  4. · Conclusion

print this article

Installing PHP under Windows: Further Configuration of WAMP - Configuring Apache
(Page 2 of 4 )

To configure Apache the file we will be editing is httpd.conf. Despite the extension this is just an ordinary text file; so open it in notepad for editing either by navigating through the folders (C:Program FilesApache GroupApache2confhttpd.conf) or via the shortcut on the Start menu (Start > All Programs > Apache > Config > Edit httpd Config File).

Apache will treat any lines starting with a hash, or pound, sign (#) as comments, and will ignore them, so a good way to test a setting would be to comment out the old line with a '#' and type your new setting.  That way if you make any mistakes it will be nice and easy to go back to the way things were (delete the new line and uncomment the old one.) There will be many lines commented out, much of it will be text explaining various bits and pieces to you, you should read the first few paragraphs (before Section 1).  This should explain a couple of points about directory paths, and different slashes.  If there is something you don't understand, don't worry as I will be taking you through it all. Remember if you mess up big time the default configuration settings are stored in a backup file (httpd.default.conf).  If there are any lines that I don't talk about, don't change them unless you know what you are doing. Finally remember, none of these changes will be apparent until Apache is restarted.
I would recommend changing one line at a time, saving the file and testing it by clicking start > All Programs > Apache > Configure > Test Configuration.  If you briefly see a DOS (Command Line) box that disappears, then everything is ok.  If the box stays it will tell you where it found an error.

Letís move on to the various directives (configurations/options).

Line: Listen 80

This tells Apache which port to listen for requests on. The default is port 80. If you change the port from default, for example to 8080 or 8008 (both common choices), then any URLs must be validated (e.g. http://www.localhost:8080/ or http://localhost:8080/test.php). As you could imagine typing this for every URL would get quite annoying, quite quickly, so unless you have a real reason to change it, such as IIS compatibility issues, don't.

Line: LoadModule

The Various LoadModule commands tell Apache to load various external modules.  Don't touch these unless you know what you are doing, If you remember when we first installed WAMP in the first tutorial, we added a LoadModule line for PHP (LoadModule php4_module php4apache2.dll).  That's because PHP is an external module that Apache needs to load for PHP scripts to work. Move the PHP LoadModule line from the end of the file, where you put it on install, to the end of the LoadModule block.

Line: ServerAdmin <email>

Make sure the email address you wish to be contacted on is here. Should any error page crop up this will allow people to contact you..  This is not really a major issue on a development server, however, should anything go wrong this would let people know who the server belongs to.

Line: ServerName <servername>:<port>

localhost:80 will do for this one; for similar reasons to ServerAdmin.

Line: DocumentRoot <path>

This tells Apache where your web documents are stored. You can leave this as is, or change it to something you prefer (c:webdocs might be quicker to browse to than C:/Program Files/Apache Group/Apache2/htdocs).  Whatever you do, make sure the directory exists and that you copy all your files to it.

Line: AddType

Back when you installed PHP and added the LoadModule line you should have also added an AddType (AddType application/x-httpd-php .php) line. AddType tells Apache which extensions to associate with which types of documents. Move the PHP AddType line from the bottom of the file to the bottom of the AddType block. If you wish you could change the PHP AddType line to something like (AddType application/x-httpd-php .php .htm).  This will associate .htm file types with PHP, so you can include some php scripts in htm files.

We will be adding another AddType line (AddType application/x-httpd-php-source .phps).  This line will make the extension .phps a PHP Source file, which will display the PHP code with special coloured formatting (once we turn script highlighting on in PHP). You will probably find this quite useful for debugging.

Line: ErrorDocument

These allow you to create your own documents to handle errors.  For instance, if a page is missing you usually get an ugly page with a message similar to '404 Not Found'.  Well, you can make your own error pages.  This will be more fully covered in a future tutorial; however, for the moment uncomment the line ('# ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var') by removing the '#' and change the .html.var extension to .html.  In your document folder create a new directory called 'error' then create an html page called HTTP_NOT_FOUND.  This page should contain a message telling the user that the page they clicked on could not be found.  You should also include a link to your main page. Now, after Apache is restarted, whenever you go to a page that doesn't exist (http://localhost/bad/page) you will get your own pretty error page instead of the standard ugly one.

That's about all you have to worry about for Apache.  As I said before, I recommend that you change one setting at a time, test the configuration (Start > All Programs > Apache > Configure > Test Config), and, if the black screen disappears, fine, if it stays, take note of any errors and correct whatever you may have done wrong.  Remember that no changes will take effect until Apache has been restarted (Start > All Programs > Apache > Control > Restart).

blog comments powered by Disqus

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials