Jump to content

DOCUMENT_ROOT


iwato

Recommended Posts

QUESTION: To what does the following echoed result refer, the location of

echo $_SERVER['DOCUMENT_ROOT']; // Output:  '/Applications/MAMP/htdocs'

  1. my webserver
  2. my php interpreter
  3. my user folder (directory)
  4. something else altogether

IMPORTANT OBSERVATION: I know to where the result is pointing; I am trying to understand from where it is pointing -- i.e., what comes before the first forward-slash.Roddy

Link to comment
Share on other sites

Before the first forward slash? The first forward slash refers to the system root - there is nothing higher than that.

Link to comment
Share on other sites

On Windows, each drive is marked with a letter, like "C:", "D:", etc. so that you know which drive a path comes from.On UNIX based OSes, MAC OS X included, you have a system root (the place where all devices come from... so to speak), located at whatever your system drive is. The folders you have at the system root by default are also on the system drive. You can map any device to any path from the system root, so that you may then refer to the contents of that device with that path as a start. On GUIs or command lines, the device path will be seen as a new folder.I don't really work with UNIX OSes, but if memory serves, the convetion is to place devices in the "dev" folder, so that you can clearly distinguish contents on other devices from that of your system drive. Since this is just a convetion, you can always map them to another path of course.

Link to comment
Share on other sites

When Unix machines refer to devices they're talking about hardware. /dev contains entries for the various physical hard drives, logical drives and arrays, CD drives, RAM, etc. Those are the hardware devices. Many applications get installed into /etc or in a user folder under /usr. On of my servers, for example, Apache is installed in /etc/httpd and /usr/local/apache.

Link to comment
Share on other sites

QUESTION: To what does the following echoed result refer
echo $_SERVER['DOCUMENT_ROOT']; // Output:  '/Applications/MAMP/htdocs'

Based upon what everyone has said, it appears that the DOCUMENT_ROOT as defined by the superglobal $_SERVER in my current MAMP environment refers to the path between my system folder and the folder that contains my website. Is this a correct statement?If not, could someone please clarify.If so, were I to change the location of my website -- namely, the directory folder that includes my PHP, HTML, and other documents --, how would I go about redirecting my system folder to the new location of my website? Would it be simple of matter of reassignment? Say,$_SERVER['DOCUMENT_ROOT'] = 'new path';Or, would other additional adjustments be necessary?Roddy
Link to comment
Share on other sites

PHP fills its $_SERVER['DOCUMENT_ROOT'] variable by a php.ini setting called "doc_root". In manual PHP installations, you need to alter php.ini yourself if you need this variable, but MAMP does it for you.Apache however checks its configuration file httpd.conf instead, and the DocumentRoot directive to be exact. You need to edit that, and restart Apache if you want to truly alter the document root... the PHP setting is a pseudo copy in case PHP runs as (F)CGI, because in that case, PHP doesn't have access to Apache's settings.

the path between my system folder and the folder that contains my website. Is this a correct statement?
Pretty much... if you add Aliases and rewrites into the definition, it becomes slightly more complex... a more correct definition in that case would be "The path between the system folder and the folder that contains files and folders, used in the absence of matching aliases and rewrite rules."
Link to comment
Share on other sites

PHP fills its $_SERVER['DOCUMENT_ROOT'] variable by a php.ini setting called "doc_root". In manual PHP installations, you need to alter php.ini yourself if you need this variable, but MAMP does it for you.
When I call the get_cfg_var() with its $option parameter set to 'doc_root', I discover that this option is empty. Also, I am still unclear about the difference between the configuration settings obtained from get_cfg_var() and those obtained from get_ini(). In this regard, I have three specific questions:
  1. From where do these two functions draw their information?
  2. Is there a way to trace the route taken by these functions?
  3. Does the source of information change with regard to configuration and runtime?

To whatever extent possible please address the MAMP operating environtment in your answers.

Apache however checks its configuration file httpd.conf instead, and the DocumentRoot directive to be exact. You need to edit that, and restart Apache if you want to truly alter the document root... the PHP setting is a pseudo copy in case PHP runs as (F)CGI, because in that case, PHP doesn't have access to Apache's settings.
Yeah, I even found discovered the way to do it -- well, at least in part.
Pretty much... if you add Aliases and rewrites into the definition, it becomes slightly more complex... a more correct definition in that case would be "The path between the system folder and the folder that contains files and folders, used in the absence of matching aliases and rewrite rules."
Thank you for the pat on the back.Really, it helps!Roddy
Link to comment
Share on other sites

1. It seems get_cfg_var() reads the values supplied at run time (i.e. via php.ini), while ini_get() reads the currently active values (after the different configuration stages have been merged).2. AFAIK, nothing from the PHP level... you can always manually look at PHP's source of course.3. There are three types of configuration, each overriding the previous - compile time, process start time, run time. The first is clear, the second and third stage are basically the same thing when you run PHP as CGI (well... not technically, but the difference can't be observed), because the PHP process starts and ends with each HTTP request. When you run PHP as an Apache module, the PHP process starts and ends alongside Apache, while the runtime starts with the actual HTTP request. If you run PHP from the command line, the arguments on the command line supply the process start time configuration.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...