In the book Build your own Database Driven web site. on page 182 There is a note about CGI.
The one place where you can’t count on $_SERVER[‘DOCUMENT_ROOT’] is on a server running the Common Gateway Interface (CGI) version of PHP. The CGI specification does not require the web server to inform PHP of the document root directory for the site, so this value will usually be absent on such configurations. Thankfully, CGI installations of PHP are increasingly rare, and should certainly be avoided in production environments. If you followed the installation instructions for PHP in this book, you can rest assured that $_SERVER[‘DOCUMENT_ROOT’] will work.
My server is running the CGI interface. The book does not give any suggestions on how to work around this. Does anyone have an idea?
I have to be honest…I’ve never used the CGI vesion because I didn’t see the point of it… when you say your server do you mean your local server? Since you’re starting with this book, I would assume that you’ve done the installation and therefore you can re-install it and it is your own computer
I say this because by looking at the documentation, PHP.net recommends the installation as a module and not as a CGI altough it seems that it is installed as CGI by default under Solaris
On my local machine it works fine but when I upload it to my hosting site they use CGI.
The hosting site responded with:
Since your file should store under your member folder on hosting environment,
You may include follow path instead of $_SERVER[‘DOCUMENT_ROOT’]
for example: /shfs/home/johnt128/www/gnipsel/…
Ok, when I do a <?php phpinfo(); ?> on the domain where my web site is DOCUMENT_ROOT is not the correct document root. It shows “/etc/httpd/htdocs” when it should be “/shfs/home/johnt128/www/gnipsel/”. So to make my web site work on both my local server and my domain host I assume I can not use DOCUMENT_ROOT to find the path to my base directory for includes and such. What should be used to find the base directory?
Once you’re running CGI, you can configure your PHP even more flexible than usual.
You can have customized php.ini file, where you can set any setting.
I’m not sure about document root setting, but at least you can set
auto_prepend_file=/path/to/init.php
which is merely PHP file which would be added to each running script automatically
So, you can have there a line
<?
$_SERVER[‘DOCUMENT_ROOT’]=“whatever you want”;
first of all try to put php.ini file into root directory, change some value there and watch if phpinfo() output will reflect it.
if so - you’re ok.
If no - ask hosting support if you can use custom php.ini or not