Home arrow Apache arrow Getting Started with Apache 2.0 Part II

Getting Started with Apache 2.0 Part II

In this second article in a three-part series, you will learn how to customize the the log files generated by the Apache Web server, and much more.

TABLE OF CONTENTS:
  1. Getting Started with Apache 2.0 Part II
  2. The Apache Log Files
  3. Who Are You?
  4. One Server, One Hundred Websites
By: Harish Kamath
Rating: starstarstarstarstar / 16
March 21, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Last time, I showed you how to install Apache on your own machine from scratch, and explained the configuration directives that help run the Web server. You also learned how to configure the latest versions of PHP and Apache to work together - an exciting combination, though I must admit that there are conflicting opinions on this subject.

Today, I'll explain the configuration of the "main server." I opted to skip this topic in the last article. Next, I'll talk about the different log files generated by the Apache Web server and how you can customize them to your requirements. Finally, we'll see how to create "Virtual Hosts" that give us the ability to run multiple websites on a single instance of the Apache Web server.

So, what're you waiting for? Let's get cracking!

One Server, One Website

In the previous article, I gave you a quick overview of the "httpd.conf" configuration file but I stopped short of explaining the section that dealt with the "main server" configuration due to space constraints. So, let me talk about it before I run out of bytes again.

By default, Apache is configured to serve a single website, and the "main server" configuration section encompasses "directives" that drive this default website. Let me explain them one-by-one:

ServerAdmin webmaster@mysite.com

The "ServerAdmin" directive allows you to specify an e-mail address for the administrator of the Web server. This comes in handy if an error occurs on the server: Apache will display this e-mail address on the Web page for further action by the visitor who encountered the error.

Humans being humans, website visitors cannot be expected to remember the bunch of numbers that form the IP address when most fail to even remember their own anniversaries. This is where the use of human-friendly "domain names" and the "ServerName" Apache directive comes in handy, as it is easier to remember a URL such as www.mysite.com than its IP address. Take a look:

ServerName www.mysite.com:80

As seen above, this directive allows you to explicitly specify the name for your Web server and the port on which it runs. However, if you do not have a valid host name for your server, you can also opt to list the IP address of the Web server with this directive.

DocumentRoot /usr/local/apache/htdocs

This directive specifies the location of the "root" folder of the Web server. By default, all requests are served from the files located under this folder.

Next, I'll talk about the "Directory" directive - this special directive allows you to specify a list of features for each file-system directory on the Web server. Consider the following snippet:

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

Let us start with the root folder on the server. For obvious security reasons, the default Apache configuration enforces high security for this folder by disabling most features. However, you can customize these very features for subsequent folders located under the root folder. Let me start with the root folder of the "Web server" as specified in the "DocumentRoot" directive:

<Directory /usr/local/apache/htdocs>
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

The "Options" directive allows you to list the features that you would like to enable for the directory in question; in the above example, you have the "DocumentRoot" folder under scrutiny. For example, the above snippet enables two of them: "Indexes," which directs the Web server to list the contents of the directory in the absence of an index page (for example, index.htm) and "FollowSymLinks," which, as the name suggests, instructs the Web server to follow any "symbolic" links that may be located in the current folder.

There are other features that you can enable in this "Directory" directive, including the "ExecCGI" directive that allows you to execute CGI scripts on your Web server, the "Includes" directive allows you to include Server-Side Include (SSI) commands in your Web pages and much more. For a complete list, please review the following URL: http://httpd.apache.org/docs-2.0/mod/core.html#options

Next, the "AllowOverride" directive enables the use of a folder-specific ".htaccess" file, which in turn can contain its own set of Apache directives to drive access and security on a per-folder basis.

Note that the "directives" that you can use in this ".htaccess" file are governed by the value specified for the "AllowOverride" directive above. If this is set to "None" - as in the code listing above - the ".htaccess" files are totally ignored. For other options, I recommend that you read the following documentation: http://httpd.apache.org/docs-2.0/mod/core.html#allowoverride.

Finally, you have the "Order," "Allow" and "Deny" directives. These three directives are provided by the "mod_access" Apache module and allow you to implement a fine-grained access policy across the entire Web server. The "Order" directive lists the "order" in which the "Allow" and "Deny" directives should be implemented, whereas the "Allow" and "Deny" directives allow you to specify a domain or an IP address (even partial ones) or a combination of a network/netmask addresses - thereby permitting or restricting access to specific users respectively. For more information on this "mod_access" module and its associated directives, hop over to http://httpd.apache.org/docs-2.0/mod/mod_access.html

Now, you must be wondering why I've opted to talk about these "main server" specific directives now. The reason is simple. Later in the article, I'll show you how to configure a single Web server to run several websites, and you should be able re-use these directives for each Web site.



 
 
>>> More Apache Articles          >>> More By Harish Kamath
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

APACHE ARTICLES

- Apache Unveils Cassandra 1.2
- Apache on ARM Chips? Dell and Calxeda Help M...
- The Down Side of Open Source Software
- VMware Unveils Serengeti for Apache Hadoop
- SAP Takes Steps to Improve Hadoop Integration
- Looking to Hone Apache Hadoop Skills?
- How to Install Joomla on WAMPP
- Working with XAMPP and Wordpress
- GUI Available for Apache Camel
- Reduce Server Load for Apache and PHP Websit...
- Creating a VAMP (Vista, Apache, MySQL, PHP) ...
- Putting Apache in Jail
- Containing Intrusions in Apache
- Server Limits for Apache Security
- Setting Permissions in Apache

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: