Avatar of tonelm54
tonelm54
 asked on

Get PHP root path

Ive come across this a few times, and I cannot figure it out.

I usually find out where the site is installed using $_SERVER['DOCUMENT_ROOT'], however on some servers it reports the htdocs folder its in, on other it reports its parent folder.

Is there a more reliable way of finding out where the site is located so I can navigate up and go into folders no part of htdocs. For example uploads.

Thank you in advance   
PHPApache Web Server

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Bembi

Everything you can see from the web site perspective is ralative to your own root path.
If you want to now what is behind it, you have to go behind the sceenes and inspect the connected php settings.
I  would assume, this you will not be able to see, but your provider may possibly tell you. 
The php documents root is either a general php directrive or - as far as your provider allows to change it  - a web specific directrive. This can differ of course form provider to provider.
But what you get from the web site perspective is what your provider defined (at least as default) for your webspace.

For the webspace it doesn't play a role at the end, sometimes you just have to know it to be aware how to setup some services. So my question would be, what makes the difference for you?  
Dave Baldwin

Some hosts allow you complete access up to your Linux 'home' directory.  But a lot of hosting companies restrict your access to your own web folders.  Even FTP is not going to show you anything 'above' that.
David Favor

1) You asked, "Is there a more reliable way of finding out where the site is located".

Yes.

Always your Webserver config file.

PHP directories... can be... confusing/jumbled/broken...

Your Webserver config is the definitive source of your DocumentRoot location.

2) You asked, "Is there a more reliable way of finding out where the site is located so I can navigate up and go into folders no part of htdocs. For example uploads."

To little data to answer this.

Find site == Webserver config.

Navigate Up == How this occurs relates to your Webserver config + any code (PHP or other) running on your site.

folders no part of htdocs == Unsure what this might mean.

uploads == Start with your Webserver config + then your full URL + refer to your Webserver logs, if an error occurs.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.