Πέμπτη 14 Απριλίου 2011

Setting Up the Apache Web Server Under Linux

Where To Get Apache

The obvious place to get the latest version of Apache is off of the Apache web site: http://www.apache.org. The source distribution file is apache_1.1.1.tar.gz while the Linux ELF binaries is apache_1.1-linux-ELF.tar.gz. Grab what you find is necessary...
If you are running Red Hat Linux 4.0 like I am, during the installation process you are allowed to select whether or not you want to install a web server. If you do, Red Hat 4.0 includes the latest Apache and installs everything automatically with a default configuration. This default configuration even RUNS correctly without any modifications! However, even in this case, please read my notes and preferences regarding installation in the next section.
Typically, unless you need to add special modules or features, the binary distribution or the default Red Hat installation should be fine. However, let's say you wanted to run Apache as a proxy server. In this case, you would need the source so you can compile the proxy module as part of the binary.
(Note: I have heard rumors that the binary included with Red Hat 4.0 has some bugs. I have yet to encounter any myself, so take that rumor with a big grain of salt.)


Installation

I'm not going to cover compiling Apache since it's actually a fairly painless process and pretty well documented. Given that, let's move on to actual installation...
Personally, I like to group all the web server files together in a centralized location. If you are installing this manually, then this is something you can do from the outset, and I highly suggest doing this since it will reduce administration headaches.
If you had Apache installed automatically as part of the Red Hat installation procedure, then things will NOT be centralized! In fact, I thought the file placement scheme was one of the most confusing I've ever encountered. Here's what the Red Hat 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/*
I found this to be really disorganized, so I ended up putting mostly everything under one directory (I left the binaries in /usr/sbin):
mkdir /httpd
    mv /etc/httpd/conf /etc/httpd/logs /home/httpd/* /httpd
    rmdir /home/httpd
You should end up with:
/httpd/
          /cgi-bin
          /cgi-src
          /conf
          /html
          /icons
          /logs
And then to preserve the original Redhat file locations:
ln -s /httpd /home/httpd
    ln -s /httpd/conf /etc/httpd/conf
    ln -s /httpd/logs /etc/httpd/logs
Finally, I added this link since I felt that it made more sense:
ln -s /httpd/logs /var/log/httpd
If you are installing and compiling Apache manually, you may want to have the original source files also located under /httpd (or whichever directory you have).


Configuration

Apache has three main configuration files: access.conf, httpd.conf, and srm.conf. If you are running Red Hat 4.0, these files will already be set with the correct directory paths. If you centralized the locations of all these files, but made those symbolic links as I mentioned above, things will still be fine since the symbolic links preserves where Red Hat installed everything.
If you are doing a "generic" installation or have some other setup, then you will need to do the following:
In access.conf, change/update these directory entries:

    
In httpd.conf:
ServerRoot /httpd
In srm.conf:
DocumentRoot /httpd/html
    Alias /icons/ /httpd/icons/
    ScriptAlias /cgi-bin/ /httpd/cgi-bin/
Essentially, these are the necessary directives in the config files that need to be updated with the new "centralized" organization.
For further configuration options, I will have to give the standard statement, "Please refer to the docs." :)


Starting/Running the Web Server

To make a long story short, you simply to need to execute the binary "httpd". Typically, this is done when the system starts up, in one of the rc files.
In Red Hat 4.0, it has more of a System V'ish startup style. In /etc/rc.d/init.d resides httpd.init, which is the script used to start and stop httpd. You can also execute this by hand if you find the need.
For other systems (or a manual install), I suggest starting httpd after most other services have started (i.e.: put it in rc.local). A simple line such as
/usr/sbin/httpd &
will suffice.
Obviously, it must start after tcp/ip networking has been started. :)

Δεν υπάρχουν σχόλια: