"A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila." - Mitch Radcliffe

Setting Up An Apache Server For Testing

Setting Up An Apache Server For Testing

Wednesday 3rd August 2005 - Friday 9th September 2005

Categories: Guides, GNU/Linux, FLOSS

Apache 1

This page is for those of you wanting to install Apache 1 - those that want to install Apache 2 should go to the next page. If you're not sure which version you want, then you'll probably want to install Apache 2.

First of all, you need to install Apache itself. So, as root in a terminal, type apt-get install apache or use synaptic, or whatever you normally use to fetch packages. Next, we want Apache to be able to generate your pages - if we want to be able to generate PHP pages, we install the package php4.

Now, Apache should be running - test by going into a web browser and typing in localhost as a web address. If everything's working as it should, you'll get an Apache placeholder page.

Before we start configuring Apache to load your pages, we need to make sure that Apache can only be accessed by the machine it's on, since we're only using it to test web pages. We do this by editing /etc/apache/http.conf. You'll need root permissions to do this, so the easiest way is to open up a terminal, become root and type nano /etc/apache/http.conf. Once in this file, add the line BindAddress For this change to take effect, you need to restart Apache by using the command /etc/init.d/apache restart. From now on, you should only be able to access Apache on this machine.

The next step is to point Apache in the direction of your web pages. By default, the location is /var/www. Although you can put your web pages in there, I find it easier to keep web pages in your Home directory so that it easier to edit. If we're going to do this, we need to change some Apache configuration files.

As root, access the file /etc/apache/httpd.conf. Find the line DocumentRoot /var/www/ (line 282 in my version of the file), and change /var/www/ to the path of your web page - this means the directory your index is stored in. If I have the file index.php in the directory /home/foobar/webediting/, I would change the line so it displays DocumentRoot /home/foobar/webediting/. You also need to change a line shortly afterwards - right now, it should display <Directory /var/www/>. Change it to match the previous line you changed. In my example, it would become <Directory /home/foobar/webediting/>. Finally, we need to restart Apache using the command /etc/init.d/apache restart. Visit localhost in your web browser, and you should see your web page in all it's glory!

Server Side Includes (SSI)

If you want to use Server Side Includes in your web page and test it using Apache, you will (or should!) find that it does not work straight away. In order to get it to work, you must enable the relevant module. Using the file browser, terminal or program of your choice, access the directory /usr/lib/apache/1.3. Here, you should see various files, including 090mod_include, or something similar. As root e.g. in a terminal, you need to type the command /usr/sbin/apache-modconf apache enable 090mod_include. If the name of the module is different on your computer, adjust the command accordingly. Restart apache using /etc/init.d/apache restart, and your server side includes should be working perfectly.

Adding a Markup Validator

If you create web pages, you should check that they are valid (X)HTML using the W3C Validator. If you're on Debian, then this is a very simple process. Simple obtain the package w3c-markup-validator e.g. by typing apt-get install w3c-markup-validatoras root in a terminal, and apt will fetch all the packages you need. Navigate, in your web browser, to localhost/w3c-markup-validator, and you should get your own personal copy of the validator.

Note: If you do not have Server Side Includes installed, you need to install them to get all pages of the Validator to display correctly. For instructions, see above.


Problem: I get a HTTP Error 403 Forbidden Page instead of my web page.

Solution: As root, access the file /var/log/apache/error.log, and try and find a line that contains something similar to (13)Permission denied: If the line continues: access to /foobar/baz.php failed because search permissions are missing on a component of the path, you need to sort out the permissions of your directories and files.

All the directories of the path need to be able to be read and executed by everyone, so the permissions need to be at least drwxr-xr-x, or 755. You can change this in Nautilus if you own the file, so that the Owner can read, write and execute, while the Group and Others can read and execute. For the file itself, everybody should be able to read i.e. at least -rw-r--r--, or 644. For example, if I get a 403 Error when accessing my page /home/foobar/webediting/index.php, I would check that the directories /home, /home/foobar, and /home/foobar/webediting have the right permissions (drwxr-xr-x), as does index.php (-rw-r--r--).