I've got a pretty stable development machine setup running Apache and taking advantage of virtual hosts to help keep my projects separate, and managing a dyndns.org service that we use to gain access to them. Each VHost directive typically appears like this:
<VirtualHost *:80> ServerName [my_internal_subdomain].[my_dyndns_name].dyndns.org ServerAlias home DocumentRoot "D:/webserver/[projectDirectory]/httpdocs" php_admin_value open_basedir "c:/WINDOWS/TEMP;D:/webserver/[projectDirectory]/" ErrorLog "D:/webserver/[projectDirectory]/logs/error.log" TransferLog "D:/webserver/[projectDirectory]/logs/access.log" </VirtualHost>
Clearly [projectDirectory], [my_internal_subdomain] and [my_dyndns_title] are values I understandOralter for every directive, just you don't need to publish them here :)
One factor has always confounded me however, in PHP, if I wish to need a file from say /includes/, I'd be prepared to use:
Except doing this throws a wide open_basedir restriction error - because "/" is attempting to visit, most probably towards the cause of D:/ - whereas I'd like each virtual host to determine that the need for DocumentRoot is actually where I'd like PHP to visit basically call personal files by "/".
This is the way my production server appears to operate, and it is a little of the discomfort needing to code everything to sort out exactly what the relative road to /includes/ is perfect for the advantage of my dev machine.
I expect this can be a quite simpleOrapparent directive I am missing however i aren't able to find it. Can anybody help?
Would you mean this?
require($_SERVER['DOCUMENT_ROOT'] . '/includes/myfile.php');
require pathways takes filesystem pathways so "/" will be the main from the filesystem OR pathways that report for your
include_path setting. You are able to improve your includes slightly and hang the include path such as this to obtain around it:
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . 'D:/.../httpdocs'); require('includes/myfile.php');
This works since it will discover the
includes folder inside your
PHP alone doesn't have real idea of a DocumentRoot because of its file-related functions. It appears just the file system from the server. The entire DocumentRoot clients are something applied in the webserver layer.
If you wish to use
require('/....') inside your code, you'd want to use mod_chroot (or mod_security's chroot functionality), so that you can "jail" each vhost into its very own directory tree, making the
/ directory be anything you want for every one.
However, chrooting features its own problems - it might lock from the relaxation from the file system. In case your script professional()'s something externally, or connects to MySQL, or does anything around the filesystem, you'd must have copies of individuals executables, .so libraries, MySQL socket file, etc... inside the jail.
In linux it's more prevalent to possess a 'chrooted' atmosphere then in home windows. You might determine your root by setting a configuration directive from the file inside your root and obtain your directory title such as this
$dirname = dirname(__FILE__); // or however you wish to arrange your affairs. $myConfigObject->set('root',$dirname);
Edit: This method doesn't nescesairly make use of the document root, however discover that oftentimes I'll have multiple instances of the identical project, which the majority of my php files is going to be outdoors the document root for security reasons.
It will likely be something like this:
/home/dir (project root /home/dir/stable (project instance root) /home/dir/dev (project instance root2) /home/dir/stable/lib (php files) /home/dir/stable/web (webroot)