play_ Posted October 6, 2008 Share Posted October 6, 2008 Alright. This is all in my local machine (localhost). I use WAMP. I have a 'www' folder. That's the DocumentRoot (DocumentRoot "S:/sites/www/") now, inside 'www', i have folders of the sites i work on. let's say siteA, siteB, siteC, siteD,etc Sometimes i get path issues (with php) when using includes and stuff. For example, if i link something to '/', it goes to 'www', not 'site#'. So what i usually have to do is, if i wanna work on siteB, i have to change apache's DocumentRoot to DocumentRoot "S:/sites/www/siteB/"....and do this for every time i work on a site. is there a way around this? Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/ Share on other sites More sharing options...
corbin Posted October 6, 2008 Share Posted October 6, 2008 Hrmmmm three solutions I can think of: virtual hosts for each site. (hosts file or something could be used if you didn't feel like making a ton of hosts on no-ip or something.) Or, you could do something like: define('ROOT', dirname(__FILE__)); In the first file the site is accessed through if that makes sense, and then just use that in the include path. Or, you could use relative includes. Hrmmm, what else could you do.... You could use wildcard subdomains and make it do, sd.site.tld go to /docroot/sd/. I'm out of ideas. Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-657904 Share on other sites More sharing options...
play_ Posted October 6, 2008 Author Share Posted October 6, 2008 How would i go go about Virtual Hosts? I've read this: http://httpd.apache.org/docs/2.0/vhosts/name-based.html So i tried something like this: <VirtualHost *:80> ServerName siteA DocumentRoot C:\www\siteA </VirtualHost> then i go to 12.356.67.89/siteA but it doesnt work (of course i replace those numbers with my IP) If i were to get rid of the <virtualhost> block, and just typed 'localhost' or my IP address in my url bar, it works. it lists folders inside 'www'. Any help? Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-657946 Share on other sites More sharing options...
trq Posted October 6, 2008 Share Posted October 6, 2008 Given the above example you would simply type http://siteA in your address bar. Of course you will also need to add an entry to your hosts file. eg; 127.0.0.1 siteA Sorry, not being a windows user I'm not sure where the hosts file is stored on windows. You'll need to search for a file called hosts. Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-657949 Share on other sites More sharing options...
play_ Posted October 6, 2008 Author Share Posted October 6, 2008 Thank you, Thorpe. That worked perfectly. And for anyone reading this in the future, the host file in windowsXP is in: C:\WINDOWS\system32\drivers\etc\ But what if i want other people to see? I mean, the server is live because when i type in my IP, directory listing 'www' shows. What if i wanna show someone siteA? (i tried typing my ip followed by /siteA...but siteA is not root that way) Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-657954 Share on other sites More sharing options...
wildteen88 Posted October 6, 2008 Share Posted October 6, 2008 I had a similar issue to this, however I solved it by using the mod_userdir module.It allowed me to use the following url: http://11.22.33.44/~sitename/ to access whatever site I had setup in my virtualhosts when using an IP address to access the Server. Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-658192 Share on other sites More sharing options...
play_ Posted October 6, 2008 Author Share Posted October 6, 2008 Hi Wildteen, I actually went through this page: http://httpd.apache.org/docs/2.0/mod/mod_userdir.html but still don't seem to be getting it to work. Apache won't even start after i try. Could you show me how you did it? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-658323 Share on other sites More sharing options...
corbin Posted October 7, 2008 Share Posted October 7, 2008 UserDir disabled UserDir enabled site1 site2 site3 UserDir /path/to/site/directories/ That should do it. Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-658625 Share on other sites More sharing options...
play_ Posted October 7, 2008 Author Share Posted October 7, 2008 naw =( here's the config: ------------------------ NameVirtualHost *:80 <VirtualHost *:80> ServerName localhost DocumentRoot S:\sites\www </VirtualHost> <VirtualHost *:80> ServerName purrr DocumentRoot S:\sites\www\purrr </VirtualHost> <VirtualHost *:80> ServerName decay DocumentRoot S:\sites\www\decay </VirtualHost> <VirtualHost *:80> ServerName sushie DocumentRoot S:\sites\www\sushie </VirtualHost> ------------------------ Just in case if it helps. Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-658665 Share on other sites More sharing options...
trq Posted October 7, 2008 Share Posted October 7, 2008 Have you got any domain name pointing to this machine? You could simply make the sites a subdomain of the current domain. eg; NameVirtualHost *:80 <VirtualHost *:80> ServerName localhost DocumentRoot S:\sites\www </VirtualHost> <VirtualHost *:80> ServerName purrr.yourdomain.com DocumentRoot S:\sites\www\purrr </VirtualHost> <VirtualHost *:80> ServerName decay.yourdomain.com DocumentRoot S:\sites\www\decay </VirtualHost> <VirtualHost *:80> ServerName sushie.yourdomain.com DocumentRoot S:\sites\www\sushie </VirtualHost> Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-658670 Share on other sites More sharing options...
play_ Posted October 7, 2008 Author Share Posted October 7, 2008 Shouldn't i be able to do something like that with my IP? For example: <VirtualHost *:80> ServerName 122.111.22/sushie DocumentRoot S:\sites\www\sushie </VirtualHost> I don't see why that wouldn't work, but it doesn't. I mean it works, but, S:\sites\www\sushie isn't the root..the root is 'www'. (i test by having <?php echo $_SERVER['DOCUMENT_ROOT']; ?> on the index file of each site. Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-658733 Share on other sites More sharing options...
corbin Posted October 8, 2008 Share Posted October 8, 2008 That's an invalid ServerName is why.... Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-659576 Share on other sites More sharing options...
play_ Posted October 8, 2008 Author Share Posted October 8, 2008 Well it's actually my IP. I just didn't wanna write it to the public =P Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-659700 Share on other sites More sharing options...
corbin Posted October 8, 2008 Share Posted October 8, 2008 I mean the /sushie part is invalid. Quote Link to comment https://forums.phpfreaks.com/topic/127178-documentrootissuesi-suppose/#findComment-659799 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.