A WebServer Guide -- Help Using Apache

Web server program sits around awaiting requests from visitors' web browsers for objects it has in its possession, and then sends these objects back for the visitor's viewing pleasure. This article guides you through setting and getting started with Apache on Linux. This article gives an insight on Apache Installation !!

What is a Web Server?

Before we get into the particulars of Apache, let's talk about what a web server is. A web server is a program that runs on a host computer (also, confusingly enough, called a web server) that serves up web sites. In other words, the web server program sits around awaiting requests from visitors' web browsers for objects it has in its possession, and then sends these objects back for the visitor's viewing pleasure. Objects that web servers can serve include HTML documents, plain text, images, sounds, video, and other forms of data. These objects may not necessarily exist in static form, but instead are generated on-the-fly by programs run by the server; CGI scripts are the most common of these programs.

Web servers and browsers communicate using HTTP, Hypertext Transfer Protocol, a simple but effective language for requesting and transmitting data over a network. Thus, you'll sometimes hear web servers referred to as HTTP servers.

Web servers come in various shapes and sizes. They run under a variety of operating systems, have varying levels of power and complexity, and range in price from rather expensive to free.

What's so special about Apache?

Apache is:

Powerful -- Apache's performance and reliability is legendary. Feature-Rich -- The Apache server sports a host of features, including: XML support, server-side includes, powerful URL-rewriting, and virtual hosting, to name but a few. We'll be talking about some of these features in future articles. Modular -- Looking for a feature not implemented in the core Apache server? Chances are you'll find a module that can add the functionality you need. Extensible -- Can't find a module that suits your purposes? Well, as Apache is open source, you can write one yourself. In fact, you can even make changes to the inner workings of Apache. All the information you need is right there in the source code and numerous online resources. Share your patches or modules with the community by making them open source as well! Popular -- At the time of this writing, Apache holds a smidge under 60 percent of the web server market. And, yes, popularity does count; help abounds and is only a mailing list or newsgroup posting away. Free -- This is one instance where you don't necessarily get what you pay for. Where does Apache live?

Apache is maintained by the Apache Software Foundation's Apache Server Project at http://www.apache.org.



Apache Web Server

The Apache Web server, for those of you who haven't heard of it, is arguably the most popular Web server in use on the Internet today. While Microsoft contends that its Internet Information Server (IIS) is making huge gains, it's still struggling in many ways against Apache. Why?

For starters, you don't have to be running Windows to run Apache. It was first developed on the various Unix/Linux/BSD platforms, then recently ported to Win32. Internet Information Server, while a very good Web server on the NT platform, is trapped in the "Windows-only" world. While IIS has many handy features, not everyone wants to run NT for their Web server's OS.

Another reason for Apache's widespread acceptance is its overall stability. While you can slow down an Apache Web server (especially if you run tons of PERL/CGI scripts on it), you can rarely, if ever, kill one. The Apache Web server service is near bombproof.

Lastly, it's relatively fast. I say "relatively" as it's relative to what you're doing with it. If you're hosting a Web site with mostly static content, Apache is a fireball. If you throw tons of CGI scripts at it, while making database calls at the same time, you're going to slow it down. Though much of the slowdown will come from your scripts themselves, and not Apache.

This article is going to cover the basics of Apache configuration on Red Hat Linux 6.x-7.1, but fear not; most of the Apache configuration features are cross platform. That means that if you make a modification to Apache on Linux, that same modification, or one extremely similar, is available on other various flavors of Linux using the same syntax!

Getting Apache

Apache is available from http://www.apache.org. While you're downloading the Apache package that's appropriate for your Operating System, be sure to grab the documentation.

If you're a Linux user, the odds are in your favor that Apache has been pre-installed. With the exception of desktop-centric Linux such as Caldera, it's rare that you won't have the Apache server installed. During your Linux installation, if you see an option for "Web services" make sure to select it so that Apache will be installed.


If you're new to the Unix/Linux/BSD world, I should warn you about something. There are two types of installation packages - source and binary. If you're new to the Unix world, try to download a binary format. A binary is the fully compiled version of the application that's ready to be installed on your system.

A source package is just that, it's the source code to the application. This means you have to compile it into an executable program all by yourself. One often messes up while compiling an application. If you're fortunate, you'll find your error immediately. If you're unlucky, it could be hours, days or weeks before you find out, and then you have to spend time re-compiling it again to fix your mistakes. Do yourself a favor when first learning Apache - find the binary package for your OS. You can learn the finer points of compilation later.

Installing, and Running Apache

Those of you running the RedHat Linux distribution may want to take advantage of RedHat's RPM ("RedHat Package Manager") system. Almost identical to a binary, an RPM is further customized to play nicely with other RPMs and provide a consistent interface to installing, updating, and removing binaries. They often entail a loss of flexibility and clarity -- for instance, it's not readily apparent where the contents of some packages will end up. That said, for Linux newcomers or when installing a small standard component, RPMs are simple and reliable.

Bear in mind that an Apache RPM may already be installed on your system depending on how Linux was originally installed on your computer. To find out, at the shell prompt, type:


rpm -qa | grep apache


If you see something like apache-1.3.9xxx, an Apache RPM has already been installed and you can skip on to "Starting Apache".

If you don't have an Apache RPM, you must obtain one. RedHat 6.x Onwards ships with apache-1.x.x-x.i386.rpm in the RedHat/RPMS directory on the installation CD. Or, point your Web browser at ftp://ftp.redhat.com/pub/redhat/current/i386/RedHat/RPMS and pick yourself up a copy. If you've not already done so, you'll need to become root. Navigate to the same directory as the .rpm file you obtained, and then type the following command, substituting the name of the .rpm you're using for apache-1.x.x-x.i386.rpm.


rpm -ivh apache-1.x.x-x.i386.rpm

RPM should grind away, displaying its progress with a primitive ####### progress bar. Barring any errors, you're done.?If you're interested in knowing how to install Apache from scratch, read on. Or you can skip on to Starting Apache.

Building Apache from source may seem a daunting proposition to newcomers, but the Apache developers have done a wonderful job of making the task about as simple as could be. Just three more commands than a binary installation and you skip the arduous task of figuring out which binary is the right one for your particular operating system. Let's give it a whirl, shall we?


Point your Web browser at http://www.apache.org/dist and download the gzip'd form of the current version of Apache.

Now let's uncompress that archive using gunzip and tar. You should replace the apache_1.3.11.tar.gz below with the name of the gzip'd file you downloaded.

gunzip apache_1.3.11.tar.gz | tar xvf -


You should end up with an apache_1.3.x directory, x being the particular sub-version of Apache you downloaded. Move into the newly created directory.

cd apache_1.3.x

Now we'll use the the configure and make commands to (you guessed it) configure, make, and install Apache. If you've not already done so, now would be the time to become root.

./configure


Your screen should look something like:

# ./configure

Configuring for Apache, Version 1.3.11 ... Creating Makefile Creating Configuration.apaci in src Creating Makefile in src + configured for Linux platform + setting C compiler to gcc + setting C pre-processor to gcc -E + checking for system header files + adding selected modules + checking sizeof various data types + doing sanity check on compiler and options ... Creating Makefile in src/modules/standard Unless errors were reported (not warnings, mind you), your Apache installation is now configured and we can move on. This is where things get a bit ugly -- not difficult, mind you, only ugly. Makeing Apache produces screenfulls of scary-looking output, but don't worry -- as long as the process doesn't stop suddenly with an error message, all is as it should be. make

Your screen should look something like:

# make

===> src make[1]: Entering directory `src/httpd/apache_1.3.11' make[2]: Entering directory `src/httpd/apache_1.3.11/src' ===> src/regex ... [several lines later] ... gcc -DLINUX=2 -DUSE_HSREGEX -DUSE_EXPAT -I../lib/expat-lite -DNO_DL_NEEDED `../apaci` -o ab -L../os/unix -L../ap ab.o -lap -los -lm -lcrypt

make[2]: Leaving directory `src/httpd/apache_1.3.11/src/support'
make[1]: Leaving directory `src/httpd/apache_1.3.11'
Finally, you're ready to install your Apache build.

# make install


And you're done! Pretty painless, you have to admit -- although the make output can bring about mild eye-strain ;-)

Here's what the Red Hat Linux installation does:

web server binaries


/usr/sbin/httpd

/usr/sbin/httpd_monitor



config files


/etc/httpd/conf/*



log files



/etc/httpd/logs/*



web server root

(contains cgi, icons/images, and html files)



/home/httpd/*



Configuration


Apache uses some rather easy to understand text files for configuration. On a Red Hat system, you'll find them in /etc/httpd/conf. Quite a few Linux distributions place them in this same place, but if you can't find such a directory, do a search for "httpd.conf" and/or "access.conf". The latest versions of Apache have a main configuration file called "httpd.conf". Older versions use httpd.conf, access.conf and srm.conf. Once you find these, you've found the main config files.

Here's how you can find them.

Login as root (or su as the root operator) cd / find -name httpd.conf Performance Settings

There are multiple performance settings you can activate in Apache. Each of these is designed to prevent slow user connections from hogging up all your server's resources. They can also be used to prevent things like Web spiders from hogging up all your resources.

Starting Apache

Let's take your new Apache installation out for a spin.

If you installed Apache using a binary or from scratch, as root, type /usr/local/apache/bin/apachectl start If you used an RPM, as root, type httpd

Point your browser at your brand new Web server, http://localhost or http://127.0.0.1 (Internal Loopback IP Address), substituting your server's hostname for localhost and you should see the magnificent "It worked!" default home page.


Contact Author at nakul@cwsteam.com





This article comes from osforge.com
http://www.osforge.com

The URL for this story is:
http://www.osforge.com/viewtutorial60.html