how to configure apache web server

The configuration file

Apache configuration is all in a file called 'httpd.conf'.

On your mswindows machine, if you have installed apache through the wamp installer, that file is in C:\wamp\Apache2\conf\
It can be edited in any text editor. (Notepad if you are a masochist; NotePass++ or vim if you like to do real work. :p )

On your linux machine that file is usually located in /etc/httpd/conf/
Again, it can be edited in any text editor. vi is a nice one.

When we are beginning, this file all looks pretty much like another language! Which it is. But not too hard to learn.

The basic configuration options

After we install apache, there are usually two things we would like to do.

  1. Create virtual hosts
    (multiple website names)
  2. Enable server-side includes
    (make your web pages include content from other files)

1. Create virtual hosts

1a. Enable virtual hosts in apache.

File: Windows \wamp\apache2\conf\httpd.conf
       Ubuntu /etc/httpd/conf/httpd.conf
       Other Linux /etc/httpd/conf/httpd.conf
What to do: Remove the '#' in the front of the Include ... line:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

(When apache is installed with Wamp5, this is on line 468 of httpd.conf)

1b. Add a virtual host for apache:

File: Windows \wamp\apache2\conf\extra\httpd-vhosts.conf
       Ubuntu /etc/httpd/conf/extra/httpd-vhosts.conf
       Other Linux /etc/httpd/conf/vhosts/
What to do: add on at the end of the file:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "D:/websites/foldername"
    ServerName site
    ErrorLog logs/site-error_log
    CustomLog logs/site-access_log common
    <Directory "D:/websites/foldername">
        Options Includes Indexes
    </Directory>
</VirtualHost>

(Replace the words in italics, with the website name and folder name for your setup.)
Add one of these for each "virtual host" (separate website).

1c. Then we need to tell the operating system, that this "virtual" website lives on your computer:

File: Windows C:\Windows\System32\drivers\etc\hosts
       All Linux /etc/hosts
What to do: Add one of these lines at the end of the hosts file for each virtual website that you have set up in apache:

127.0.0.1	sitename

1d. Restart apache so that it can reread the changes in its configuration files.

1e. Check that the virtual host is working.

In your web browser, type in the virtual hostname that you made. The homepage of that website on your machine should appear!

2. Enable server-side includes (SSI)

2a. Tell apache to use its SSI code:

File: Windows \wamp\apache2\conf\httpd.conf
       Ubuntu /etc/httpd/conf/httpd.conf
       Other Linux /etc/httpd/conf/httpd.conf
Find the section in the file that looks like the one below,
Remove the '#' in the front of the AddOutputFilter ... line, and
Change the .shtml in that line to .html

# AddType text/html .shtml
AddOutputFilter INCLUDES .html 

(When apache is installed with Wamp5, this is on line 456 of httpd.conf)

2b. Tell apache to actually include files in the web pages for a site:

File: Windows \wamp\apache2\conf\extra\httpd-vhosts.conf
       Ubuntu /etc/httpd/conf/extra/httpd-vhosts.conf
       Other Linux /etc/httpd/conf/vhosts/

In the "<VirtualHost *:80>" block for the site:

    <Directory "D:/websites/foldername">
        Options Includes Indexes
    </Directory>

("Includes" is the keyword that makes server-side includes work.)

2c. Restart apache

so that it can reread the changes in its configuration files.

2d. Check that SSI is working

Make a small web page with a server-side include directive in it, and load it from the virtual site. (Learn more about server-side includes here.)

Know more

Other configuration options
You can learn about other more advanced configuration in this web_server directory.
Apache manual
You have everything about configuring apache right there on your machine when you installed apache. You can usually access it through your browser as http://localhost/manual/
Apache website
www.apache.org
The home of apache.

It would be great to have Tibetan and Chinese translations of this page. Can you help? Contact us! http://tibetangeeks.com/contact/