Monday, August 19

APACHE Web Server Configuration on Linux RHEL / CentOS 5&6

                       APACHE Web Server Configuration
                        
                                 



 Different web servers in world :-

Tux               :     Kernel based only text support, Very fast
Stronghold   :     from RedHat Linux
Sun one        :    Also known as iPlanet from Sun Microsystems
AOL server    :    American online free web server
Apache          :    Open source




what is apache?

Apache is a freeware & is the Most Popular& widely used Web Server which consumes 60% of web market that can be configured in both windows and LINUX.
 

Apache Server is used to launch  our web pages  as websites.

service profile: 

  • Type         :    System V-managed service 
  • packages  :    httpd,httpd-devel,httpd-manual 
  • Daemon    :    /usr/sbin/httpd
  • script        :    /etc/init.d/httpd
  • ports         :    80(http), 443(https) 
  • configuration file  :  /etc/httpd/conf/httpd.conf

steps to configure apache :
 

   #yum install httpd-*  -y
   #service httpd start
   #chkconfig httpd on
   #vi /etc/httpd/conf/httpd.conf
 

copy 7 lines (line no 1003 to 1009)
paste under 1009 line
change as follows
<VirtualHost 192.168.0.22:80>
         ServerAdmin root@www.bsrtech.net

         DocumentRoot /var/www/html/bsrtech/
         ServerName  www.bsrtech.net

        DirectoryIndex index.html
 </VirtualHost>


(here 192.168.0.22 is our system's ip & /var/www/html/bsrtech is the document root here we have to place web pages to convert as web site, NOTE: web page must be with a name of index.html)
:save&quit

cd /var/www/html/

create directory name with bsrtech
 # mkdir bsrtech

 # cd bsrtech
 #vim index.html
(type as follows)
   <html>

       <head>
            <body bgcolor=red><conque>
                   <h1> "    welcome to BSR TECHNOLOGIES" <h1>
           </body>
       </head>

  </html>
:save & quit
#service httpd restart
open firefox and type in url
http://www.bsrtech.net (now the website will appear)
 

To launch virtual websites using virtual hostnames

#vi /etc/httpd/conf/http.conf
(line no 990) # NameVitualHost *: 80 (remove # and *:80) type ur system ip
(NameVirtualHost 192.168.0.22:80 )
copy last five lines and paste under it

 NameVirtualHost 192.168.0.22:80
  <VirtualHost 192.168.0.22:80>
      ServerAdmin root@www17.redhat.com
      DocumentRoot /var/www/virtual
      serverName  www17.redhat.com
   </VirtualHost>

(here we are changing system name as www17.redhat.com and document root under /var/www/virtual)
save & quit
#mkdir -p /var/www/virtual
# cd /var/www/virtual 
# vi index.html
<head>
<body bgcolor=green>
<h1> "welcome to virtual website" <h1>
</body>
</head>
save & quit
#service httpd restart


to check 
open mozilla 
type http://www17.redhat.com

 to create virtual webpages under any directory

by default selinux allows webpages which are located under /var/www/  if we want to launch a webpage which is not present under /var/www we have to change selinux context,boolean values.

ex:
# vi /etc/httpd/conf/httpd.conf
<VirtualHost 192.168.0.17>
     ServerAdmin root@xxx17.redhat.com
     DocumentRoot /cyber
     serverName  xxx17.redhat.com
  </VirtualHost>
save&quit
#mkdir /cyber
#cd /cyber
#vi index.html
<html>
<body bgcolor=blue>
<h1> "welcome to cyber'+'technologies" <h1>
</body>
</html>
save & quit
#chcon -R --reference=/var/www/html /cyber
#service httpd restart

to check :
open mozilla
type in url box as follows
http://xxx17.redhat.com(u will get website)


(Click On below image to large......) 



##############################################################################


        TRY   THINGS   AFTER    PRACTICING EXAM ESSENTIALS


to create link pages in a website

#vi /etc/httpd/httpd.conf
<VirtualHost 192.168.0.17>
    ServerAdmin root@www17.redhat.com
    DocumentRoot /var/www/virtual
    serverName  www17.redhat.com
    Alias /training   /var/www/training (add this line in that website)
 </VirtualHost>

save & quit
# cd /var/www/
#cat > training
(type any thing)
save
#service httpd restart


to check  :
go to mozilla
 type www17.redhat.com/training




to create Authenticated websites
#vi /etc/httpd/conf/httpd.conf

 <Directory /var/www/html>
 AllowOverride AuthConfig
 </Directory>
save & quit

# cd /var/www/html
#vi .htaccess
AuthName "it"
AuthType Basic
AuthUserfile /etc/httpd/conf/passwd
require valid-user


we have to provide http password for an user to view this website
#htpasswd -mc /etc/httpd/conf/passwd sam
(type password 2 times)

#service httpd restart

to check :

open mozilla ---clear private data ---in url type http://station17.redhat.com
(give username&password)




to restrict a particular user or particular system to access a website

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

<Directory "/var/www/html">
 Order Allow,deny
 Allow from all
 deny station12.redhat.com
</Directory>
( here we are denying station12.redhat.com)

to check try to open station17.redhat.com from station12 system


to create ssl certificate for an web server

#yum install openssl-* -y
#yum install mod-ssl-* -y


 # vi /etc/httpd/conf.d/ssl.conf
(line no134) #SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt (remove #)
save&quit
#cd /etc/pki/tls/certs
 make genkey
 provide passphrase
#make testcert
passphrase(create with samepassword)
provide country,city,office,mailaddress
#service httpd restart


to run scripts

#vi test.sh
 #!/bin/bash
echo Content-Type:text/html
echo
--
date
ls -l
echo welcome to cyber services

save&quit
#mkdir -p /var/www/hml/cgi-bin
#cp -rf test.sh /var/www/html/cgi-bin/
#cd /var/www/html/cgi-bin/
#cd ..
#chown -R apache.apache cgi-bin
#cd cgi-bin
#chmod 755 test.sh
#vi /etc/httpd/conf/httpd.conf
add a line in website data
ScriptAlias /cgi-bin  "/var/www/html/cgi-bin"
save&quit
#service httpd restart
#setsebool -P httpd_tty_comm on
#setsebool -P httpd_enable_cgi 1
#setsebool -P httpd_sys_script_exec_t rw

to check:

open mozilla

type http://station17.redhat.com/cgi-bin







###############   End Apache Web Server   ####################

6 comments:

:: Linux - Legends ::