Tuesday, 28 January 2014

Apache Web server in CentOS 6.4

Apache is an open source freely available HTTP web server that runs on most UNIX-based operating systems as well as on Windows.
Apache web server is used to serve web pages like (.htm .php .pl .cgi .js) etc.
As per March 2012, Apache web server runs on almost 65.24% websites across all the domains.

As we all are aware that Apache is a very powerful, highly flexible and configurable Web server for Nix OS.
Here in this tutorial, we are going to discuss one more feature of Apache which allows us to host more than one website on a single Linux machine.
Implementing virtual hosting with Apache web server can help you to save costs you are investing on your server maintenance and their administration.

Types of Virtual Host

There are two types of virtual hosting is available with Apache.
Name Based Virtual Hosting 
With the name based virtual hosting you can host several domains/websites on a single machine with a single IP.
All domains on that server will be sharing a single IP. It’s easier to configure than IP based virtual hosting,
you only need to configure DNS of the domain to map it with its correct IP address and then configure Apache to
recognize it with the domain names.

IP Based Virtual Hosting 
With the IP based virtual hosting, you can assign a separate IP for each domain on a single server,
these IP’s can be attached to the server with single NIC cards and as well as multiple NICs.

  • Document root Directory: /var/www/html or /var/www
  • Main Configuration file: /etc/httpd/conf/httpd.conf
  • Default HTTP Port: 80 TCP
  • Default HTTPS Port: 443 TCP 
  • Test your Configuration file settings and syntax: httpd -t
  • Access Log files of Web Server: /var/log/httpd/access_log
  • Error Log files of Web Server: /var/log/httpd/error_log

 Install Compile Apache(Apache 2.2.25) in CentOS 6.4 with Source

1) Stop unwanted Services or settings
# /etc/init.d/NetworkManager stop
# chkconfig NetworkManager off
Note: Make sure you have configured Network i.e. (IP Address/Netmask/Gateway/DNS)

# vi /etc/sysconfig/selinux

2) Open Necessary Ports in iptables
# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

Restart Iptables to Save the Rule
#/etc/init.d/iptables restart
#chkconfig iptables on

3) Install Dependencies for Apache

yum install make gcc automake zlib-devel bison cmake libtool wget gcc-c++ unzip ncurses-devel openssl-devel pcre-devel libxml2-devel curl-devel gd-devel libxslt-devel

4) Compile APR & APR Utils
#APR #wget http://mirrors.axint.net/apache//apr/apr-1.4.6.tar.gz

#tar -xvzf apr-1.4.6.tar.gz
#cd apr-1.4.6/
#make install
#cd ..

Note : if you get error= 

rm: cannot remove `libtoolT': No such file or directory issue. then follow the steps.

Edit your configure file

vi /softwares/apr-1.4.6/configure
Change the line

    $RM "$cfgfile"
    $RM -f "$cfgfile"

# APR Utils#wget http://mirrors.axint.net/apache//apr/apr-util-1.4.1.tar.gz

#tar -xvzf apr-util-1.4.1.tar.gz
#cd apr-util-1.4.1
#./configure --with-apr=/usr/local/apr
#make install

5) Install and Configure Apache
Stop Existing Apache#/etc/init.d/httpd stop
#chkconfig httpd off

Make One Directory#mkdir /softwares/
#cd /softwares/
Download Apache #wget http://archive.apache.org/dist/httpd/httpd-2.2.25.tar.gz

Extract Tar File
#tar -zxvf httpd-2.2.25.tar.gz
#cd httpd-2.2.25

Compile Apache (User Your Option I compile in /opt)

#./configure  --prefix=/opt/apache --with-apr=/usr/local/apr/
#make install
#rm -rf /softwares/httpd-2.2.25

Edit Apache Conf File & Add Following Container into this file.
#vi /opt/apache/conf/httpd.conf

Listen 80
User apache
Group apache

Restart Apache
#/opt/apache/bin/apachectl -k restart

Check YOur Web Server (Apache) is Started or Not
#ps -aef |grep apache

OutPut :-

apache    6226  6006  0 17:08 ?        00:00:00 /opt/apache/bin/httpd -k restart
apache    6229  6006  0 17:08 ?        00:00:00 /opt/apache/bin/httpd -k restart
apache    6230  6006  0 17:08 ?        00:00:00 /opt/apache/bin/httpd -k restart
apache    6235  6006  0 17:08 ?        00:00:00 /opt/apache/bin/httpd -k restart
apache    6251  6006  0 17:08 ?        00:00:00 /opt/apache/bin/httpd -k restart


No comments:

Post a Comment