HOW TO CONFIGURE APACHE VIRTUAL HOSTING IN LINUX

In this article we are going to learn how to configure APACHE VIRTUAL HOSTING.

  • First we are going to install http web server through yum(yellowdog updater modified) 
[root@localhost ~]# yum install http*

Loaded plugins: rhnplugin, security
Repository 'a' is missing name in configuration, using id
This system is not registered with RHN.
RHN support will be disabled.
a                                                                                      | 1.3 kB     00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.i386 0:2.2.3-31.el5 set to be updated
a/filelists                                                                            | 2.3 MB     00:00
--> Processing Dependency: libapr-1.so.0 for package: httpd
--> Processing Dependency: libaprutil-1.so.0 for package: httpd
---> Package httpd-devel.i386 0:2.2.3-31.el5 set to be updated
--> Processing Dependency: apr-util-devel for package: httpd-devel
--> Processing Dependency: apr-devel for package: httpd-devel
---> Package httpd-manual.i386 0:2.2.3-31.el5 set to be updated
--> Running transaction check
---> Package apr.i386 0:1.2.7-11.el5_3.1 set to be updated
---> Package apr-devel.i386 0:1.2.7-11.el5_3.1 set to be updated
--> Processing Dependency: gcc = 4.1.2 for package: apr-devel
---> Package apr-util.i386 0:1.2.7-7.el5_3.2 set to be updated
--> Processing Dependency: libpq.so.4 for package: apr-util
---> Package apr-util-devel.i386 0:1.2.7-7.el5_3.2 set to be updated
--> Processing Dependency: openldap-devel for package: apr-util-devel
--> Processing Dependency: db4-devel for package: apr-util-devel
--> Processing Dependency: expat-devel for package: apr-util-devel
--> Running transaction check
---> Package db4-devel.i386 0:4.3.29-10.el5 set to be updated
---> Package expat-devel.i386 0:1.95.8-8.2.1 set to be updated
---> Package gcc.i386 0:4.1.2-46.el5 set to be updated
--> Processing Dependency: libgomp >= 4.1.2-46.el5 for package: gcc
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc
---> Package openldap-devel.i386 0:2.3.43-3.el5 set to be updated
--> Processing Dependency: cyrus-sasl-devel >= 2.1 for package: openldap-devel
---> Package postgresql-libs.i386 0:8.1.11-1.el5_1.1 set to be updated
--> Running transaction check
---> Package cyrus-sasl-devel.i386 0:2.1.22-5.el5 set to be updated
---> Package glibc-devel.i386 0:2.5-42 set to be updated
--> Processing Dependency: glibc-headers = 2.5-42 for package: glibc-devel
--> Processing Dependency: glibc-headers for package: glibc-devel
---> Package libgomp.i386 0:4.4.0-6.el5 set to be updated
--> Running transaction check
---> Package glibc-headers.i386 0:2.5-42 set to be updated
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers
--> Processing Dependency: kernel-headers for package: glibc-headers
--> Running transaction check
---> Package kernel-headers.i386 0:2.6.18-164.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================
 Package                         Arch                Version                           Repository        Size
==============================================================================================================
Installing:
 httpd                           i386                2.2.3-31.el5                      a                1.2 M
 httpd-devel                     i386                2.2.3-31.el5                      a                146 k
 httpd-manual                    i386                2.2.3-31.el5                      a                811 k
Installing for dependencies:
 apr                             i386                1.2.7-11.el5_3.1                  a                123 k
 apr-devel                       i386                1.2.7-11.el5_3.1                  a                232 k
 apr-util                        i386                1.2.7-7.el5_3.2                   a                 76 k
 apr-util-devel                  i386                1.2.7-7.el5_3.2                   a                 53 k
 cyrus-sasl-devel                i386                2.1.22-5.el5                      a                1.4 M
 db4-devel                       i386                4.3.29-10.el5                     a                1.9 M
 expat-devel                     i386                1.95.8-8.2.1                      a                130 k
 gcc                             i386                4.1.2-46.el5                      a                5.2 M
 glibc-devel                     i386                2.5-42                            a                2.0 M
 glibc-headers                   i386                2.5-42                            a                601 k
 kernel-headers                  i386                2.6.18-164.el5                    a                993 k
 libgomp                         i386                4.4.0-6.el5                       a                 70 k
 openldap-devel                  i386                2.3.43-3.el5                      a                1.6 M
 postgresql-libs                 i386                8.1.11-1.el5_1.1                  a                196 k
Transaction Summary
==============================================================================================================
Install     17 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 17 M
Is this ok [y/N]: y
  • It will calculate the file size and ask you whether you wanna install it or not.Type y and hit ENTER.
Downloading Packages:
--------------------------------------------------------------------------------------------------------------
Total                                                                          75 MB/s |  17 MB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : db4-devel                                                                             1/17
  Installing     : expat-devel                                                                           2/17
  Installing     : kernel-headers                                                                        3/17
  Installing     : apr                                                                                   4/17
  Installing     : libgomp                                                                               5/17
  Installing     : postgresql-libs                                                                       6/17
  Installing     : apr-util                                                                              7/17
  Installing     : httpd                                                                                 8/17
  Installing     : cyrus-sasl-devel                                                                      9/17
  Installing     : openldap-devel                                                                       10/17
  Installing     : glibc-headers                                                                        11/17
  Installing     : glibc-devel                                                                          12/17
  Installing     : httpd-manual                                                                         13/17
  Installing     : gcc                                                                                  14/17
  Installing     : apr-devel                                                                            15/17
  Installing     : apr-util-devel                                                                       16/17
  Installing     : httpd-devel                                                                          17/17
Installed:
  httpd.i386 0:2.2.3-31.el5       httpd-devel.i386 0:2.2.3-31.el5       httpd-manual.i386 0:2.2.3-31.el5
Dependency Installed:
  apr.i386 0:1.2.7-11.el5_3.1                          apr-devel.i386 0:1.2.7-11.el5_3.1
  apr-util.i386 0:1.2.7-7.el5_3.2                      apr-util-devel.i386 0:1.2.7-7.el5_3.2
  cyrus-sasl-devel.i386 0:2.1.22-5.el5                 db4-devel.i386 0:4.3.29-10.el5
  expat-devel.i386 0:1.95.8-8.2.1                      gcc.i386 0:4.1.2-46.el5
  glibc-devel.i386 0:2.5-42                            glibc-headers.i386 0:2.5-42
  kernel-headers.i386 0:2.6.18-164.el5                 libgomp.i386 0:4.4.0-6.el5
  openldap-devel.i386 0:2.3.43-3.el5                   postgresql-libs.i386 0:8.1.11-1.el5_1.1
Complete!
  • To run APACHE VIRTUAL HOSTING we have disable firewall settings. First we will check its on or not.
[root@localhost ~]# iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
RH-Firewall-1-INPUT  all  --  anywhere             anywhere
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
RH-Firewall-1-INPUT  all  --  anywhere             anywhere
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
Chain RH-Firewall-1-INPUT (2 references)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere            icmp any
ACCEPT     esp  --  anywhere             anywhere
ACCEPT     ah   --  anywhere             anywhere
ACCEPT     udp  --  anywhere             224.0.0.251         udp dpt:mdns
ACCEPT     udp  --  anywhere             anywhere            udp dpt:ipp
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ipp
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
  • If you see ACCEPT word that means firewall is on . SO we will disable firewall and selinux(security enhance linux).
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
  • Check your ip address of machine. And type it on the browser .You will see this type of page . This means apache is running fine but we have to add content to this apache virtual ip address of the machine.

appache

  • So now we are going to the configuration file of APACHE.
[root@localhost ~]# vim /etc/httpd/conf.d/welcome.conf
  • IF we want to disable welcome page and add our own content we have to comment out .
  apr.i386 0:1.2.7-11.el5_3.1                          apr-devel.i386 0:1.2.7-11.el5_3.1
  apr-util.i386 0:1.2.7-7.el5_3.2                      apr-util-devel.i386 0:1.2.7-7.el5_3.2
#
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL.  To disable the Welcome page, comment
# out all the lines below.
#
<LocationMatch "^/+$">
    Options -Indexes
    ErrorDocument 403 /error/noindex.html
  • You must be thinking how to comment out the lines ? You just have to put.
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL.  To disable the Welcome page, comment
# out all the lines below.
#
#<LocationMatch "^/+$">
    #Options -Indexes
    #ErrorDocument 403 /error/noindex.html
#
  • Now we will go to path where our content file will be saved.
[root@localhost ~]# cd /var/www/html
  • And add .html file deepit.html(you can give any name )
[root@localhost html]# vim deepit.html
  • This is what i have written in this file.

DEEPIT PILLAI

 

ETHICAL HACKING

DEEPITP5.WORDPRESS.COM

  • After you are done writing Press ESC and type :wq (to save and quit)
~
~
:wq
  • We will again go to APACHE configuration file to add our content .
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
  • You will find its a big file. Press PAGE DOWN button to come to the bottom of the page.
# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.2/> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
# for a discussion of each configuration directive.
#
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.
#
# The configuration directives are grouped into three basic sections:
#  1. Directives that control the operation of the Apache server process as a
#     whole (the 'global environment').
#  2. Directives that define the parameters of the 'main' or 'default' server,
#     which responds to requests that aren't handled by a virtual host.
#     These directives also provide default values for the settings
#     of all virtual hosts.
#  3. Settings for virtual hosts, which allow Web requests to be sent to
#     different IP addresses or hostnames and have them handled by the
#     same Apache server process.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
# with ServerRoot set to "/etc/httpd" will be interpreted by the
# server as "/etc/httpd/logs/foo.log".
#
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi
#
# For files that include their own HTTP headers:
#
#AddHandler send-as-is asis
#
# For type maps (negotiated resources):
# (This is enabled by default to allow the Apache "It Worked" page
#  to be distributed in multiple languages.)
#
AddHandler type-map var
#
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
#
# Action lets you define media types that will execute a script whenever
# a matching file is called. This eliminates the need for repeated URL
# pathnames for oft-used CGI file processors.
# Format: Action media/type /cgi-script/location
# Format: Action handler-name /cgi-script/location
#
#
# Customizable error responses come in three flavors:
#
#
#
# End of proxy directives.
### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#
  • Just in the end of this file we have to add our content . Press I and enter into the insert mode .In top of this line  you will see some bold letters i have highlighted for you guys . You have write in same way . AFter And Don’t forget where its capital letter we have to also give capital letters.
  • I have given you example of mine file . Press Esc and :wq (to save and quit)

DocumentRoot /var/www/html/
DirectoryIndex deepit.html



:wq
  • Now turn on the httpd server after making changes in configuration file (needed)
[root@localhost html]# service httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd: [Fri Dec 23 00:03:03 2016] [error] (EAI 2)Name or service not known: Failed to resolve server name for 192.168.0.106 (check DNS) -- or specify an explicit ServerName
                                                           [  OK  ]
  • FIrst check whatever you have change in configuration is ok or not by httpd -t command, if you see syntax ok this means it will run smoothly.
[root@localhost html]# httpd -t
[Fri Dec 23 00:03:23 2016] [error] (EAI 2)Name or service not known: Failed to resolve server name for 192.168.0.106 (check DNS) -- or specify an explicit ServerName
Syntax OK
  • Now try to open your browser with same ip adress of the machine with port number.

apache virtual hosting

HOW TO CREATE VIRTUAL IP ADDRESS AND CONFIGURE APACHE VIRTUAL HOSTING IN LINUX .

WHAT IS VNC SERVER . HOW TO CONFIGURE VNC SERVER IN LINUX AS SERVER AND WINDOWS, ANDROID , IPHONE OR IPAD AS CLIENT.

WHAT IS FTP SERVER AND HOW TO CONFIGURE LINUX AS FTP SERVER AND WINDOWS OR LINUX AS CLIENT.

One thought on “HOW TO CONFIGURE APACHE VIRTUAL HOSTING IN LINUX

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s