Tuesday, December 15, 2009

Apache Installation on Linux

Quick Installation Guide



Step 1: Check the http RPM


# rpm -qa |grep http
httpd-suexec-2.0.52-25.ent
httpd-2.0.52-25.ent
system-config-httpd-1.3.1-1
httpd-manual-2.0.52-25.ent

Step 2: Configure /etc/httpd/conf/httpd.conf file



# vi /etc/httpd/conf/httpd.conf

Then Edit the following line

ServerAdmin root@localhost, u can use another mail account

#ServerName new.host.name:80 ;

If this is not set to valid DNS name for your host, Entry here your IP_ADDR and uncomment
UseCanonicalName Off
DocumentRoot "/var/www/html"
DirectoryIndex index.html index.html.var index.php

Step 3: Start the httpd service


# chkconfig httpd on
# /etc/init.d/httpd restart

Configure Named Virtual Hosting:


Step 1: Edit /etc/httpd/conf/httpd.conf file as


NameVirtualHost 203.188.190.28:80

<VirtualHost *:80>
    ServerName localhost.localdomain
    DocumentRoot /var/www/html
    DirectoryIndex index.php index.html index.htm
</VirtualHost>

<VirtualHost 203.188.190.28:80>
    ServerName mgbs.cyberbangla.com
   ServerAlias mgbs.cyberbangla.com
    DocumentRoot /var/www/html/joomla/
    DirectoryIndex index.php index.html index.htm
</VirtualHost>

<VirtualHost 203.188.190.28:80>
    ServerName mgbs1.cyberbangla.com
    ServerAlias mgbs1.cyberbangla.com
    DocumentRoot /var/www/html/joomla1/
    DirectoryIndex index.php index.html index.htm
</VirtualHost>

Step 2: Copy the website content in the Document Root


Make sure that index.php index.html index.htm are exist in root directory.

Step 3: Restart the httpd service


# chkconfig httpd on
# /etc/init.d/httpd restart

Step 4: Change the file permission in /var/www/html/joomla


# chmod –R 755 /home/www/joomla
# chmod –R 755 /home/www/joomla/
# chmod –R 755 /home/www/joomla/*

Step 5: Go to web browser and enter the site address or IP


http://mgbs1.cyberbangla.com

Configuration - Multiple Sites and IP Addresses


Step 1: Make DNS entry with IP aliases


Step 2: Edit /etc/httpd/conf/httpd.conf file as


NameVirtualHost 97.158.253.26
NameVirtualHost 97.158.253.27

<VirtualHost *>
    DocumentRoot /home/www/site1
</VirtualHost>

<VirtualHost 97.158.253.26>
    DocumentRoot /home/www/site2
   ServerName www.my-site.com
    ServerAlias my-site.com, www.my-cool-site.com
</VirtualHost>

<VirtualHost 97.158.253.27>
    DocumentRoot /home/www/site3
   ServerName www.test-site.com
</VirtualHost>

How To Protect Web Page Directories With Passwords


You can password protect content in both the main and subdirectories of your DocumentRoot fairly easily. I know people who allow normal access to their regular Web pages, but require passwords for directories or pages that show MRTG or Webalizer data. This example shows how to password protect the /home/www directory.

1) Use Apache's htpasswd password utility to create username/password combinations independent of your system login password for Web page access.


You have to specify the location of the password file, and if it doesn't yet exist, you have to include a -c, or create, switch on the command line. I recommend placing the file in your /etc/httpd/conf directory, away from the DocumentRoot tree where Web users could possibly view it. Here is an example for a first user named peter and a second named Paul:
[root@bigboy tmp]# htpasswd -c /etc/httpd/conf/.htpasswd peter
New password:
Re-type new password:
Adding password for user peter
[root@bigboy tmp]#

[root@bigboy tmp]# htpasswd /etc/httpd/conf/.htpasswd paul
New password:
Re-type new password:
Adding password for user paul
[root@bigboy tmp]#

2) Make the .htpasswd file readable by all users.


[root@bigboy tmp]# chmod 644 /etc/httpd/conf/.htpasswd

3) Create a .htaccess file in the directory to which you want password control with these entries.


AuthUserFile /etc/httpd/conf/.htpasswd
AuthGroupFile /dev/null
AuthName EnterPassword
AuthType Basic
require user peter

Remember this password protects the directory and all its subdirectories. The AuthUserFile tells Apache to use the .htpasswd file. The require user statement tells Apache that only user peter in the .htpasswd file should have access. If you want all .htpasswd users to have access, replace this line with require valid-user. AuthType Basic instructs Apache to accept basic unencrypted passwords from the remote users' Web browser.

4) Set the correct file protections on your new .htaccess file in the directory /home/www.


[root@bigboy tmp]# chmod 644 /home/www/.htaccess

5) Make sure your /etc/httpd/conf/http.conf file has an AllowOverride statement in a <Directory> directive for any directory in the tree above /home/www. In this example below, all directories below /var/www/ require password authorization.


<Directory /home/www/*>
   AllowOverride AuthConfig
</Directory>

6) Make sure that you have a <VirtualHost> directive that defines access to /home/www or another directory higher up in the tree.


<VirtualHost *>
   ServerName 97.158.253.26
   DocumentRoot /home/www
</VirtualHost>

7) Restart Apache.


# /etc/init.d/httpd restart

Try accessing the web site and you'll be prompted for a password.

Article Written By : Mahabub Bhai.

No comments:

Post a Comment