|
Project: Linux Howtos
Apache installation and configuration
By Apu Shah <apu@freeos.com>
Posted: ( 2000-11-20 12:37:37 EST by )
The Apache project started out to build a commercial grade, open source
web server. As open source projects go, this one has done fantastically well,
powering over 61% of the web servers on the Internet with Microsoft's
IIS a distant second at 19%. Why would you want to choose Apache? This
article will try to answer that and also take you through the installation
and basic configuration of this great web server.
It was a cold morning in New York City, early 1996 when I entered the office and rushed to the kitchen for that hot mug of coffee to warm myself. I met with my boss to discuss the tasks for the day, one of which was, "Install and configure Apache". Hmmm, I thought to myself. What is this Apache? I had heard about the Native American tribe, the Indian who sings ragamuffin reggae and the 1957 Chevrolet classic truck but I did not know that it was something that could be installed and configured on my Solaris 2.5.1 box. I then embarked on a trip that took me through history, technology, philosophy, and statistics. In this article I will share stories of my trip with you and hope that it inspires you to take a journey to meet the ruler of the web, Apache. What is Apache? Apache is a web server. In fact Apache is the worlds most popular and dominating web server with over 61% of all Internet web servers running Apache. A far second is Microsoft IIS, with a measly 19% of market share. This is a true testament to Apache's popularity. (Statistics courtesy of http://www.netcraft.com) Apache actually stands for "A patchy server". Since the original Apache was built from "patching" the original NCSA HTTP daemon in early 1995. Apache is not owned by a single commercial entity (like IIS is owned by Microsoft, iPlanet is owned by Sun/Netscape Alliance) but rather, is developed by a loose knit team of voluntary programmers scattered across the globe, collaborating through the Internet. Today, development of Apache is coordinated by a non-profit organization called the Apache Foundation. Apache has been written in C, using a dynamic, modular architecture (much like the kernel module architecture) in which pieces of functionality can be inserted into the web server by loading pieces of code known as modules. The pieces of code are built as shared libraries/objects on Unix systems. These pieces of code can also be statically compiled into Apache. This makes Apache highly extensible and configurable. But where can I get Apache if I don't have it? Apache is available for download on the Internet, free of charge and is bundled with all (??) Linux distributions. In fact, most (or maybe all) Linux distributions install and configure Apache for you by default. In other words when you install Linux, you are also installing Apache. So to obtain Apache you have two choices, either just get it off the Linux distribution or download the latest and greatest from www.apache.org Now that I have it, how do I install it? Apache distributions come in various forms. Each of these are described below: 1. Source distribution: This consists of the source code and no pre-built binaries. Once you download a source distribution, you must compile it and run the scripts bundled with the distribution to install it. This gives the user maximum flexibility to custom configure and install Apache. The user even has the liberty of extending or modifying the source code and installing other functional modules as well. The install procedure is built directly into the Makefile to build the source and simply issuing the command 'make install' will install Apache with it's defaults on your system. 2. Binary distribution: This consists of pre-built binaries for the various supported operating environments and platforms. These distributions come with installation scripts that allow you to install Apache on your system. 3. Packaged distributions: These distributions come in packaged formats like RPM (for RedHat and derivative systems). These distributions are installed via the standard installation management program called rpm. This allows the software installation of Apache to be tracked by the Operating System. At the end of this article there is a more detailed explanation of how to actually compile and install an Apache source distribution. Ok, now it's all installed, but how do I configure it? An Apache use a single configuration file called httpd.conf to manage its operating characteristics. In this file, you can configure Apache server characteristics like Server name, port on which to run the server, the threading and process spawn limits, the modules that it loads, the handlers for various types of files, virtual directories and hosts, mime-types, access control etc. etc. phew! For default installations you need not touch this file. Only when you need non-standard options for configuring Apache you will have to open this file. This file is well commented and pretty much self-explanatory, so editing it is a breeze. Well it works, but what are its features?
Apache is a full-featured web server that offers a full suite of functionality from basic web serving to highly advanced server configurations. Since Apache is open source, developers can even extend it beyond the basics, thereby making Apache's feature set infinite. Apache is secure. The Apache security controls are very flexible and very powerful. You can specify access control on a particular directory or a particular file, for a particular user, for a group of users, for a particular IP address or a group of IP addresses. All of these settings can be made in the Apache configuration file httpd.conf. In other words you can restrict access of a particular file to a particular user coming from a particular IP address, at the lowest level. The standard socket level security mechanism, SSL, is also available as an Apache module, available freely from openssl.org. This is a standard way of encrypting data transmission between a web client and server. Apache has extensive logging. Apache allows webmasters with extensive options of logging access information to the site. By default Apache uses the "Common Logfile Format" (CLF), which is a standard format for logging access to the server. However, users can specify their own custom format for logging. Apache also tracks other variables of access such as User Agent (the browser), Referrer and even User tracking similar to session maintenance. Apache is modular. The way to extend the functionality of Apache is through a standard mechanism called modules. Modules are pieces of code that conform to the Apache API. A particular module provides a single piece of well-defined functionality. The server can load these modules in two ways, either by statically compiling it in httpd or by building it as a shared object and loading it in the Apache configuration file httpd.conf. For example, security functionality provided by SSL is available as an Apache module. Java servlet support is also a module. This modular architecture makes the functionality of Apache only limited by the available number of modules (there are many!) Apache allows you to extend the functionality of your web site. It is possible to extend the functionality of your server by writing a specific module that performs this task. There are various documents, tutorials and published books, which detail the process of writing a module for Apache. These modules are written in C and conform to the Apache API. Dynamic sites are easy with Apache. Apache supports various dynamic page generation technologies. Some popular ones are Java servlets, PHP, PERL, Python. These technologies usually have an Apache module that enables the web server to invoke server-side programs and return results. There are also a number of application servers that support Apache like IBM Websphere, BEA Weblogic, Netscape iPLanet etc. Is that all? The only limiting factor to Apache's feature set is our imagination. Due to the modular nature of Apache, new functionality can be added to the server on demand by plugging in the module to support the functionality. Among the standard modules bundled with Apache include URL rewriting, access control and authentication, setting of non standard HTTP headers, server-side includes, CGI support, server side image map support, proxy and caching support etc. In summary, Apache is acknowledged as the leading web server on the Internet. Its modular architecture makes it inherently flexible to change. It enjoys wide scale industry support and all popular web development environments work with Apache. It comes with all the advantages of open source allowing system administrators to highly optimize the web platform. Quick start guide If you are now anxious to get started with Apache, here is how you go about compiling the Apache source code and configuring your installation. 1. Download the latest Apache source distribution from www.apache.org 2. Unpack the source distribution. The source distribution comes as a compressed archive. Let's say that we are installing Apache 1.3.12 (apache_1.3.12.tar.gz). Uncompress and untar the archive with the following command: $ tar -zxvf apache_1.3.12.tar.gz This will create a directory named apache_1.3.12 in your current working directory. We'll call this the Apache source directory. 3. RTFM. RTFM. RTFM. Please read the README file in the Apache source directory. 4. Configuring your environment to compile Apache. The source distribution comes with a script called configure, which checks your environment for the necessary support files (like headers, shared libraries and utility programs) that are required to successfully compile Apache. To configure, change directory to the Apache source directory and type $ ./configure --prefix=/usr/local/apache The prefix argument indicates where we wish to install Apache. This command will output several lines on the screen. Essentially this command creates the Makefiles for the build according to your system configuration. If there are errors in configure, you may be missing some header files or utility programs which you must install before proceeding. 5. Compile Apache. Once configure runs successfully you can compile Apache using the make command $ make This will output several lines on the screen indicating that it is compiling and linking Apache. This should normally conclude with no errors, however if any errors occur, they will usually be caused due to missing utility programs or libraries. The Apache FAQ has some pointers if you get stuck (http://www.apache.org/docs/misc/FAQ.html) 6. Install Apache Apache installs itself in /usr/local/apache by issuing the command $ make install If this concludes successfully your system now has Apache installed. You should see Apache's installation files in /usr/local/apache and the main configuration file in /usr/local/apache/conf called httpd.conf 7. Configure Apache Apache is configured through a single file /usr/local/apache/conf/httpd.conf. This file consists of a number of Apache Directives, which determine the various operating parameters of the Apache server. For purposes of a simple installation, you will need to modify only a few directives described below DocumentRoot - This is the location of the directory from which HTML files are served. You can replace the default by any directory. The directive, DocumentRoot "/usr/local/apache/htdocs" instructs Apache to serve files from /usr/local/apache/htdocs. In other words, when you try and access http://servername/somepage.html in a browser, Apache will serve the file /usr/local/apache/htdocs/somepage.html. Directory options - Once the DocumentRoot is defined, you must instruct Apache how to serve and handle various files found in that directory. This is achieved by modifying the Directory directive. The Directory directive has various options such as execution of server side includes, whether to follow symbolic links from the directory, access control to the directory etc. In our configuration file, we need not change anything. Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all
That's about it. Apache is now configured for default behavior and web serving. If there are any other parameters that you need to set, the configuration file is well commented and pretty much self-explanatory. 8. Starting Apache Apache comes with a script named apachectl that facilitates starting, stopping, restarting apache. $ /usr/local/apache/bin/apachectl start /usr/local/apache/bin/apachectl start: httpd started To stop apache use /usr/local/apache/bin/apachectl stop 9. Test your installation Once Apache is running, fire up your web browser and access http://localhost/. If your installation was successful and Apache is running, you should see a test page saying something like "If you can see this, it means that the installation of the Apache web server software on this system was successful". CONGRATULATIONS! You now have a successful installation of Apache running on your system! For more advanced features like CGI support, module additions etc. you can read the Apache documentation that comes bundled with your installation by accessing http://localhost/manual/index.html. Apu Shah is the Chief Technology Officer of FreeOS.com, a leading provider of customised solutions, consulting, training and distribution in Free Operating Systems such as Linux. Feel free to contact him at apu@freeos.com
Apache Project
ApacheToday
Other articles by Apu Shah
Current Rating: [ 6.65 / 10 ]
Number of Times Rated: [ 85 ]
|