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

In this post we are going to learn how to create virtual ip address and virtual host on that virtual id .

This post is all about apache virtual hosting .Setting up more then One Host/Site over Single Server is called Virtual Hosting. First we will create virtual ip address.

  • First get the ip address of the machine  by ifconfig .My ip is 192.168.0.120.
[root@localhost ~]# ifconfig
          Base address:0xd010 Memory:f0000000-f0020000
eth1      Link encap:Ethernet  HWaddr 08:00:27:C6:13:E2
          inet addr:192.168.0.120  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fec6:13e2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:894 errors:0 dropped:0 overruns:0 frame:0
          TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:116794 (114.0 KiB)  TX bytes:11772 (11.4 KiB)
  • Now we will create one more ip in eth1 like eth1:0 and it will be our virtual ip address .
[root@localhost ~]# ifconfig eth1:0 192.168.0.130
  • Now check by ifconfig . Your virtual ip address will be created . Like this you can create many virtual ip address just change eth1 path like  eth1:1 or eth1:2
eth1:0    Link encap:Ethernet  HWaddr 08:00:27:C6:13:E2
          inet addr:192.168.0.130  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

NOW WE WILL LEARN HOW TO CONFIGURE APACHE VIRTUAL HOSTING 

  • First we will install package which is needed for apache virtual hosting .
[root@localhost html]# yum install php*
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.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php.i386 0:5.1.6-23.2.el5_3 set to be updated
--> Processing Dependency: php-cli = 5.1.6-23.2.el5_3 for package: php
--> Processing Dependency: php-common = 5.1.6-23.2.el5_3 for package: php
--> Processing Dependency: libgmp.so.3 for package: php
--> Running transaction check
---> Package gmp.i386 0:4.1.4-10.el5 set to be updated
---> Package php-cli.i386 0:5.1.6-23.2.el5_3 set to be updated
---> Package php-common.i386 0:5.1.6-23.2.el5_3 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================
 Package                     Arch                  Version                           Repository          Size
==============================================================================================================
Installing:
 php                         i386                  5.1.6-23.2.el5_3                  a                  1.1 M
Installing for dependencies:
 gmp                         i386                  4.1.4-10.el5                      a                  665 k
 php-cli                     i386                  5.1.6-23.2.el5_3                  a                  2.1 M
 php-common                  i386                  5.1.6-23.2.el5_3                  a                  151 k
Transaction Summary
==============================================================================================================
Install      4 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 4.0 M
Is this ok [y/N]:y
  • It will calculate file size and ask you whether you wanna install it or not . Type y and hit Enter .
 
Downloading Packages:
--------------------------------------------------------------------------------------------------------------
Total                                                                          44 MB/s | 4.0 MB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : php-common                                                                             1/4
  Installing     : gmp                                                                                    2/4
  Installing     : php-cli                                                                                3/4
  Installing     : php                                                                                    4/4
Installed:
  php.i386 0:5.1.6-23.2.el5_3
Dependency Installed:
  gmp.i386 0:4.1.4-10.el5       php-cli.i386 0:5.1.6-23.2.el5_3       php-common.i386 0:5.1.6-23.2.el5_3
Complete!
  • Now we will fill content on the page we are going to host  .And content path will be  /var/www/html/php.
[root@localhost ~]# cd /var/www/html/php/
  • Now we will create one file which will be in  /php and which will have all content of our new page .
[root@localhost php]# vim index.php
  • In this page i’m adding some content.
<?php
echo "HELLO";
echo "ETHICAL HACKING";
ECHO "LINUX"
?>
<html>
<body>
<h1>HI IM DON</H1>
<h2> DEEPIT</h2>
</body>
</html>
~

When you are finish press ESC and type :wq ( to save and quit)

~
~
:wq
  • Then go to apache configuration file .
[root@localhost php]# vim /etc/httpd/conf/httpd.conf
  •  Apache configuration file will look like this .
# 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.
#
#<VirtualHost *:80>
#    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
#</VirtualHost>
  • I’m simply adding this command for apache hosting .
  • After virtual host i’m typing the virtual ip address i have created with the port number .(:80)
  • After document root give the path of the file where your file is located . Php file that I have  created .
  • Server name what you want to give .
  • After Directory index- file name of your content.
  • Make sure way of writing is same . Check the bold line upwards .
</VirtualHost>
<VirtualHost 192.168.0.130:80>
DocumentRoot /var/www/html/php
ServerName deepitp5.com
DirectoryIndex index.php
</VirtualHost>

Now press ESC and type :wq ( to save and quit)

:wq
  • Now open your browser and type server name you have mentioned .

apache virtual host

WHAT IS NFS SERVER AND HOW TO CONFIGURE NFS SERVER 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 PYTHON SERVER AND HOW TO CONFIGURE PYTHON AS WEB SERVER 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