Mastering the Web
Click here
Contents
Website Planning Tutorial
Website Design Tutorial
HTML Tutorial
HTML Tables Tutorial
CGI Tutorial
JavaScript Tutorial
Perl Tutorials
CSS Tutorial
Installing a Web Server
Security Tutorial
HTML Cookies Tutorial
Web Tracking Tutorial
Download Free Programs
F.A.Q.

Installing Apache 2 and PHP 5

The best way to understand what is going on when you upload your website's files to a host computer is to convert your own computer in a Web server. I am not meaning here that you must serve your files from your computer, but that you may simulate in your computer what would happen in the host computer. To do this, you must first download the installation files from the download page and I will explain here what to do next, assuming that you have Windows XP in your computer.

The Apache 2 installation file is an executable one, so you must open it as you would with any other program. You may right click and select "Open", select it and press "Return", etc. You will be presented with the following options:

What to install
Choose "Typical."
Where to install
Modify the default path ("C:\Program Files\Apache Group\") and write instead "C:\". This will install Apache to "C:\Apache2" and will save you a lot of typing.

The PHP 5 is a normal ZIP compressed file. You just have to unpack it to your root directory, i.e., "C:\". You will find that a new folder appears, under the name of "php-5.0.0-Win32". Do not hesitate and rename it to "php".

When the Apache installation finished, you may have noticed a new icon that appeared in your desktop tray, at the low right corner of your screen. This icon stands for the Apache Monitor. It lets you control your server and give commands to it. In fact, the server is running from the moment the installation finished, if it was successful.

An "Apache HTTP Server" entry is also added to your Start Menu. From there you may change the server configuration, review the server logs, and issue commands. This menu entry also permits you to start the Monitor if for any reason you removed it from the tray.

There are three commands that you can give to the server: Start, Stop, and Restart. The server will start running with every Windows start-up. If you are in doubt about whether it is actually running, press the key combination Control+Shift+Escape. The Task Manager window will appear, and you can check if under the Processes tab an entry appears with the name "Apache.exe". If all is normal, and the Monitor is in the tray, hovering with the cursor over its icon will display a box saying that all services are running.

If, for any reason, the Web server conflicts with another task going on in the same computer, you can suspend it temporarily. To do so, left click the icon. A little box with the legend "Apache" appears. Click on it, and next click on "Stop". The icon will change its central dot to a red colour. To make it start again, repeat the process and click "Start".

The "Restart" command is used whenever you make a change to the server's configuration. This is done by editing the "httpd.config" configuration file, which we will soon doing. After you finished editing, you must choose "Restart".

Finally, you must know how to troubleshoot any problem you may have. Apache keeps two log files where you may find what is happening; these are the access log and the error log. Both can be accessed from the Start Menu. You should look at them as the first step if there is something not working as it should do.

Configuration and testing

To make work your Apache Web server, you must configure it, because as it came out of the box it will not function properly. Configuration is done by editing the file httpd.conf, which resides in the directory "C:\Apache2\conf". Open it with you favourite text editor (for example, Notepad++) and do the changes I will indicate you.

To make things more easy, I will show you where to make the changes by giving the number of the lines that must be modified. As we are going to add lines, line numbers must be understood as referring to the original file. Now, let us begin: go to the "C:\Apache2\conf" directory and open the file httpd.conf.

After line #172, add:

LoadModule php5_module "c:/php/php5apache2.dll"

This enables PHP as an Apache module.

Replace lines #279 and #280 with:

    Order Deny,Allow
    Deny from all

and add:

    Allow from 127.0.0.1

This is just to prevent anybody with bad intentions to use your server if you are connected to Internet.

Replace line #320 with:

DirectoryIndex index.php index.html index.htm index.html.var

This permits a browser to retrieve index.php as the home page of your site.

After line #743, add the following:

AddType application/x-httpd-php .php

This enables *.php pages to be handled by PHP.

To make effective these changes, restart the Web server.

The php.ini-dist file that comes with PHP must be copied to "C:\Windows" as php.ini. Then you must modify these lines:

Line #293

log_errors = On

Line #337

error_log = c:/php/logs/php_error.log

Line #438

extension_dir = "c:/php/ext/"

To test if the configuration is all right, start your browser and, at the address bar, type http://localhost. You will see a page that begins with this text:

If you can see this, it means that the installation of the Apache web server software on this system was successful.

To test the PHP interpreter, you must write a little test page as this one:

<html>
<head>
<title>What is this?</title>
</head>
<body>
There is no mistery -- 
<?php
echo "it's just PHP -- ";
?>
after all.
</body>
</html>

Save the page as whatis.php in the directory "C:\Apache2\htdocs", and retrieve it with your browser. You should see the entire phrase displayed. This ends the installation and testing of your Web server. If you have any doubt or trouble, feel free to use my contact page.

Previous | Contents | Next

| HOME | FEEDBACK | BOOKMARK |
Build your Website
© 1999-2008 Hector Castro -- All rights reserved

www.great-web-info.com