Thursday, October 4, 2007

Apache 2.x setup Quick guide for Linux

I am herewith trying to log all the issues faced during apache web server setup.
Download apache from http://httpd.apache.org/download.cgi

There you can find either a source or binary.

Normally it is good to compile the source to a OS platform. But it is little extra effort. Setting up using a apache binary is faster but may not be reliable.

Here are basic and advanced steps for apache setup:

To setup , follow these very basic steps to setup apache in it's default location
Extract the apache bundle

1. tar xvf apache.x.tar
2. cd apache.x
3. ./configure
4. make
5. make install
6. cd ./apache/bin
7. ./httpd -k start[stop] # run's on port 80 which is default

Open browser..Go to http://localhost/ #....This should open a page ...It Works!!

To make an advanced setup like configuring additional modules, setup destination,etc , do the following:

1. tar xvf apache.x.tar
2. cd apache.x
3. ./configure --prefix=/path/to/apache --enable-[auth]=shared
4. make
5. make install
6. cd ./apache/bin
7. ./httpd -k start[stop]


Go to ./apache/conf/httpd.conf to change the port or any other setting. Will blog later on httpd.conf .

To have apache use a custom httpd.conf on startup do this :
./httpd -k start -f /custom/conf/httpd-custom.conf

To chek if apache supports DSO, run
./httpd -l # this lists all the modules setup in apache

I have listed a set of modules which were enabled for apache 2.0.59 to run a website on production:

--enable-authn_file=shared --enable-authn_anon=shared --enable-authz_host=shared --enable-log_config=shared --enable-logio=shared --enable-expires=shared --enable-headers=shared --enable-setenvif=shared --enable-mime=shared --enable-status=shared --enable-vhost_alias=shared --enable-dir=shared --enable-alias=shared --enable-rewrite=shared --enable-access=shared --enable-auth=shared --enable-userdir=shared --enable-autoindex=shared --enable-negotiation=shared

There are thousands of directives to be configured in httpd.conf .Refer http://httpd.apache.org/docs/2.2/mod/directives.html for apache 2.2

To change the server port by changing in ./apache/conf/httpd.conf the Listen 80 directive

Virtual host directive : A single apache server can have multiple virtual hosts and can server different sites.

To set this, open ./apache/conf/httpd.conf and enter the directive as below:


<VirtualHost 172.20.41.39:80>
 ServerName xyz.com
 ServerAlias www.v2.xyz.com v2.xyz.com www.eetonline.com www.xyz.com eetonline.com

 DocumentRoot /web/docs/electronics/v3.xyz.com
 DirectoryIndex index.html index.htm
 ErrorDocument 403 /nopagefound.jhtml
 Redirect /uk/motorola http://www.xyznet.com/
 
 <Location "/globalSpec"> # to specifiy the mounted directory to be used
  ExpiresActive on
  ExpiresDefault "access"
  Header append Cache-Control "no-cache"
  Header append Expires "Thu, 4 Jan 1990 10:00:01 GMT"
  Header append Last-Modified "Tue, Jan 27 2099 23:59:59 GMT"
  Header append Pragma "no-cache"
  Options FollowSymLinks MultiViews
  satisfy any
  Order deny,allow
  Deny from all
  AuthType Basic
  AuthName "xyz login"
  AuthUserFile /web/admin/apache/etc/auth/xyz.com-globalSpec
  require valid-user
 </Location>
<VirtualHost>

No comments: