Wanting to create alias directories to point to project on different drive
Posted by: cmegown (---.wi.res.rr.com)
Date: September 13, 2012 06:51AM

Hey folks, bear with me here while I try to explain what I want to do smiling smiley

I have WAMP installed on my C drive, but want to have access via alias directories to projects on my D drive (for source control purposes). I've been reading around and it seems like alias directories are the solution, but I've tried and I'm getting nothing but Access Forbidden messages. I'm not even 100% sure I'm setting the alias up right so I'll go through the steps right here:

Left-click tray icon > Apache > Alias directories > Add an alias. From there I get a prompt to enter in an alias (which in this case I'll call 'projects'). So I enter in 'projects' and press enter. Then it asks for the path to the project I want to point to, so I enter in D:/projects/. WAMP restarts fine and then I enter in localhost/projects/ in my browser and I'll get the Access Forbidden error.

I'd love some feedback and assistance here, thank you!

Options: ReplyQuote
Re: Wanting to create alias directories to point to project on different drive
Posted by: cmegown (---.wi.res.rr.com)
Date: September 13, 2012 07:09AM

Also, it's worth noting that localhost/ and phpmyadmin/ both work perfectly fine. I think it has something to do with the fact that I'm trying to access files on a different drive?

Options: ReplyQuote
Re: Wanting to create alias directories to point to project on different drive
Posted by: RiggsFolly (---.as13285.net)
Date: September 13, 2012 10:31AM

I think you would be much better setting up a virtual host for each of your other projects.

Here is a HOWTO I have been working on, where I have used C:\website you can change it to be D:\



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
</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 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: Wanting to create alias directories to point to project on different drive
Posted by: stevenmartin99 (Moderator)
Date: September 13, 2012 04:52PM

alias is fine to use, but there is a bug in latest wamp creating alias.

dont bother to use the menu to create an alias,

just goto c:\wamp\alias

make a copy the phpmyadmin file and rename it to whatever you like, then open it and edit the two paths
and the two alias names

save and restart wamp.

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

Options: ReplyQuote
Re: Wanting to create alias directories to point to project on different drive
Posted by: cmegown (---.wi.res.rr.com)
Date: September 14, 2012 12:18AM

Excellent answers!

@RiggsFolly thank you for your highly detailed answer smiling smiley that actually solves another question that I was going to ask as well!

@stevenmartin99 that worked perfectly! Thank you!

Options: ReplyQuote
Re: Wanting to create alias directories to point to project on different drive
Posted by: roshnit (---.npg.sta.suddenlink.net)
Date: November 06, 2012 01:51AM

My config file looks like this before I did anything to it

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>



Now it looks like this


<VirtualHost *:80>
ServerName localhost
DocumentRoot D:/www
ErrorLog D:/www/logs/error.log
CustomLog D:/www/logs/access.log common
</VirtualHost>

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



It sends me to a page when i go to localhost and I don't get any errors, but the files are not showing up. I want to use this as a directory to that shows multiple project I am working on stored in my external drive.

Options: ReplyQuote
Re: Wanting to create alias directories to point to project on different drive
Posted by: selwynpolit (---.dyn.grandenetworks.net)
Date: July 10, 2013 10:24PM

I have been doing battle with wampserver 2.2 (64 bit) and Windows 8. I want a virtual host file setup which would let me use a local site called mytest.com. I've been following the excellent directions here and finally got it working. I thought I would share my success! yay!

btw - my box has tcpip 6 installed so that is why the Allow from ::1 is sometimes required.

Also it is necessary to create all the directories before apache will actually run. One of the most useful clues I got was to go to a cmd prompt, find httpd.exe and type httpd. It spits out useful info about what is wrong with the conf files like:

C:\wamp\bin\apache\apache2.2.22\bin>httpd
Syntax error on line 14 of C:/wamp/selwyn-includes/httpd-vhosts-selwyn.conf:
order not allowed here


This is what my httpd-vhosts.conf files looks like:

<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "c:/wamp/www">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
# You would never want a remote user to see this
</Directory>
</VirtualHost>


<VirtualHost *:80>
ServerName mytest.com
DocumentRoot "c:/websites/site1/htdocs"
ErrorLog "c:/websites/site1/logs/error.log"
CustomLog "c:/websites/site1/logs/access.log" common

<Directory "c:/websites/site1/htdocs">
Options All
Allow from all
AllowOverride All
</Directory>
</VirtualHost>

Options: ReplyQuote


Sorry, only registered users may post in this forum.