Install Virtualhosts on Fedora 11/12

by
Share this Article: Facebook0Google+0Twitter0LinkedIn0Reddit0Pinterest0StumbleUpon0Digg

Lets give a definition of a vrtualhost

The term Virtual Host refers to the practice of maintaining more than one server on one machine, as differentiated by their apparent hostname. For example, it is often desirable for companies sharing a web server to have their own domains, with web servers accessible as www.company1.com and www.company2.com, without requiring the user to know any extra path information.

Apache was one of the first servers to support IP-based virtual hosts right out of the box. Versions 1.1 and later of Apache support both, IP-based and name-based virtual hosts (vhosts). The latter variant of virtual hosts is sometimes also called host-based or non-IP virtual hosts. (source apache.org)

now first we have to install httpd server

#yum install httpd

Now when the apache server installled you can find the config files

Example : we have 2 domaine : example1.com and example2.com

Now . we have to make the domains pub_html inside the home user /home/test1

now first create the public_html inside this directory with subdirctories of this domaine

cd  /home/test1
mkdir public_html

Now create the subdirectories of the virtual hosts :

mkdir -p public_html/example1.com/{public,private,log,cgi-bin,backup}
mkdir -p public_html/example2.com/{public,private,log,cgi-bin,backup}


now lets make a small script to direct the index.html to the virtualhost

VI  public_html/example1.com/public/index.html

and add

html
head
title>example1.com
/head
body
h1>example1.com
/body
/html

dont froget to close the lines with




 

 


dont forget to make the same chnage in the index.html of example2


Now you have to edit httpd.conf and make line uncomented
# Use name-based virtual hosting.
#
NameVirtualHost *:80

Now restart your httpd service
#services httpd restart
you will get somthing like

Stopping httpd:                                            [  OK  ]

Starting httpd: [Mon 15 Dec  07:12:12 2010 [warn] NameVirtualHost *:80 has no VirtualHosts

                                                           [  OK  ]

Configure virtualhosts

vi /etc/httpd/conf/httpd.conf
add this

# Place any notes or comments you have here
# It will make any customization easier to understand in the weeks to come

# domain: example1.com
# public: /home/test1/public_html/example1.com/



# Admin email, Server Name (domain name) and any aliases
ServerAdmin webmaster@example1.com
ServerName example1.com
ServerAlias www.example1.com


# Index file and Document Root (where the public files are located)
DirectoryIndex index.html
DocumentRoot /home/test1/public_html/example1.com/public


# Custom log file locations
LogLevel warn
ErrorLog /home/test1/public_html/example1.com/log/error.log
CustomLog /home/test1/public_html/example1.com/log/access.log combined




save and exit

dont forget to do the same config for example2.com

No reboot or reload the httpd
#services httpd restart
or
#services httpd reload



Now navigate to the first virtual host

http://www/example1.com and should be working

if you want to check your logs

ls  /home/demo/public_html/example1.com/log/

this it the output

access.log error.log

Please enjoy and ask if you have any question

For questions please refer to our Q/A forum at : http://ask.unixmen.com/

Share this Article: Facebook0Google+0Twitter0LinkedIn0Reddit0Pinterest0StumbleUpon0Digg