Welcome Guest, Not a member yet? Register   Sign In
local dev environment - changing wwwroot determined by port
#1

[eluser]drewbee[/eluser]
Hello All,

I have multiple projects, each of which exist at the root on my local machine but exist on completely separate entities out in the web.

Also, I am running WAMP but all of this should be taken care of by the apache config directive.

I want to setup a type of routing with the http.config but not sure if it is possible. Let's say I have the following structure

wwwroot/Project1
wwwroot/Project2
wwwroot/Porject3

What I need to happen, lets say based on the port given to change the webroot directive to actually be at the given project

so http://localhost (default, point to www/Project1)
http://localhost:81 (point to wwwroot/Project2)
http://localhost:82 (point to wwwroot/Project3)

so on and so forth. Is this possible to do? Maybe with htaccess? Searching has led me no results anywhere.

If anyone else has some suggestions on this one, please let me know.

I am not looking to redirect or anything like that, as I want the subfolder to truly be the 'document root' of the current instance.

Right now I actually go into the apache httpd.config and edit the webroot value, and restart the server.

Edit again. Maybe I can use virtual hosts to toggle between the different roots. I just happened to stumble across this document:
http://httpd.apache.org/docs/1.3/vhosts/examples.html
#2

[eluser]drewbee[/eluser]
Looks like this may be what I am looking for:
Code:
Listen 80
    Listen 81
    Listen 82

    NameVirtualHost 192.168.1.1:80
    NameVirtualHost 192.168.1.1:81
    NameVirtualHost 192.168.1.1:82

    <VirtualHost 192.168.1.1:80>
    ServerName localhost
    DocumentRoot /wwwroot/Project1
    </VirtualHost>

    <VirtualHost 192.168.1.1:81>
    ServerName localhost
    DocumentRoot /wwwroot/Project2
    </VirtualHost>

    <VirtualHost 192.168.1.1:82>
    ServerName localhost
    DocumentRoot /wwwroot/Project3
    </VirtualHost>
#3

[eluser]TWP Marketing[/eluser]
drewbee,
I use a WAMP also ( UniformServer.com ) and the following configuration of httpd.conf and the windows hosts file:

Code:
httpd.conf
...
# GADGETSFORGOLD
<VirtualHost *>
ServerName GadgetsForGold.com
DocumentRoot /www/gfg
</VirtualHost>
# TWP MARKETING
<VirtualHost *>
ServerName TWPMarketing.com
DocumentRoot /www/twp
</VirtualHost>
# STOPBRITE
<VirtualHost *>
ServerName Stopbrite.com
DocumentRoot /www/sb
</VirtualHost>
# UG_Manager
<VirtualHost *>
ServerName UGM.com
DocumentRoot /www/ugm
</VirtualHost>

hosts
...
127.0.0.1 localhost
127.0.0.1 localhost:80
127.0.0.1 GadgetsforGold.Com
127.0.0.1 StopBrite.com
127.0.0.1 TWPMarketing.com
127.0.0.1 UGM.com

The hosts file uses only one port (in case you have other apps needing port access.) It allows me to reference my dev sites by actual full domain name instead of http://localhost/...

The DocumentRoot for my installation is "/www/" which will vary depending on your apache configuration. Yours is apparently something like: "/wwwroot/". Season to taste...

NOTE: the first two lines of the hosts file seem to be required to correctly resolve the domain names, they must be the first two lines. It caused me some grief and lost time before a kind developer revealed the secret to me...




Theme © iAndrew 2016 - Forum software by © MyBB