Jump to content

DocumentRoot..issues...i suppose


play_

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

 

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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)

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.