What is Web Root

Okay, this is my dumb question for the month (or maybe year)…

What is the “Web Root”?

Where is it at?

What does it describe?

What does it hold?

(Am having a debate with some rude developer and want to get a solid grounding in what terms really mean…)

Debbie

It is a particular folder on the web server but can be a different folder for different situations.

For web pages visible on the web the root folder is the one that the domain name itself points to.

If your hosting has multiple domains then each domain will have its own separate folder that is the web root for that domain.

For any scripts that you have running outside of a web page the root will be the top level folder of your account

It sounds like you saying that the “Web Root” is a folder where your physical files reside and are served up on the Internet, right?

(So it is where you would find “index.php”, right?)

Debbie

Yes document root is where your main index.php page goes. In Apache your root directory is defined.
The path entered there will be the landing page / root directory for that domain or IP address.

What would you collectively call either of these…


'/Users/user1/Documents/DEV/++htdocs/03_MySite/'

'/var/www/vhosts/MySite.com/httpdocs/');

Debbie

In Linux you have a root directory, kind of like “my computer” in windows (you can’t go any higher). When you are in the root directory you will see many directories, among them are Users and var.
Apache, which is the webserver will have a virtual host directive (vhosts) that will route a domain name to a vhost.

In Apache you define a path to your vhosts such as /var/www/vhosts/MySite.com/httpdocs/ and /var/www/vhosts/YourSite.com/httpdocs/.

These are your web root, type in MySite.com and you will be directed to MySite.com.
I would guess that in the Apache directives you have a DEV server to try out scripts before going live in the vhosts.

Both /Users/user1/Documents/DEV/++htdocs/03_MySite/ and /var/www/vhosts/MySite.com/httpdocs/ define different web roots.

Typically /var/www/vhosts/MySite.com/httpdocs/ will be what visitors see when they go to mysite.com.

/Users/user1/Documents/DEV/++htdocs/03_MySite/ can be accessed many ways depending on Apache’s httpd.conf file, this is where you develop your site before uploading to the live site.

Basically with Apache you can have unlimited web roots as defined by the virtual host directive.

I have no clue what you are trying to say, and that didn’t answer my question, but thanks anyways! :lol:

Debbie

A root is the starting point at which branches form.

A root folder is the main folder that contains all other subfolders/files. It is the highest point in the hierarchy. When a root folder contains subfolders, it can be called a folder tree.

The web root folder is the folder that is publicly accessible on the Internet. It typically has some sort of index/default page, but it certainly isn’t a requirement.

Each domain/subdomain has its own web root. For a particular domain where a webpage/website is hosted, the web root can be named any number of different things, depending on how the host is configured, such as:

  • htdocs
  • www
  • wwwroot
  • httpdocs
  • http_public

For your MySite.com example, the httpdocs folder is that domain’s web root.

As far as visitors are concerned, they never see the web root’s folder name or where the web root folder is located on a server. They only have access to the contents of the web root folder after visiting a domain (or IP address, in some cases).

Okay.

So, then, what would you collectively call these…


'http://local.dev3/'

'http://www.MySite.com/'

Debbie

Domain, server, address, web address, URL, website…etc. I’ve referred to them and heard others refer to them by any number of terms–usually depending upon the person’s knowledge or the context of the conversation.

And I suppose some would also call it a web root, because it accesses the root of the website in question. Although, it’s not very common to use that in this context. The term “web root” is commonly used when administering a server or host account–the stuff behind the scenes which a visitor wouldn’t see.

How about “BASE_URL” ??

And I suppose some would also call it a web root, because it accesses the root of the website in question. Although, it’s not very common to use that in this context. The term “web root” is commonly used when administering a server or host account–the stuff behind the scenes which a visitor wouldn’t see.

I was a victim of that until this weekend.

So “WEB_ROOT” should be reserved for describing where my web files are physically stored on the Webserver, right?

Thanks,

Debbie

That’s usually attributed to the domain of your website, but it can vary. It is how outside visitors access what would be the web root of your website.

Content Management Systems usually need this defined somewhere in the settings panel so they can find and serve supporting files and folders to visitors (ie, CSS files in the <head>).

If you configure a CMS in a subfolder of your web root, then the base URL will change to something like this: http://example.com/mysubfolder

So “WEB_ROOT” should be reserved for describing where my web files are physically stored on the Webserver, right?

Correct.

Or if you set up a “Virtual Host” on your laptop - like I did - then it would be…

http://local.dev3/

Correct.

Glad I got that straightened out!

Thanks,

Debbie

Just to clarify (people seem to be all over the place on explaining it) web root is simply the physical directory on the server OS that your HTTP server is treating as root (/) for the domain.

A while ago I needed the web root on a host that wouldn’t provide it… so I wrote some PHP to figure it out. Mostly it’s a matter of just stripping FILE from the end of $_SERVER[‘PHP_SELF’] thus:


function webRoot() {
	return str_replace(
		$_SERVER['PHP_SELF'],
		'',
		/* correct for windows slashes */
		str_replace('\\\\','/',__FILE__) 
	);
}

Simple little test proggy:


echo '<pre>
PHP_SELF : ',$_SERVER['PHP_SELF'],'
__FILE__ : ',__FILE__,'
Web Root : ',webRoot(),'
</pre>';

To show it in action… run on XAMPP on my win7 machine I get this for output:


PHP_SELF : /webRoot.php
__FILE__ : C:\\web\\webRoot.php
Web Root : C:/web

Note the slash reversal… Windows using the opposite slash of the *nix world can be annoying at times.

Run from my old server (debian+ISPConfig):


PHP_SELF : /webRoot.php
__FILE__ : /var/www/web3/web/webRoot.php
Web Root : /var/www/web3/web

Run from my new hosting location (freeBSD, ngnix with passthrough to apache):


PHP_SELF : /webRoot.php
__FILE__ : /home/cutcodedown/public_html/webRoot.php
Web Root : /home/cutcodedown/public_html

With it changing from host to host and OS to OS and even *nix distro to *nix distro, it’s really best to pull the value automatically with a script like this… only problem is, a handful of faulty windblows php setups don’t report PHP_SELF properly… Pretty much I say “OH WELL” on that. Care also has to be taken as some mod_rewrite rules can screw it up as well.

Oh, in theory this should be the job of $_SERVER[‘DOCUMENT_ROOT’], but it returns the subdirectory currently being run from, not the actual http server root… and if the php configuration files are set wrong, it outputs total unreliable gibberish. I’ve never been able to use the value returned by DOCUMENT_ROOT in a meaningful manner.

Even when it works right, it doesn’t return web root, just doc root… you run it in \web\ est\webroot.php DOCUMENT_ROOT will sometimes return \web, sometimes return \web\ est, sometimes return \, sometimes return nothing at all, and I’ve seen it on occasion return total gibberish like a randomly generated hash.