James
James

Reputation: 31738

How to set PHP document root in httpd.conf

I have a site in a subdirectory e.g. root/sites/testsite/ and I would like the php variable $_SERVER['DOCUMENT_ROOT'] to be root/sites/testsite/ and not root, how would I do this being in mind I am on shared hosting?

Thanks in advance

Upvotes: 0

Views: 741

Answers (1)

IMSoP
IMSoP

Reputation: 97638

$_SERVER['DOCUMENT_ROOT'] is automatically set to the DocumentRoot configured in your Apache VirtualHost configuration entry. This will be the directory pointed to by the URL / on your domain.

You will need to change the code to use a different variable to calculate the base directory, such as one hard-coded in a config file. You may also be able to use the Apache SetEnv directive in a .htaccess file to pass in a variable - e.g. SetEnv BaseDir root/sites/testsite/ would result in $_SERVER['BaseDir'] being set to the string "root/sites/testsite/".

Alternatively, you could assign a new value to the variable at the beginning of the script, in order to "spoof" its value (for instance if using 3rd-party code that relies on this variable).

Upvotes: 1

Related Questions