virtual hosts and projects
Posted by: mrling (---.1scom.net)
Date: March 01, 2013 03:01AM

I have wampserver set up and when i type localhost into my browser, the wamp index page displays (/wamp/www/indexphp/). On this page there is a section for 'Your Projects' and 'Your Virtual Hosts' towards the bottom. When creating file in the '/wamp/www/' directory, it will show up in 'Your Projects'. Also, if you create a 'vhosts' folder and .conf file in the wamp directory (ex: /wamp/vhost/mysite.conf), then you will see this in 'Your Virtual Hosts'. So, I was wondering if anybody could explain to me the purpose of these two directories, and why someone should use "Your Projects" rather than "Your Virtual Hosts" ... or vice versa?



Edited 1 time(s). Last edit at 03/01/2013 03:01AM by mrling.

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: RiggsFolly (---.as13285.net)
Date: March 01, 2013 11:06AM

Now thats strange, in all the time I have been using WAMP I had never noticed that Vistual Hosts section, Duh.

Ok this is the difference between 'Your Projects' and 'Your Virtual Hosts'

Your Projects
Will list any folder that exists below the c:\wamp\www folder as a clickable link to
http://localhost/[folder name]

Your Virtual Hosts
Lets say you have created a Name Virtual Host for a few of your projects.
Lets say your virtual hosts have these url's
'site1.dev'
'site2.dev'
Now the folder holding those vistual hosts could be anywhere on your system, in fact I always create a vhosts for each project and store my virtual hosts outside the WAMP folder structure so I dont have to worry when I upgrade WAMP.

If you create a folder c:\wamp\vhosts and place a file in there called
site1.dev.conf and
site2.dev.conf

You dont put the actual directory holding the site in that folder, just a file with the extension .conf and a name that matches your virtual hosts url. Wamp will then generate a link to each of those url's so you can click on it from this page and launch that site.






Hope this helps

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: mrling (---.1scom.net)
Date: March 01, 2013 11:48AM

Thank You! Thank You! Thank You! Exactly what I needed to know.

Just to make sure I got it right, you say that you don't put your site's folder in the vhost directory, so you put it in the 'wamp/www/site1' directory? Vhost simply allows wamp to link to the site as 'mysite1' in the browser rather than '/localhost/mysite1'?

Also, what is the purpose of having 'dev' in the 'site1.dev.conf' file name? Right now my site is showing up on the '/wamp/www/index.php' page using 'mysite.conf' file in the vhost folder.

I was watching a tutorial with regard to the .conf files in the vhosts folder, and they put a directory address inside it with some code...should i do this or is it ok to just create the file?

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: RiggsFolly (---.as13285.net)
Date: March 01, 2013 12:41PM

First lets see a link to the tutorial you are viewing. Like I say I never used this before and I just took a look at the WAMP code and made a few extrapolations and a test or two.

Sites I develop:
Actually I never put my sites under the c:\wamp\www folder so if I upgrade wamp my site code is safely away from any likelyhood of accidental deletion. I have a totally seperate folder d:\websites\www into which I put a different folder for each site I develop

So
d:\websites\www\MyFirstWordPressSite
d:\websites\www\MyFirstJoomlaSite
d:\websites\www\etc etc etc

Then I setup a VHOST for each site.
I think that I am more likely to end up with code that will easily transfer to the live hosted site this way. By that I mean its less likely I am going to make the basic boob of using a directory path or something like that that will not transfer to the live environment.

I like to use MyFirstWordPressSite.dev, MyFirstJoomlaSite.dev etc etc but thats only my convention you can actually use anything for the top level domain name. I use .dev to identify that its a development site because I also create a seperate folder with that same site in so my clients can UAT the development, which is addressed via another VHost address MyFirstWordPressSite.uat.

I can then setup a dynamic dns link using dyndns to that uat site so clients can remotely UAT my work.

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: mrling (---.1scom.net)
Date: March 01, 2013 12:58PM

Here is the tutorial I mentioned: [www.geekgumbo.com]

At the very end is the part that concerns putting code in the 'vhosts/mysite.conf' file.

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: RiggsFolly (---.as13285.net)
Date: March 01, 2013 01:19PM

I guess something may have changed since the tutorial was written or he just got it wrong.

There is no code that actually looks inside the vhosts/*.conf files. All that is used to generate the vhosts name is the filename itself.

I have just setup all my vhosts to appear in this section of the wamp home page and my conf files do not contain anything. Just make the name of the file match your vhosts name.

so site1.dev.conf will generate a link in that sections to site1.dev

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: RiggsFolly (---.as13285.net)
Date: March 01, 2013 01:23PM

Just for interests sake here is my HowTo Create vhsost in wamp Tutorial



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.localhost to make it obvious to me that I am dealing with my localhost copy of a site, you may prefer another notation, thats ok, the word localhost has no actual defined meaning in this case, its just my way of naming my development versions of a live site.


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
	    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.
	</VirtualHost>

	<VirtualHost *:80>
	    DocumentRoot "C:/websites/site1"
	    ServerName site1.localhost
	    Options Indexes FollowSymLinks
	    <Directory "D:/websrc/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
		</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 of your sites, so leave it OFFLINE.
If you want to put one or more sites online you will have to change the Allow commands MANUALLY in this my-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

5. Add a line under these to include your vhosts file, this will cause apache to register their existance.
Leave the origial httpd-vhosts.conf unchanged, it may serve as a useful reference if you get something wrong.
Also make a backup of this file as if you re-install or upgrade wamp it may be lost.
example:
Include conf/extra/my-vhosts.conf

6. 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

<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) and your internal network.
P.S. Your internal network will probably be something like 192.168.x.y, check your system first!


7. Now in order for your browser to know how to get to these new domain names i.e. site1.localhost and site2.localhost, 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
and is a file called "hosts", 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.localhost
   127.0.0.1   site2.localhost
NOTE: You will need to add lines to this file for each new virtual host site you create.



8. In order for Apache to pick up these changes you must bounce apache.
Do this by: Wamp manager -> Apache -> Service -> Restart Service


You should now be able to use the address site1.localhost 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.localhost ) 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: virtual hosts and projects
Posted by: mrling (---.1scom.net)
Date: March 03, 2013 12:20AM

Great info RiggsFolly! I printed a copy of your tutorial. Question: So you like to put your website in a directory outside of wamp to keep it save from upgrade deletion, but do you also keep a copy in the \wamp\www\ folder? Or do you use this directory just for the wamp index.php file?

Also I was wondering, shouldn't the directory and document root be the same for the second vhost in the httpd-vhosts.conf file from step 3? The document root points to "C:/websites/site1" while the directory points to "D:/websrc/www/site1".



Edited 1 time(s). Last edit at 03/03/2013 01:01AM by mrling.

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: mrling (---.1scom.net)
Date: March 03, 2013 05:42AM

@RiggsFolly
I was finally able to setup a vhost in the /wamp/www/mysite/ directory, but when I tried to do what you did, and set it up on my external D partition (d:/websites/mysite/), it didn't work. Whenever I typed the host into the address bar in firefox, it says;

"The address wasn't understood"

"Firefox doesn't know how to open this address, because the protocol (d) isn't associated with any program."

"You might need to install other software to open this address."

Did you ever get this message or know what it's talking about?

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: RiggsFolly (---.as13285.net)
Date: March 04, 2013 11:26AM


Great info RiggsFolly! I printed a copy of your tutorial. Question: So you like to put your website in a directory outside of wamp to keep it save from upgrade deletion, but do you also keep a copy in the \wamp\www\ folder? Or do you use this directory just for the wamp index.php file?


No copy in the wamp\www folder. That will now only be looked at for the WAMP home page.



Also I was wondering, shouldn't the directory and document root be the same for the second vhost in the httpd-vhosts.conf file from step 3? The document root points to "C:/websites/site1" while the directory points to "D:/websrc/www/site1".


Nice catch, thats a error in my doc that nobody else found yet. Thanks. You are correct both should point to the same disk/folder. I have corrected for fuure use.




I was finally able to setup a vhost in the /wamp/www/mysite/ directory, but when I tried to do what you did, and set it up on my external D partition (d:/websites/mysite/), it didn't work. Whenever I typed the host into the address bar in firefox, it says;

"The address wasn't understood"



Ok you are not understanding.

Using my example, I have created a domain name called site1.localhost that lives on my PC. It is only known to me PC. My PC knows about it because I placed its name in the HOSTS file and said its ip address was 127.0.0.1. So to access it from the browser you would enter

http://site1.localhost

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: cnoevil (---.adsl.catt.com)
Date: March 13, 2013 02:40AM

Greetings RiggsFolly,

Wow, what can I say? I have followed your instructions to the "T" , scoured the Apache docs for some insight on Virtual Hosts, Googled it and spent the past 3 evenings pulling my hair out trying to get this to work, but no joy.

The wampserver try icon turn orange and that's the end of it. I have tested it in the browser and nothing comes up, not even localhost.

However, if I reverse everything that I've edited, Wampserver runs like a champ. I really would like to get my head around this since I am trying to learn how to write php apps and wrangle Apache server well enough to do basic administration tasks. It's really starting to make me feel stupid and defeated.

Running Windows 7 Home Premium using Wampserver 2.2.

Any advice or clues to steer me ... oh I don't know...somewhere productive?

Thanks,
Mark

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: RiggsFolly (---.as13285.net)
Date: March 13, 2013 03:01AM

Any advice or clues to steer me ... oh I don't know...somewhere productive?

Well if we are going to get into snyde comments.... may I suggest quill pen and paper !!

Ok other have followed that tutorial and got themselves working with vhosts, but I admit it is probably not perfect.

Point 1: If the wamp manager tray icon stays Orange, then there is no point going any further, apache has not started due to one of more errors in the vhost settings.


Have you looked at the APache Error log?

Have you looked at the Windows Event log?


Have a look at both and if you dont understand the errors you see ( or there are none ), paste your vhost config along with an example of each error from either of the above and I will give it the once over.


If that does not work maybe we can organise a TeamViewer session and I can help you through the process by sharing your screen and watching whats going on. I am on GMT and am available most days 9:00 to 21:00.

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: cnoevil (---.adsl.catt.com)
Date: March 13, 2013 03:12AM

Oh for sure I wasn't complaining about your tutorial. It's very well organized and thorough, in fact, I've been all over the web and found tutorials very much like your own here but less informative and they all seem to be having success. It's just me who is failing.

I have checked the Apache error logs and could see anything in there that looked suspicious, but I sure didn't think to check the Windows event logs. Thanks for the idea. I will check there and see if anything turns up.

Mark

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: cnoevil (---.adsl.catt.com)
Date: March 13, 2013 03:44AM

RiggsFolly:

OK, finally something to work with. I did check the windows event viewer (Thanks!) and discovered these errors being thrown by Apache Service. The errors come in pairs, I'm guessing each time that I tried to start wampv and failed. BTW, I did indeed alter the original file instead of making a new one because I had already tried doing this using a different tutorial before I found yours.

The Apache service named
reported the following error: >>>
Syntax error on line 30 of C:/wamp/bin/apache/apache2.2.22/conf/extra/httpd-vhosts.conf:


The Apache service named
reported the following error: >>>
order not allowed here


Here is what's going on in and around line 30 of httpd-vhost.conf

27: <VirtualHost *:80>
28: DocumentRoot "C:/wamp/www"
29: ServerName localhost
30: Order Deny,Allow
31: Deny from all
32: Allow from 127.0.0.1
33: # You would never want a remote user to see this wamp config page.
34: </VirtualHost>


Well, that's pretty much all I have so far. I'll just keep digging and be grateful for any help I can get. Sorry about the mix up, I wasn't being a wise@ss towards you I just get frustrated with my own stupidity and lack of expertise.

Thanks Again,
Mark

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: RiggsFolly (---.as13285.net)
Date: March 13, 2013 10:08AM

Hi Mark,

Dont worry about it, just me getting touchy aftre midnight.

Looks like I spotted the muppet in the equation..... and it was me, I will correct my tutorial !

The error is because I missed a line or two of code, sorry.
The vhost definition for localhost should look like this, with the missing <Directory> block included

<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "D:/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>

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: cnoevil (---.adsl.catt.com)
Date: March 13, 2013 08:43PM

Thank you, thank you, thank you RiggsFolly.

The directory thing fixed it. I need to spend more time learning about Apache.

But for now, I finally have it working, my faith and zeal is renewed and I can go on with my life... :-)

Mark

Options: ReplyQuote
Re: virtual hosts and projects
Posted by: cnoevil (---.adsl.catt.com)
Date: March 14, 2013 03:32AM

Hey RiggsFolly, I just wanted to let you know that I have my virtual host up and running now. Your help was much appreciated and I even have a link to my vhost on the localhost index page provided by wampserver. I tried to send you a thanks earlier but the forum software took it and marked it as possible spam to be released from custody only on the approval of a moderator. What's up with that? I thought it would have shown up by now but since I don't see it yet, I'm trying again. Maybe you'll get to see this one, I don't know.

Anyway, thank you so much!
Mark

Options: ReplyQuote


Sorry, only registered users may post in this forum.