How to create second/multiple websites using Apache/XAMPP.

HOW TO CREATE MULTIPLE WEBSITES USING APACHE/XAMPP.

This tutorial will explain how to add additional websites to your Apache web server.  You may be wondering "Do I need to install Apache for a second website?" and the answer is NO.

There should only be one instance of Apache installed and running on your server computer and trying to install another instance of it will only cause problems.  The same goes with PHP.  The only server software you will probably ever need to install another instance of is if you want a seperate MySQL database, and then you would install and configure it seperate from the first.

I've written a few tutorials that explain the method listed in this tutorial, but they all were pertaining to certain configurations and I just realized I never have wrote one that was just a straight forward explanation how to create a second website yet.  So this will be an easy and simple to follow tutorial on how to do that and I'll link to the other articles I wrote to give you some options on how you can apply the multiple websites.

 

If you would like to use the video tutorial, you can visit this article:

How to create second/multiple websites using Apache/XAMPP



HOW IT WORKS:

Apache refers to this as VirtualHosts or vhosts.  Once Apache is running and you have PHP running on your server, there isn't any additonal software needed for a different website.  That would be like saying to open another text document you would need to start another instance of Windows.  Once you've already started Windows once, you can create and open all the files you want as long as Windows stays running.  A web server works the same way.

So by now you've probably realized your first website is in the folder called htdocs.  Any files you put in that folder you can reach through your web browser.  This is done in a simple configuration file that links your web address to that folder.  It is defined in /apache/conf/httpd.conf file.  If you open that file with Notepad, you will find a line that says:

ServerName localhost:80

This gives the website the local domain name "localhost", which will be accessed on port 80.  Port 80 is the default port for web page traffic.  So when you open your browser and type localhost, Apache recognizes it and tells it where to go, which is defined by this line:

DocumentRoot "C:/xampp/htdocs"

So this makes htdocs your root folder, meaning whatever is put in htdocs can be reached by going to localhost.  You may be wondering where "localhost" comes from and it's actually a name assigned automatically by Windows.  You can create different names by reading my tutorial, How to setup local domains or fake domains .  Do note however these DO NOT work on any other computer besides the one the Apache software is running on.

So in order to make another website, we just need to make another definition that tells a different name to go to a different folder.  You can use the article mentioned above or if you're wanting to setup multiple public domain names, you can read this tutorial on how to do that.

Now there is not a way to have multiple websites publically accessible using just your IP address.  You can only specify one website with only your IP.  The reason being is because even though you only have one IP with domain names, Apache recognizes the domain name someone is going to your IP from and directs them to the correct folder based on that.

I'm going to use domain names in my example simply because this is the most likely used method for multiple websites and the one I use myself to host several websites on my server.

httpd.conf is only used to define a single website on the web server.  If you want to host more than one website on your server, you need to enable VirtualHosts.  So in httpd.conf, find the following line and make sure it's enabled by removing the comment from in front of it:

Include conf/extra/httpd-vhosts.conf

If it has a # or ; in front of it, make sure and remove it.  Save and close the file.

Now go to /apache/conf/extra/httpd-vhosts.conf and open it with Notepad.

I personally perfer to find a good example setting and delete everything in this file, then copy/paste the example in there to make it easier to manage.  All of the comments are great if you want everything explained, but it's much easier to manage this file with them all removed.  So here's an example you can use of a multiple site configuration.  Be SURE to remove any entries you don't use or comment them out by putting a # at the beginning of every line not used.

NameVirtualHost *:80

<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>



##  My First Domain    ##

<VirtualHost *:80>
ServerName myfirstdomain.com
ServerAlias www.myfirstdomain.com
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>


##  My Second Domain  ##

<VirtualHost *:80>
ServerName myseconddomain.com
ServerAlias www.myseconddomain.com
DocumentRoot "C:/xampp/htdocs2"
<Directory "C:/xampp/htdocs2">
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>

</VirtualHost>

##   My Third Domain   ##   

<VirtualHost *:80>
ServerName mythirddomain.com
ServerAlias www.mythirddomain.com
DocumentRoot "G:/website/mythirddomain"
<Directory "G:/website/mythirddomain">
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>

</VirtualHost>

Now that looks really complicated, but it's actually quite simple.  If you look at my entry for myfirstdomain.com, you notice there's not near as much text under it and you are probably wondering why.

Technically all you need is an entry like that unless you want to define permissions or need to do so.  You may encounter an ERROR 403 and need to define permissions for that folder, so then you would need to add permissions as I've done for my second and third domain.  You can also limit access with the values defined here, but that is beyond this tutorial.  The permissions I've used above may or may not work for you and you may need use other directives to fix your particular needs.  If you want more information on possible permission configurations, you can view Apache's documentaton on it by following these links:

http://httpd.apache.org/docs/2.2/vhosts/
http://httpd.apache.org/docs/2.2/vhosts/examples.html

http://httpd.apache.org/docs/2.2/mod/quickreference.html

I feel the other entries are pretty self-explanitory, although I will explain a couple of things about them.  First, make SURE you have correctly spelled both instances of the directory paths.  I've gotten 403 errors that have left me puzzled only to find out I didn't spell the second directory path correctly, so verify that it's correct.

I added the lines ##  My First Domain  ##, which are just comments and not required.  If you have a lot of domains with subdomains, you will have several entries here and using comments to organize them will save you time when searching for something.  You can use # or // to define comments.  If you don't properly comment the line(s) out, you will get an error because it will try to read the line as part of the code.

Now if you look at the third domain entry, you will see the drive letter is different and the folder is in a completely different place away from the other files.  I did this to show how you can put the websites on other drives besides the one you installed Apache or XAMPP on.  Apache, PHP, etc. isn't drive specific, so as long as the website's folder is on the same computer and correctly defined, it can be placed anywhere you like.

This can be particularly useful if you're running out of space and need to put additional websites on the computer.

 

 

That pretty much sums up how to create multiple websites on the same server.  There's a few options as to how to use these and as I stated above, the most common would be using domain names.

If you're doing this only for local development or testing purposes and do not intend on launching them as publicly accessible, then the local hosts/fake domains is a great way to test multiple websites.

Another cool option you may consider if you're wanting to add folders to your website(s) from another drive without moving your whole website to that drive, you can use Aliases, which I have more information on that in this article.

The final note to consider is if you are planning on making your website accessible to the public, you need to make sure your ports are properly forwarded and configured, which you can read this article on Port Forwarding.



Comments
Add New Search RSS
Anonymous Y-m-d H:i:s

Hello
Leave feedback
Name:
Your email:
 
Website:
Message Title:
Formatting:
[b] [i] [u] [url] [quote] [code] [img] 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Enter the text as you see it in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."

Last Updated (Wednesday, 04 February 2009 04:57)

 

!!REMEMBER: Support Forums!!

I still keep getting requests for support in the comments of posts and unfortunately I cannot give adequate responses due to the fact there's limited space and it just isn't the right place for support.
I therefore am encouraging visitors to PLEASE go to http://forum.myownserver.info for any support related questions. You will NOT receive any spam or anything you don't specifically subscribe to! I'm very meticulous about this myself and if at any time you need help stopping notifications from posts you previously subscribed to, contact me and I will promptly fix the issue.

Thank you for your participation in this!

Open SourceApache HTTP Server ProjectMySQLPHP
Twitter Feed
28.04.10
Ubuntu 10.04 Lucid releases tomorrow and it's going to be great! Read my overview at http://is.gd/bMiiL
24.04.10
New http://myownserver.info website in the works! Check it out at http://myownserver.info/wiki/ and feel free to contribute.
17.04.10
Petition to bring development on Rapache back! If you like Rapache, please participate in this! http://wp.me/prBVg-1n
14.04.10
New configuration tutorial for exim4. If you are savvy with exim4, please give me a shout! http://bit.ly/cPYtSP
31.12.09
Finally! Want to set your server up to send emails via your PHP scripts? Check out my tutorial on Exim4 on Ubuntu! http://wp.me/ppEQZ-4d
29.12.09
Have you ever wanted to create your own personal URL shortening/re-direct service? Here's a very simple how-to: http://tinyurl.com/ykgx79l
24.12.09
Merry Christmas to everyone!
14.12.09
Check out this cool forum script running on a text file database! No mysql database needed! Myupb is this and more. http://tiny.cc/myupb
11.12.09
Concrete 5 – A really cool, easy to use CMS script! Start building your website with this free app! http://tiny.cc/dWncn
03.11.09
I decided to start my own IRC channel since I'm on it quite often anyways. Join me on channel #myownserver.info .
16.09.09
Tutorials on creating your own bittorrent setup is finished! Read more at http://tinyurl.com/bittorrent-how-to
16.09.09
Make your own torrent server and tracker tutorial coming soon!
15.09.09
Finished posting Drupal 6.13 on XAMPP tutorial. http://tinyurl.com/drupal613
14.09.09
I re-wrote the port forwarding tutorial and added a video tutorial to it as well. http://tinyurl.com/portforwardingtutorial
13.09.09
Can you make PHP 5.2 and PHP 5.3 run on a single Apache2 server? If so, PLEASE contact me and share how to do so! Thanks.
12.09.09
XAMPP 1.7.2 Hybrid project completed and was successful. Read the results at http://tinyurl.com/xampp172-hybrid
11.09.09
Hybrid XAMPP . . . I really need a life. Read about it at http://tinyurl.com/hybridxampp
11.09.09
@adriandenoon At Drupal, read this: http://tinyurl.com/nobaddrupal . Although, I'm writing a new post with encouraging news now!
11.09.09
@adriandenoon I've already got a tutorial on installing WordPress. . . http://tinyurl.com/l22jbw Not sure what platform you're on though.
10.09.09
I need some ideas for some tutorials. Is there something you want to see? Send me a message and I'll look into it!
Make a Donation
This site does not run ads nor does anyone fund it. The owner and author is unemployed and pays for it himself, so if you're feeling generous, please make a donation of any amount to help out. Thank you very much.

Powered by easy paypal donation

Survey
Which is better?
 
Search
User Login



Visitors


Countries

31.2%United States United States
8.4%United Kingdom United Kingdom
7.4%India India
4.4%Australia Australia
4.2%Canada Canada

Visitors

Today: 40
Yesterday: 152
This Week: 827
Last Week: 1121
This Month: 4731
Last Month: 4987
Total: 49962


JoomlaWatch Stats 1.2.9 by Matej Koval