Tuesday, October 16, 2012

Linux Apache Server Configuration Tutorial


Apache Server Configuration:

The Apache Web Server is one of the most popular open-source HTTP Servers that exists today. It's a powerful, secure, and fully featured web server that can be found hosting anything from personal web sites to corporate domains. If you have a DSL or Cable connection with a static IP then you can use the Apache web server to host your web site (as long as your ISP doesn't have a problem with you running a server on their network). This tutorial will teach you how to set up your own Apache web server on Linux so you can host your own web sites either at home or work.


Configuring Apache Server Settings (httpd.conf)

Apache's main configuration file is called httpd.conf and is located in /etc/httpd/conf/. The default httpd.conf will work without any changes, however we want to customize Apache a little bit. Our main focus is to setup the use of Virtual Hosts so we can run as many web sites as we want using a single IP address.


Check the Apache (httpd) Package is installed or not.

rpm -qa | grep httpd




The main location of the configuration files are reside at /etc/httpd.

Which contains the conf and conf.d directory.



The main configuration file for Apache server is /etc/httpd/conf/httpd.conf




This file contains three major sections.

1. Global Environment
2. Main Server Section
3. Virtual Hosts Section




I . Global Environment Section:

Here all the major values are called as directives. 

Serverroot directive  ---- /etc/httpd   ---- Which contains all Apache config files.



Connection time out Directive  -- Default value is 120 seconds



Apache uses the HTTP protocol and uses the 80 as port number.

Listen directive  with port number 80.



Load modules directive defines, what are the modules loaded when the apache will restarted.



It includes the configuration files available in /etc/httpd/conf.d . Like php.conf, mysql.conf and ssl.conf



II. Main Server Section:

Server administrator directive  --- mail id of the web administrator.



Documentroot = /var/www/html . Which defines the web application deployment location (Source codes like HTML and Php)


Directory security directive  --- / (root) no one can not access 
It will set as 
Allow override None.



If you want to exceute the CGI scripts then add ExecCGI.




Set this directive as Allow from All.


Set the home index pages.



Error log location and error log format.


To execute the CGI scripts enable the scriptalias.




III. Virtual Host Section:

1. IP Based
2. Name Based --- Which uses the multiple websites single ip address.

Enable name based virtual host.



Now add the multiple site information in the virtual host section.




Now deploy the web site applications in the document root ... /var/www/html location.




Create the index.html file






For this example, i am using two websites, 

1. www.senthil.com
2. www.kumar.com

Now check the httpd daemon is running or not.

service httpd status

if not 

service httpd start


elinks and lynx are the text browsers in linux.

elinks http://www.senthil.com







Now we are accessing through the firefox browser  (www.senthil.com)


(www.kumar.com)



You can check the logs in /var/logs/httpd.

senthil_access_log
senthil_error_log





You can check who are all accessed the website using the access log file.





3 comments:

  1. Really useful and valuable.. I cant find such informations even in product official sites. Looking for a video tutorial from you !!!

    ReplyDelete
  2. yes,its very useful .It would be more helpful of u post video tutorial.I am also waiting for that.Remote Infrastructure Management

    ReplyDelete



  3. Great post.I'm glad to see people are still interested of Article.Thank you for an interesting read..

    IT Infrastructure Management

    ReplyDelete