cPanel, shared host, $_SERVER vars -- determng the root path?

I’m using a php file to store host specific configurations (config include). I’m having trouble setting up the the root path for a shared host server. After reading this I’d like to hear a comment on how the root path using $_SERVER vars is resolved on shared hosts.

This is an excerpt of my includes file…

$liveUrl = "http://".$_SERVER['HTTP_HOST']."/~justtemp/test_site/".$liveDir;
$siteRoot = $_SERVER['DOCUMENT_ROOT']."/~justtemp/test_site/";
$includesPath = $siteRoot."_includes/";

This is what I’m getting from print $siteRoot;
/usr/local/apache/htdocs/home/justtemp/public_html/

As you can see the var $_SERVER[‘DOCUMENT_ROOT’] produces this,
/usr/local/apache/htdocs/

And I’m adding this to complete the path,
/home/justtemp/public_html/
This is the “root” directory viewed in cPanel.

However, my page includes are not working. And a lot of other strangeness (displaying half of a form generated with php) in my php code that’s not calling any of these config vars.

Chris

Problem Solved…er… known
cPanel has know issue with using the server var Document_Root on accounts that use IP+~username/ as their base URL.

This seems illogical why this would effect the document_roor var since the path doesn’t even include the IP or ~username (see above exam…p…l…e… damn. I just noticed the quoted code snippet with document_root has the incorrect path…the body’s ok though…half correct:blush:

The temporary solution is to simply remove the document_root serv var. Which is fine with me. 'Long as it reduces the amount of typing and I can use my var in all the places; I can’t anticipate a problem here.

Chris

I see we’re both used to doing things one way. haha. I’m not familiar with this ini-set() function or how it is used.

The solution I use is meant to work this way. The server var document_root is used to get server’s listed root for that host service. No matter which LAMP server I move my files to, this document root should give the absolute path from the server’s root to the site’s root directory set in Apache’s httpd.conf file. Then all that remains to do is add the path to your project/current site’s root.

That’s what I understand and that’s how it’s been working. Only now I find out that there is a problem with how cPanel and Apache are configured together that causes a problem with using this sever var. I don’t understand.

Another thing I don’t understand about cPanel is why it sets up public_html when www is easily understood as the “live” folder directory. Why the alias?

Chris

Not sure what you are doing here.

usr/local/apache/htdocs/home/justtemp/public_html/

Your include path should be outside of your public_html (above it somewhere) e.g.

usr/local/apache/htdocs/home/justtemp/includes/

So you could just include a file which contains this line:


ini_set('include_path', 'usr/local/apache/htdocs/home/justtemp/includes/');

You can set this per domain or folder using an instruction in .htaccess files too.