.
Tips For Linux

>> Installing and Configuring Apache Web Server - Part 2

This part of the article deals with the main configuration file that Apache Web Server uses for all its settings. You can achieve all the settings that you want by modifying this file.


The Configuration File - /etc./httpd/conf/httpd.conf


If you see the contents of the httpd.conf file, you would notice that there are a lot of tags enclosed by < and > . They look like XML tags - opening & closing tags. All the instructions that Apache requires are stored in such structures called directives. All of these directives would have a proper opening tag and a closing tag. If there is a tag mismatch then Apache would mostly output some errors during startup.

/etc./httpd/conf/httpd.conf is the main Apache configuration file. It has all the details required by Apache to run successfully. Most of the entries in the httpd.conf file are well documented. So when you go through the file you would find most of the commented statements useful. Now I shall explain a lot of the directives that are found this file.

You may uncomment whichever directive you want to use, in the configuration file. (Uncommenting means deleting the ' # ' at the beginning of the line)


ServerName localhost

The above directive lets you access your local website's index page by typing the following in your browser http://localhost instead of the unfriendlier but common http://127.0.0.1


ServerRoot
This is the directive indicating the ServerRoot. Many new users confuse this with the root of their website. So they change this to the directory where their index.html (of their website) exists. Please note that the ServerRoot is the directory which Apache uses to form the paths for all of its configuration files. So you must leave the entry as it is.


DocumentRoot= /home/httpd/html
In case you are interested in knowing the directory where you website is to be setup, it is defined by a directive called DocumentRoot. In case you open the index.html file that exists in the above mentioned directory using a browser, you would notice that this is the same page that gets displayed whenever you run Apache server and type http://127.0.0.1 in the address bar. This is the location for the default page to be displayed whenever you reach the website that you setup on your machine.

You can change the DocumentRoot directive to point to the absolute path of the directory where your local website is present. Note that the absolute path is essential.


ServerType standalone
This setting is best left untouched in case you are a homeuser who is trying to configure Apache for CGI programming or some simple web design. Standalone indicates exactly this - that your machine is a standalone machine and that it requires no special settings. An alternate setting is the inetd which can be set as follows


ServerType inetd

The main difference between inetd and standalone is that in standalone mode all the settings that Apache server uses (which are stored in the httpd.conf file) are read when the server starts. Whenever the server receives requests (at port 80) these settings which were loaded at startup are used. In inetd mode the settings are re-read every time the server receives a request at port 80. This makes the server very slow to respond, but any changes made after starting the server will take effect immediately when you make a new request. Though the inetd mode is good for development purposes since it re-reads the configuration details for every request, I prefer running the server in standalone mode only since I don't change the server settings once they are initially made.


AccessFileName .htaccess
You can use the special method to restrict access to directories by using specially named files in those particular directories. The above directive suggests the name of the file which should restrict access. Thus there has to be a file named .htaccess (note that the period is the 1st character, this makes the file a hidden file under Unix) in all those directories that you want to control access to. The contents of this .htaccess file have to be according to certain rules. I shall be elaborating on the rules in future updates to this page


TypesConfig /etc/mime.types
The above directive that is present in the httpd.conf file simply tells the server where it can find the file describing the MIME types. You can add new MIME types to the /etc./mime.types files in case you want apache to respond to such requests as well. This would enable Apache to open the concerned application whenever it gets a request for that particular file type. If you want to add any new MIME types then add it to the file indicated above rather than to the Apache configuration files.


DirectoryIndex index.html index.htm index.shtml index.cgi
The above directive is known as Directory Indexing. This basically indicates what file the Server should send to the client when the user only types the name of your website and not a particular html page. Thus in case you have a website named www.abc.com with an index.html in the root of your website. A user may only type http://www.abc.com in his browser. But the above directive indicates that the server must search for the following files in the directory and return the one it finds. Thus this directive indicates what files to search for, in case the user types a directory name instead of a particular html page on your website. Thus it would search for the files with the names given above in the same order within that directory. In case it finds any of the above that particular file would be displayed. Thus in the above case of www.abc.com the index.html file would be sent back to the client even though he had not specifically asked for that file. This is the default behaviour that you see on most of the sites on the Web.

In case Apache does not find any of the above files then Apache creates a HTML file dynamically containing the names of the files that are present in that directory. There are a lot of settings that can be made to change the appearance of this directory listing that is generated. I shall not go into the depth of that since it is not generally required for a homeuser.

I shall be adding explanations of more directives as soon as I make good use of them.


Goto Part 1 of this article | Goto Part 3 of this article


>
Tips For Linux © All Copyrights Reserved