Help with multiple domains on PC
Posted by: S S0DEN (---.beyondbb.com)
Date: August 03, 2013 09:34PM

I have just started using WAMP to host a website on the internet through my desktop PC running Windows 7, it works awesome. I would like to learn how to host multiple domain names on that same PC using WAMP. Can I do this?

I have next to no experience with MYSQL, PHP or Apache so tread lightly - thanks.

Options: ReplyQuote
Re: Help with multiple domains on PC
Posted by: RiggsFolly (---.as13285.net)
Date: August 03, 2013 11:06PM

HowTo: Create Virtual Hosts in WAMP

BEFORE DOING ANY OF THIS PLEASE ENSURE APACHE AND MYSQL ARE WORKING PROPERLY FIRST!!!

1. Create a new folder outside the wamp directory structure.
for example
C:\websites
but this can be on any disk drive visible to the PC running wamp


2. Create a subfolder in c:\websites for each site you want to create.
for example:
C:\websites\site1
C:\websites\site2


3. Edit the file C:\wamp\bin\apache\apachex.y.z\conf\extra\httpd-vhosts.conf
where x,y and z are the version numbers of apache that you actually have installed.

NOTE: If you are switching between 2 or more versions of apache this will have to be done to all your versions of apache in turn.

SUGGESTION: I like to use the format sitename.dev to make it obvious to me that I am dealing with my localhost development copy of a site, you may prefer another notation, thats ok, the word dev has no actual defined meaning in this case, its just my way of naming my development versions of a live site.

NOTE: Remove ot better still comment out ( using the # in column 1 ) the lines that already exists in this file. They are just examples.

example contents:
	#
	# Use name-based virtual hosting.
	#
	NameVirtualHost *:80

	## must be first so the the wamp menu page loads when you use just localhost as the domain name
	<VirtualHost *:80>
    	DocumentRoot "C:/wamp/www"
    	ServerName localhost
    	ServerAlias localhost
    	<Directory  "C:/wamp/www">
			Order Deny,Allow
    		Deny from all
    		Allow from 127.0.0.1
			# You would never want a remote user to see this wamp config page.
		</Directory>
	</VirtualHost>


	<VirtualHost *:80>
	    DocumentRoot "C:/websites/site1"
	    ServerName site1.dev
	    ServerAlias www.site1.dev
	    Options Indexes FollowSymLinks
	    <Directory "C:/websites/www/site1">
			AllowOverride All
			Order Deny,Allow
			Deny from all
			Allow from 127.0.0.1
		    #If you want to allow access from your internal network
		    # For specific ip addresses add one line per ip address
		    #Allow from 192.168.0.100
	    	# For every ip in the subnet, just use the first 3 numbers of the subnet
	    	#Allow from 192.168.0
	    	# If you want to allow access to everyone
	    	#Allow from all
		</Directory>
	</VirtualHost>

Add as many <VirtualHost> as you require so each of your sites have one, changing the DocumentRoot, ServerName and any other of the parameters as appropriate.
This also allows you to make SITE SPECIFIC changes to the configuration.

NOTE: This will make the wamp manager "Put Online" function no longer have any effect on these new vhost'ed sites as the security for each one is now part of the vhost definition, so leave WAMP, OFFLINE.
If you want to put one or more sites online you will have to change the Allow commands MANUALLY in the httpd-vhosts.conf file.

To check your subnet do the following:
Launch a command window, and run
    >ipconfig
Look for the line "Default Gateway" in the output and use the third number in your Allow commands.


4. Edit your httpd.conf file and search for these lines, they are near the bottom of the file.
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

Remove the '#' comment character on this line to Include your newly changed vhosts, this will cause apache to register their existance.
eg
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

5. While still editing your httpd.conf file search for
	#   onlineoffline tag - don't remove
	    Order Deny,Allow
	    Deny from all
	    Allow from 127.0.0.1

	</Directory>
DO NOT CHANGE THESE LINES!

Add the following after the <\Directory> tag to secure your new C:\websites folder.

<Directory "C:/websites/">
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Directory>

This is to set security on your new directory structure so that access to these new sites is only allowed from 127.0.0.1 (localhost) unless amended from within a specific VHOST.
P.S. Your internal network will probably be something like 192.168.x.y, check your system first!


6. Now in order for your browser to know how to get to these new domain names i.e. site1.dev and site2.dev, we need to tell windows what IP address they are located on. There is a file called HOSTS that is a hangover from the days before Domain Name Servers (DNS) were invented. It is a way of giving nice easy rememberable names to IP address's, which of course is what DNS Servers do for us all now.

Edit your HOSTS file, this can be found in C:\windows\system32\drivers\etc , the file does not have an extension.
Windows protects this file so you must be an Administrator to be allowed to save changes to this file.

If you are using VISTA or Windows7/8 you may think you are an Administrator BUT YOU ARE NOT!!!!
So to edit this file you must launch your editor, or Notepad in a specific way to gain Administrator rights. To do this find your editors icon and launch it using the following key strokes:
Shift + Right Click over its icon, this will display a menu, click the item "Run as Administrator", and click "Allow" on the challenge dialog that will appear.

Now you are ready to edit the hosts file so navigate your editor to c:\windows\system32\drivers\etc\hosts

Add the following lines to this file

   127.0.0.1   site1.dev
   127.0.0.1   site2.dev
NOTE: You will need to add one line in this file for each of your new virtual hosts.


7. In order for Apache to pick up these changes you must bounce ( stop and restart ) apache.
Do this by: Wamp manager -> Apache -> Service -> Restart Service


You should now be able to use the address site1.dev in your browser to get to your new sites.
Copy your sites code into the "C:/websites/xxxx" folder if you already have a site coded or,
place a quick and simple index.php file into the "c:\websites\xxxx" folder to proove it all works.

example:
   <!DOCTYPE html>
   <html lang="en-US">
   <head>
   <meta charset="UTF-8">
   <title>SITE1</title>
   </head>
   <body>
   <?php
        echo '<div style="background-color:red;color;white;text-align:center;font-size:18px">HELLO FROM Site1</div>';
   ?>
   </body>
   </html>



TROUBLE SHOOTING:
If you have used the new domain name ( site1.dev ) and it has not found the site.
a. Check the changes to the hosts file.
b. Restart the "DNS Service" that runs in windows. This caches all doman names that you use in a browser so that the browser does not have to query a DNS Server each time you re-use a domain name. This may have cached your failed attempt but a restart is easy and should solve the problem and is quicker that re-booting windows, which should also work.
To do this launch a command window as an Administrator ( Shift + Left Click over the command window icon ) and run these 2 commands.

>net stop "DNS Client"
>net start "DNS Client"
Note: The quotes are required as there is a space in the services name.

Options: ReplyQuote
Re: Help with multiple domains on PC
Posted by: S S0DEN (---.beyondbb.com)
Date: August 04, 2013 12:06AM

Thank you very much, I plan to try and tackle this tonight or Sunday!

Options: ReplyQuote
Re: Help with multiple domains on PC
Posted by: stevenmartin99 (Moderator)
Date: August 04, 2013 08:55AM

i would just like to make a small edit to this great manual.

## must be first so the the wamp menu page loads when you use just localhost as the domain name

this is actually wrong - this section for www should be LAST in the list - NOT first.

If apache cant match any of the vhosts , it selects the first one. - if someone on the web manages to do that , the will get to the www folder and see the wamp menu which is probably not whats intended

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Help with multiple domains on PC
Posted by: RiggsFolly (---.as13285.net)
Date: August 04, 2013 02:15PM

Hi Steven,

Thanks for the input, but that was actually my intension.

Does this make sense?

My thinking was that if/when you open up your vhost sites for external access, any casual drive by ip address hack attempt that did not use one of your actual vhost domain names would get sent to the wamp page due to the Apache default you mention.
As that site is protected by 'Allow from 127.0.0.1 localhost ::1', the hack would receive an 'access denied 403' status. Thus giving a certain amount of protection from casual attack.

Possible it would be a better idea to create a dummy default doman containing nothing rather than use the wamp site to do this as there are far to many suggestions out there to plaster everything with 'Allow from all', but was the basic idea not sound?

Feel free to comment as I was thinking I should update this to include the Apache2.4 security syntax anyway.

Options: ReplyQuote
Re: Help with multiple domains on PC
Posted by: S S0DEN (---.beyondbb.com)
Date: August 09, 2013 09:20PM

I am getting:

Forbidden

You don't have permission to access / on this server.

Domain name is autohobby.us and it simply has a test index.html file on it.

I did everything (I think) the way you outlined, but I think my issue is that the domain name autohobby.us was purchased at network solutions and then pointed at the IP address of my home PC thus allowing me to display that domain from the WAMP server...

What are your thoughts?

Options: ReplyQuote
Re: Help with multiple domains on PC
Posted by: S S0DEN (---.beyondbb.com)
Date: August 09, 2013 10:21PM

Here is what that file now looks like:

#
# Virtual Hosts
#
# 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:[httpd.apache.org];
# 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

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "c:/apache2/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "c:/apache2/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

# Use name-based virtual hosting.
#
NameVirtualHost *:80

## must be first so the the wamp menu page loads when you use just localhost as the domain name
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "C:/wamp/www">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
# You would never want a remote user to see this wamp config page.
</Directory>
</VirtualHost>


<VirtualHost *:80>
DocumentRoot "C:/websites/autohobby"
ServerName autohobby.us
ServerAlias www.autohobby.us
Options Indexes FollowSymLinks
<Directory "C:/websites/www/autohobby">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
#If you want to allow access from your internal network
# For specific ip addresses add one line per ip address
#Allow from 192.168.0.100
# For every ip in the subnet, just use the first 3 numbers of the subnet
Allow from 192.168.0.1
# If you want to allow access to everyone
#Allow from all
</Directory>
</VirtualHost>

Options: ReplyQuote
Re: Help with multiple domains on PC
Posted by: S S0DEN (---.beyondbb.com)
Date: August 09, 2013 11:59PM

I think I found the error here:

<Directory "C:/websites/">
Order Deny,Allow
Deny from all
Allow from 192.168.0.196
</Directory>

I changed it too:
<Directory "C:/websites/">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>

But now I have an error that says:

Not Found

The requested URL / was not found on this server.

If I enter "localhost" in the browser it tries to pull my Vbulletin forums content.php page which has not been uploaded into that new folder (C:\websites\autohobby).

Thoughts now?

Options: ReplyQuote
Re: Help with multiple domains on PC
Posted by: RiggsFolly (---.as13285.net)
Date: August 12, 2013 10:35AM

Ok point 1.


Change this to what follows:

<Directory "C:/websites/">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</Directory>

This covers all the 'THIS PC' situations for IPV4 and IPV6. But only allows access to this PC hence securing against external hacks.



--------------


Now change your vhost config file to this


# Virtual Hosts
# Use name-based virtual hosting.

NameVirtualHost *:80

## must be first so the the wamp menu page loads when you use just localhost as the domain name
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "C:/wamp/www">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
# You would never want a remote user to see this wamp config page.
</Directory>
</VirtualHost>


<VirtualHost *:80>
DocumentRoot "C:/websites/autohobby"
ServerName autohobby.us
ServerAlias www.autohobby.us
Options Indexes FollowSymLinks
<Directory "C:/websites/www/autohobby">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</Directory>
</VirtualHost>


Removing the default dummy-host entries and the duplicated 'NameVirtualHost *:80'
and adding security for IPV6 and IPV4


If this does not work then is suggest





Install TeamViewer and I will troubleshoot for you.

Install TV, then run it.

Do this before attempting a connection.

How to Configure Team Viewer so it does not require port 80 or 443

Run TV
Extras -> Options -> Advanced -> Press the Advanced Button -> Advanced Network Connections

Check the checkbox saying [ Dont use incomming port 80 (recommended for web servers only ) ]
Stop and restart TV.

Then
Send me a Private Message containing the TV ID and PASSWORD so I can connect.
Leave TV running as it will change the password each time you restart it.

I am on UK time (GMT+1) and am normally available 09:00 - 16:00 and sometimes later into the evening.

Options: ReplyQuote
Re: Help with multiple domains on PC
Posted by: S S0DEN (---.beyondbb.com)
Date: August 12, 2013 08:14PM

Before I edit these again, I have a couple questions so I can understand how this whole thing works.

1) How will my domains that I paid for show up on my home PC and be used over the internet for other browsers to pick up? I understand how one domain works, using my PC's real IP address and then assigning that domain to point at that one IP address using the DNS Manager on Network Solutions. But how would multiple domain names be directed where they need to be?

2) I put everything back the way it was, I currently have 1 domain linked and sitting in the "c:/wamp/www/core files to WordPress" - So I will need to redo this thing from scratch to allow me to use my other 3 domains.

3) If or when we get this working, how hard will it be to pull the data from the databases hosted on a shared host through Hostmonster and then import that data on to my newly created database or myphpadmin on my home PC?

My goal is move my sites to this one dedicated home PC and avoid the down times of the shared server through Hostmonster and Network Solutions and avoid paying them a monthly fee when I could do this myself.

Options: ReplyQuote


Sorry, only registered users may post in this forum.