In this tutorial I will be explaining you how to configure apache (httpd) on redhat distro’s including fedora and CentOS
Apache Web Server
—————–
Packages
——–
httpd-manual-2.0.52-25.ent
httpd-2.0.52-25.ent
httpd-suexec-2.0.52-25.ent
system-config-httpd-1.3.1-1
Daemon
——
httpd
Port
—-
80
Apache User Info
—————-
# grep apache /etc/passwd
apache:x:48:48:Apache:/var/www:/sbin/nologin
Configuration files
——————-
# cd /etc/httpd/
# ll
drwxr-xr-x 7 root root 4096 Feb 15 07:30 conf
drwxr-xr-x 2 root root 4096 Feb 15 07:31 conf.d
lrwxrwxrwx 1 root root 19 Feb 15 07:30 logs -> ../../var/log/httpd
lrwxrwxrwx 1 root root 27 Feb 15 07:30 modules -> ../../usr/lib/httpd/modules
lrwxrwxrwx 1 root root 13 Feb 15 07:30 run -> ../../var/run
# cd /etc/httpd/conf.d/
# ll
-rw-r–r– 1 root root 778 May 24 2006 manual.conf
-rw-r–r– 1 root root 1827 Dec 3 2004 perl.conf
-rw-r–r– 1 root root 448 Jun 26 2006 php.conf
-rw-r–r– 1 root root 1438 Jan 31 2005 python.conf
-rw-r–r– 1 root root 392 May 24 2006 README
-rw-r–r– 1 root root 10919 May 24 2006 ssl.conf
-rw-r–r– 1 root root 352 Aug 19 2004 webalizer.conf
-rw-r–r– 1 root root 299 May 24 2006 welcome.conf
# cd /etc/httpd/conf/
# ll
-rw-r–r– 1 root root 34655 May 24 2006 httpd.conf
-rw-r–r– 1 root root 12959 May 24 2006 magic
lrwxrwxrwx 1 root root 37 Feb 15 07:30 Makefile -> ../../../usr/share/ssl/certs/Makefile
drwx—— 2 root root 4096 Feb 15 07:30 ssl.crl
drwx—— 2 root root 4096 Feb 15 07:30 ssl.crt
drwx—— 2 root root 4096 May 24 2006 ssl.csr
drwx—— 2 root root 4096 Feb 15 07:30 ssl.key
drwx—— 2 root root 4096 May 24 2006 ssl.prm
Apache Configuration – Normal
—————————–
# vi /etc/httpd/conf/httpd.conf
56 ServerRoot “/etc/httpd”
67 Timeout 120
100 StartServers 8 (1 parent process, 8 child process (handles 4000 ch.p)
125 Listen 80
249 ServerName www.harish.com:80
265 DocumentRoot “/var/www/html”
375 DirectoryIndex index.html index.php index.html.var
Virtual Hosting
—————
Hosting multiple websites in apache server is known as Virtual Hosting.
Two types of virtual hostings are available.
1. Name Based
2. IP Based
1. Name Based
Different website names pointing to a single ipaddress.
2. IP Based
An unique ip address for all web sites. Each websites will have its own ip address.
Apache Configuration – Virtual Hosting (Name Based)
—————————————————
# vi /etc/httpd/conf/httpd.conf
1003 NameVirtualHost 192.168.0.12:80
1004 <VirtualHost 192.168.0.12>
1005 ServerName mail.harish.com
1006 DirectoryIndex index.html index.php
1007 DocumentRoot /var/www/mail
1008 ErrorLog logs/mail.harish.com-error_log
1009 CustomLog logs/mail.harish.com-access_log common
1010 </VirtualHost>
1011 <VirtualHost 192.168.0.12>
1012 ServerName info.harish.com
1013 DirectoryIndex index.html index.php
1014 DocumentRoot /var/www/info
1015 ErrorLog logs/info.harish.com-error_log
1016 CustomLog logs/info.harish.com-access_log common
1017 </VirtualHost>
1018 <VirtualHost 192.168.0.12>
1019 ServerName chat.harish.com
1020 DirectoryIndex index.html index.php
1021 DocumentRoot /var/www/chat
1022 ErrorLog logs/chat.harish.com-error_log
1023 CustomLog logs/chat.harish.com-access_log common
1024 </VirtualHost>
# httpd -t <— To check the syntax
Syntax OK
Apache Configuration – Virtual Hosting (IP Based)
—————————————————
# vi /etc/httpd/conf/httpd.conf
1003 # NameVirtualHost 192.168.0.12:80
1004 <VirtualHost 192.168.0.12>
1005 ServerName mail.harish.com
1006 DirectoryIndex index.html index.php
1007 DocumentRoot /var/www/mail
1008 ErrorLog logs/mail.harish.com-error_log
1009 CustomLog logs/mail.harish.com-access_log common
1010 </VirtualHost>
1011 <VirtualHost 192.168.0.13>
1012 ServerName info.harish.com
1013 DirectoryIndex index.html index.php
1014 DocumentRoot /var/www/info
1015 ErrorLog logs/info.harish.com-error_log
1016 CustomLog logs/info.harish.com-access_log common
1017 </VirtualHost>
1018 <VirtualHost 192.168.0.14>
1019 ServerName chat.harish.com
1020 DirectoryIndex index.html index.php
1021 DocumentRoot /var/www/chat
1022 ErrorLog logs/chat.harish.com-error_log
1023 CustomLog logs/chat.harish.com-access_log common
1024 </VirtualHost>
# httpd -t
Syntax OK
Apache Security
—————
1. User Based
2. IP Based
1. User Based Security
———————–
Step -1
——-
# vi /etc/httpd/conf/httpd.conf
1016 <Directory /var/www/mail>
1017 authname harishmail
1018 authtype basic
1019 authuserfile /etc/httpd/htusers
1020 require valid-user (or)
1021 require user user1 user2 user3
1022 <Directory>
Step -2
——-
# touch /etc/httpd/htusers
Step -3
——-
# htpasswd -m /etc/httpd/htusers user1
# htpasswd -m /etc/httpd/htusers user2
Step -4
——-
# service httpd restart
Above mentioned authentication is purely visible in apache configuration file.
Instead of that change the entry in httpd.conf file & create a .htaccess file.
That steps is noted below.
Step -1
——-
# vi /etc/httpd/conf/httpd.conf
1016 <Directory /var/www/mail>
1017 allowoverride authconfig <— This will look 382 .htaccess (hidden file)
1018 </Directory>
Step -2
——-
# cd /var/www/mail/
# vi .htaccess
authname harishmail
authtype basic
authuserfile /etc/httpd/htusers
require valid-user (or)
require user user1 user2
:wq
Step -3
——-
# service httpd restart
IP Based Security
—————–
# vi /etc/httpd/conf/httpd.conf
1016 <Directory /var/www/mail>
1017 order allow, deny
1018 allow from 192.168.0.12
1019 allowoverride authconfig
1020 </Directory>