Virtual Hosts In Apache - Running multiple sites on apache with different server names

free web hosting
Open Discussion > CONTRIBUTE > Tutorials

Virtual Hosts In Apache - Running multiple sites on apache with different server names

fffanatics
I noticed that a lot of people were interested in snlildude87's tutorial on how to create their own personal local test server for their webpages. However, the way he had them test their sites was moving them to the htdocs folder in the XAMPP directory. Many people like myself have or maintain multiple sites at once and this would be a pain to have to use subdirectories for each site and move files all the time. Therefore, with apache you can create something call a virtual host.

Each virtual host acts like its own web server when there really is only one. Each one has their own home directory and their own server name. Basically this will let you reference each different site in a web browser by their name and not http:\\localhost\subdir\subdir ...

Alright to begin you will have to find your virtual hosts file in apache. If you are using XAMPP it is a bit different since they split the httpd.conf file into a few files to make it easier to reference. The virtual hosts file is httpd-vhosts.conf and is located in the apache\conf\extra from within the main XAMPP directory. If you are using apache that you install yourself the virtual hosts will be added directly in the httpd.conf file located in the apache\conf directory and the section should be near the end of the file.

Alright, now to begin. Open the virtual hosts file for editing. You will notice it just is a bunch of comments. To start off you need to set NameVirtualHost. To do this just add the following line
QUOTE
NameVirtualHost 127.0.0.1
since this is a local test server. If this was not local and you wanted outside visitors to be able to access the host you would put your actual ipaddress where the 127.0.0.1 is located.

Now you need to create the virtual hosts. The easiest way to explain this is going to be showing you an example and then explaining it. Here is one of the virtual hosts out of my vhosts file.
CODE

<VirtualHost 127.0.0.1>
ServerName fffanatics
DocumentRoot "C:/Website/fffanatics"

<Directory "C:/Website/fffanatics">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>

</VirtualHost>


Alright the first section of the code is creating a virtual host on the localhost ip address. This address would change just like the NameVirtualHost would change. Then you get the ServerName. This is going to be how you reference your website in the browser. Next is the location in which the files are located. Beware that you have to use forward slashes and not backward slashes or else apache will not start.

The next block of code has to do with who all is allowed access to this host. Since i use this locally i have allowed anyone access since i am set Alloy from all. This means it will allow anyone to access the server in their browser. Since I have never used virtual hosts in an external fashion, i cannot completely say how these would change but you most likely would not allow everyone access and would limit some of the options.

Now that you have one virtual host, you can create as many more as you want. Most likely you will create atleast one more or else you would not have been interested in this tutorial. To do so just copy your previous code and change the ServerName and the DocumentRoot and you will be set.

But how do you access the virtual hosts? To do this you will need to edit your hosts file. All operating systems have these files but they are located in different places and might even be named something else. In Windows this file is located in WINDOWS\System32\drivers\etc and is called hosts (with no extension). Open this file. You will notice their is atleast 1 entry already in this file and that will be
QUOTE
127.0.0.1 localhost


What you will do is add 1 line per virtual host that you have to this file. Each one will start with the value of your NameVirtualHost (which probably will be 127.0.0.1) and instead of localhost you will enter your ServerName. This pairs your server name with the ip address and apache interprets that path to your DocumentRoot.

Now you can start up your apache server (or restart if it already was running so that the new conf files can be used). If the server does not start, go to the command promt and go to the XAMPP folder (or apache folder) and run apache_start.bat. This will give you the line number where it failed but keep in mind that XAMPP splits the conf file into multiple files so this is not the actual line in the httpd-vhosts.conf file but the total line number ran in the httpd.conf file.

Hopefully you made no mistakes biggrin.gif and everything is up and running fine. Now just open any browser window and in the address bar type your server name (for my example it would be fffanatics) and it will take you to the correct webpage. If there is a document not found, then it is not apache's fault but your DocumentRoot may be wrong or you may not have a index file.

Hope this helps people out who do multiple php sites and want to test on the same box.

As a quick side note on XAMPP, if you use the .zip file to install it, you can put it on a thumbdrive and run it from there. You just have to run setup_xampp.bat each time you use it to make sure the configurations are fine and now you can work on all your sites on different computers. However, in order for the virtual hosts to work you would have to edit the hosts file on every computer that you use so that is a negative of having a mobile web server.

 

 

 


Reply

QuickSilva
Thank you very much for this tutorial! If only I would have known the other day, I wouldn't have gone searching through Google to find the answers to my questions... But you answered them there. Very well explained too! wink.gif

Reply

sportytalk
I agree with what shining said in the above post. You've explained all about virtual hosts in an easy to understand way.

I don't really need to create virtual hosts at the moment, but they sound like a good way to have more than one website run on a local webserver at the same time (with different server names), making development a lot easier.

If I ever do decide to manage more than one website at the same time by using virtual hosts, I will come back and read this tutorial.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords :

  1. Sharepoint Calendars Integrated Into Outlook 2007
    Showing multiple Sharepoint Calendars in Outlook 2007 (Company wide De (0)
  2. How To Download Any Flv Files From Any Sites
    (6)
    Now you can download any flv files from any websites!! People often know how to download
    youtubes clip, but not from other sites. In this tutorial you will need a tool name Moyea FLV
    Downloader, it is free and you can download it at http://www.flvsoft.com/download_flv/ This is
    the best tool i have meet up with to download flv files in any site. Since it can detect flv files,
    and list it, you can download it as you want, so no more favourite clips goes away from your sight
    and now you have it on your own hard drive! 1. Run moyea flv downloader see 1.jpg 2.....
  3. Best Way To Add Paypal To Mediawiki Sites
    (0)
    Hey everyone! i just wanted to tell you guys how i added my paypal button to my site! if
    you go to apolopedia.com, you can see that i have a paypal button above my ads on every page. I
    still use the monobook skin, so i went into the skins and edited my php... i basically just added my
    paypal code above the advertisements header in the coding so that it will display there.... i would
    like it more towards the top but i dont want to mess with it too much. /** * MonoBook nouveau *
    * Translated from gwicke's previous TAL template version to remove * depe....
  4. How To Make Your Own Counter Strike Source Dedicated Server!
    (38)
    Ok, so you want to host your own CSS Server on your computer eh? Well you will not need a lot of
    things, and it is very simple. All you will need is time. /biggrin.gif"
    style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> I did this tutorial
    myself, from my experience when I made my own CSS Server. This is just a simple tutorial! It
    ONLY covers the basics of making a CSS server! Lets Get Started! /laugh.gif"
    style="vertical-align:middle" emoid=":lol:" border="0" alt="laugh.gif" /> 1. Download the HLDS
    Update Tool from here . 2. On....
  5. Installing Apache And Php
    Need help? (2)
    First of all you will need Apache httpd server. Go to this link for download And then follow the
    images to help you. 1. Go to the link and scroll down to find this bit. Then download. 2.
    Continue through the process. 3. When it is completed the installation you may have found this in
    your start menu. 4. Go in to "Configure Apache Server" and click "Test Configuration" 5. If all
    goes well, ms dos should close within a second. 6. Now to install php. 7. Go to this link and
    follow the image. 8. Just click the installer as you will not need most of the func....
  6. Start Multiple Programs With One Shortcut
    Windows XP (15)
    Welcome to my turoial on how to start multiple programs using one shortcut. You may probably be
    wondering how this is possible. Well this tutorial will use a language from MS-DOS called batch. I
    am not sure whether it is "language", but I do know that it is a way to program for MS-DOS. Batch is
    simply a way to run several MS-DOS commands with just one command. All batch files are run through
    Command Prompt, but they can be accessed with shortcuts also. Here are a few requirements for this
    tutorial. Requirements Windows XP (I tested this on XP, but it should work on m....
  7. How To Create Counter-strike 1.6 Server In Console Mode
    (5)
    Hello! Now I will show you how to create a CS 1.6 Dedicated server /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> 1. Locate HLDS.exe. It
    could start it from Steam. 2. Make a batch file. You could name it how you like, I writed it as
    start.bat. It should be located in the same folder as the HLDS.exe. It should contain something like
    this: CODE HLDS.EXE -console -game cstrike -port 27015 +maxplayers 24 +map bl_counterquake
    +sv_lan 0 +rcon_password yourrconpass -secure I recommend -console to be there, couse it starts
    hld....
  8. Dynamic Signature - Yet Another Way To Do It
    Create dynamic sigs for multiple users using .htaccess and RewriteRule (0)
    Ever since I connected a program I made in Visual Basic to MySQL database, I had an idea to create
    some sort of a status page... And I did that, where I updated my connection status every 60 seconds,
    updated my Winamp playlist, and several other interesting things... Then, I figured I could create
    an image, and display all that info, and show it on forums, as a signature... And I made a great
    PHP script, that look real fancy, and does the job perfectly... So, I was adding the reference to
    http://status.galahad.trap17.com/stat.php to all the forums... BUT (there's ....
  9. Wordpress Contact Form That Work With Free Web Hosts
    (1)
    Hi there, I had a bit of trouble setting up the wp-contact-form plugin for my wordpress blog that
    was hosted by freehostia. At first I was using the free package, so I couldn't send out any
    mail. I solved that by saving all messages to a directory, and password protecting it. When I
    updated to a payed package, I still couldn't send out any mail. It turned out that the From
    header had to be an existing email that I had registered with my freehostia account, and
    wp-contact-form used "From: " I solved that by modifying the plugin, changing From to the
    administrat....
  10. How To Group Multiple Sets Of Data In Microsoft Excel 2007
    (0)
    How to Group Multiple Sets of Data in Microsoft Excel 2007 Sometimes you may open several
    workbooks and work with a number of the same workbooks at a time. You can open this group of files
    with Microsoft Excel 2007 simultaneously. But you have to define them as part of a workspace, and
    save them in a single Excel 2007 file. To do this, follow below steps: 1- Click On the View tab and
    then in the Window group click Save Workspace. The Save Workspace dialog box appears. 2- In the File
    name field, type your work name and then Click Save. 3- At the top-left of window, C....
  11. Starting Or Stopping Apache And Mysql Server Via Batch File
    (0)
    Hi guys, this is a litte tutorial about how we start and stop the Apache and MySQL in Windows NT
    (2000, XP, 2003) via a batch file script. As we know in Windows NT based system Apache and MySQL
    installed as Windows Services. So we can stop and start it using NET command. For more information
    about DOS command, type HELP at command prompt. I assuming that your MySQL service name is "mysql"
    and your Apache (Apache 2.0.x) service name is "apache2". If you want to chek it click Start > Run >
    services.msc > OK. Windows IS NOT Case Sensitive. Let's get started!. 1. ....
  12. Check Referrer To Prevent Linking Yours From Other Sites
    Check referrer with Php and Mysql (8)
    Check Referrer Using Php To Prevent People Linking To Your Downloads From Other Sites Ever
    find that found some people are listing items, images and tuts and linking directly to the download
    url (those that are like my photoshop tutorial.php?id=0), which is a .php to count the number of
    downloads. To prevent this, you can add a piece of code to the download pages that checks which page
    referred them to the download page: if it's my domain, it downloads the file normally, if
    it's not, it will redirect to my home page instead. Important : Not all browser....
  13. Download Videos From Sites & Convert It.
    especially sites like youtube, google etc... (28)
    This tutorial shows you how to download videos from sites like YouTube, Google, Break etc, which
    runs is in the extension of .flv(Flash Video), and then convert it to .avi or .mpg format. First of
    all, go to http://keepvid.com This site support the download of the sites listed below. QUOTE
    Angry Alien, ArtistDirect, Blastro, Blennus, Blip.tv, Bofunk, Bolt, Break.com, Castpost, Current TV,
    Dailymotion, DevilDucky, FindVideos, Free Video Blog, Google Video, Grinvi, Grouper, iFilm, LuluTV,
    Metacafe, Midis.biz, Music.com, MusicVideoCodes.info, MySpace, MySpace Video ....
  14. Making A Dynamic Page On Blogspot
    Using an external server to make your pages hosted on blogspot dynamic (5)
    Good morning everyone. Have you ever wondered how to allow your visitors to edit content on your
    blog? Like adding a post straight off the page, adding a link, editing your profile etc. This will
    be extremely useful if you want your visitors to contribute to your blog besides writing comments or
    tagging. 1. Adding a post straight off the page. Go to blogger.com, login, select your blog. Go to
    settings -> email. By enabling blog email, you can now add a post by simply sending an email to the
    address you specified. The address should look something like: yourusername....
  15. Installing Php + Mysql + Apache + Phpmyadmin On Windows Part 2
    Continue the last section which is installing phpMyadmin (0)
    QUOTE phpMyAdmin lets you control you MySQL database from a web browser. Steps: 1. If you
    haven't done so already, download the phpMyAdmin Database Manager - You can download the
    software from the phpMyAdmin website. Be sure to download the phpMyAdmin-2.6.2-pl1.zip file. Save
    the file on your Windows Desktop. ... ... ... Go to for more info. Post Copied. Member
    Banned ....
  16. Installing Multiple Os On Your Pc
    How to do that (0)
    Hi everyone, Ok before I start, I want to let you guys know the meanings of some of the
    terminologies I will be using in here. Boot loader is a small program which the operating system
    places on the selected partition (in most cases, the MBR ). it is a small program that loads the
    operating system into the computer’s memory when the system is booted and also starts the
    operating system. So, before you can think of configuring your PC to have multiple boot, you should
    also know how to play around with 'em boot loaders too. And you should also make sure that y....
  17. Checking For Open Ports From Php
    If you want to check the status of a server at a specific port you can (3)
    Some days ago, i needed to check ports of a server from a webpage, for advising of its status. I
    simply used a great php code that's fsockopen . I'll explain it in the following example:
    (Imagine a file called 'checkports.php', containing the next) CODE <? $address
    =" trap17.com"; //Here you can specify the address you want to check ports $port =
    "80"; //Here you can specify the port you want to check from $address $checkport =
    fsockopen($address, $port, $errnum, $errstr, 2); //The ....
  18. A Tutorial On How To Change Your Window's Screen Name's Icon
    (0)
    Have you ever wondered why you hae a fruity duck next to your name when you sign on to windows
    (at the windows welcome screen)? Have you ever wanted to get rid of that fruity duck? Well if
    you have and dont know how, this tutorial is for you! 1) Go to Start 2) Go to Controll
    Panel 3) Find and Go To User Accounts or for others 4) Then down at the bottom look
    again for User Accounts, below "Or Pick A Controll Panel Icon" and click on it 5) Somthing Like
    this should have poped up 6) Click on Change My Picture 7) From there you can s....
  19. Multiple Classes In Html
    you can use more than one at a time (8)
    Multiple Classes in Css Styles Classes are used in html pages to give certain defined
    attributes to elements. They are useful when the attributes are to be used in more than one place on
    a page. (Named Id's are only allowed once per page, but I digress... might have a tutorial on
    that some day.) Sometimes you want Red text and sometimes you want Bold text. Easy enough to do,
    simply define a class and apply it to the element you want red or bold. Use this class where you
    want on the page, since classes are enabled to be used in several spots, for different u....
  20. Hide Names In Welcome Screen
    in XP (0)
    Annoyed by seeing many User Names in the Welcome Screen you can remove them Some times a user needs
    to be added to access a network resource but the user will not be physically logged in to your
    system. In such cases you can remove his/her name from the WelcomeScreen in Xp to do this go to
    Registry editor as normal go to HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS
    NT\CURRENT VERSION\WINLOGON\SPECIALACCOUNTS\USERLIST\ Right click in the
    empty space in the right pane and create a new DWORD value Name this new value "Username"....
  21. Run Your Own Mail / Radio Server
    SHOUTcast and more (24)
    firstly i want to point out that i did have alot more images that i took for this tutorial but i was
    only aloud to show 15 in this post /sad.gif" style="vertical-align:middle" emoid=":(" border="0"
    alt="sad.gif" /> ill ask for the ammount to be raised then i can add the rest in /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> ok here we go.. Audio
    Streaming Server (Radio) What is a Streaming Audio Server Its an application that will allow you to
    "stream" or send a continuous block of data to a client. In a few words, it will allow....
  22. Getting Content To Blog About
    Good for bloggers and content-rich sites (0)
    There are many ways to build content for your blog. I am just sharing some ways that I have
    personally used to build content-rich blog for my company. (http://blogasia.biz) While I am trying
    my best to provide as much information as possible, these are not all the ways to do it. I am merely
    sepeking from the point of a 4 month old blogger. So if you have anything to add to this thread
    please feel free to do so. 1) Feeds. Also commonly known as RSS / XML / Syndication etc. What
    ever it is .. these are merely ways of grabbing information from a website / blog that have....
  23. A Nice Mysql Server Check
    (4)
    I made this and its not very hard at all just fill in the info and it willl see if your mysql is up
    or down CODE <html> <head> <title> Mysql Connection Test
    </title> </head> <body> <h2> <?php // On this you need to put
    your host most of the times localhost username and password. $conncect = mysql_connect (
    "host", "Username", "password" ) or die (" Sorry your server
    can't connect to your mysql server <BR> Check to see you have put in the Username and....
  24. Set Os X Server 10.3 Dhcp To Filter Desks
    Restrict which PCs/Macs get DHCP IP #s (0)
    Among my other duties, I help run a small computing lab for med students at the U of MN. Recently I
    learned that though we only have about twenty legitimate DHCP clients on our wired ethernet getting
    addresses from our Mac OS X 10.3 Server (great system), thirty allocated DHCP addresses were being
    used. Huh? I found that some addresses went to testing, which I understand, but others were being
    grabbed by PCs that should have static IPs but were misconfigured and/or by outsiders who unplugged
    our PCs to network personal laptops (a no-no). We don't watch our PCs all t....
  25. Automating Tape Backups With Amanda, Part 2
    Example of a UNIX crontab running Amanda (0)
    Amanda is a free soureforge tape backup system with some advanced features. The following crontab,
    owned by user amanda under which account our Amanda tape backup software runs (atop FreeBSD),
    defines two period tape backup processes. The amcheck lines tell UNIX to run an amanda check with a
    particular parameter on each of two back tape sets at 3:00 pm (0 15). If a tape isn't ready,
    Amanda sends a warning to "root" which we in turn tell FreeBSD is me, so I then get an email kicking
    me to swap tapes. The amdump lines automate execution of 11:45 pm backups, for SetA ....
  26. How To Make A Sig Rotator
    for people with multiple sigs (85)
    Today, I will show you how to make a sig rotator similar to mine (refresh a page with my post, and
    you will see a different sig each time). We will use the sig rotator to display random sigs here at
    trap17. Create a folder called sig.png Actually, the folder can be called anything, but since we
    will be using the rotator here, it has to be called sig.png because Invision Power Board may not
    allow weird extensions. You can replace png in sig.png with any valid image extensions such as gif
    of jpg. Create a file called index.php If you need help renaming a file to .....
  27. Server Status
    MAke Your own server status in PHP (12)
    My Friend and i made an mmorpg we decided to make a code so the users could tell when the game
    server was running this codoe has many other uses to like monitor a website or w/e you want to do.
    CODE <? $ip = "youriphere"; $port = "yourporthere"; if
    (! $sock = @fsockopen($ip, $port, $num, $error, 5))
    echo '<B><FONT COLOR=red>Offline</b></FONT>'; else{ echo
    '<B><FONT COLOR=lime>Online</b></FONT>'; fclose(....
  28. How To Setup Your Own Dns (domain Name Server)
    (1)
    How To Setup Your Own Dns (Domain Name Server) This is only a quick tutorial, there are literally
    hundreds of little tricks you can do with a DNS, but this will get your basics up and running.
    I'm assuming you want to setup a windows DNS server, but the principals will work for most
    servers. You will need.. 1) A domain name over which you have full control 2) DNS server
    software(Windows server always comes with one of these) 3) At least one fixed IP address, allthough
    two is highly desirable 4) An idea of what services you want on your server The first thing you ....
  29. Checking Your Php Version
    check your version of your server (1)
    This is a very easy tutorial, others may know of this... step 1 => Download the attachment step 2
    => upload to your public directory step3 => open and run the files and you'll get a whole list
    of your server environment and so on.......
  30. How To Create Virtual Drives
    A complete guide on how to create virtual drives (20)
    I'm planning to format my computer tonight, and I need some sort of reference about this when I
    get back. What is a virtual drive? A virtual drive is a shortcut to a folder hidden deep inside
    Windows. Instead of having an icon for the shortcut (virtual drive), you will see a drive icon with
    a letter that you chose when you go to My Computer after you create the drive. After completing this
    tutorial, you will be able to turn a long path
    (C:\directory\directory\more\directory\oh\my\gosh\this\
    is\a\long\direc....

    1. Looking for Virtual, Hosts, In, Apache

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for Virtual, Hosts, In, Apache

*MORE FROM TRAP17.COM*
Similar
Sharepoint Calendars Integrated Into Outlook 2007 - Showing multiple Sharepoint Calendars in Outlook 2007 (Company wide De
How To Download Any Flv Files From Any Sites
Best Way To Add Paypal To Mediawiki Sites
How To Make Your Own Counter Strike Source Dedicated Server!
Installing Apache And Php - Need help?
Start Multiple Programs With One Shortcut - Windows XP
How To Create Counter-strike 1.6 Server In Console Mode
Dynamic Signature - Yet Another Way To Do It - Create dynamic sigs for multiple users using .htaccess and RewriteRule
Wordpress Contact Form That Work With Free Web Hosts
How To Group Multiple Sets Of Data In Microsoft Excel 2007
Starting Or Stopping Apache And Mysql Server Via Batch File
Check Referrer To Prevent Linking Yours From Other Sites - Check referrer with Php and Mysql
Download Videos From Sites & Convert It. - especially sites like youtube, google etc...
Making A Dynamic Page On Blogspot - Using an external server to make your pages hosted on blogspot dynamic
Installing Php + Mysql + Apache + Phpmyadmin On Windows Part 2 - Continue the last section which is installing phpMyadmin
Installing Multiple Os On Your Pc - How to do that
Checking For Open Ports From Php - If you want to check the status of a server at a specific port you can
A Tutorial On How To Change Your Window's Screen Name's Icon
Multiple Classes In Html - you can use more than one at a time
Hide Names In Welcome Screen - in XP
Run Your Own Mail / Radio Server - SHOUTcast and more
Getting Content To Blog About - Good for bloggers and content-rich sites
A Nice Mysql Server Check
Set Os X Server 10.3 Dhcp To Filter Desks - Restrict which PCs/Macs get DHCP IP #s
Automating Tape Backups With Amanda, Part 2 - Example of a UNIX crontab running Amanda
How To Make A Sig Rotator - for people with multiple sigs
Server Status - MAke Your own server status in PHP
How To Setup Your Own Dns (domain Name Server)
Checking Your Php Version - check your version of your server
How To Create Virtual Drives - A complete guide on how to create virtual drives
advertisement



Virtual Hosts In Apache - Running multiple sites on apache with different server names



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE