April 07, 2005

PHP Crosss Server include_path

We have a somewhat complicated dev setup, although not terribly so. It makes it complicated to get the php library directories set up.

The live server is reasonably straight forward. A single web dir for all the files. PHP uses server root instead of document root for its include directives, which is really a big pain in the ass... especially when it comes to working .htaccess files.

Setting the php_value include_path in .htaccess is preferred for a lot of reasons, not the least of which it makes it easy to change where the libraries for a given directory tree or application are. However there are a handful of problems with this, the top two are that include_path cannot be additive and that the include is relative to system root and not document root.

Not Additive: php_value include_path replaces the previous value for include_path. This is a bit of a design flaw with PHP. Other pathing systems allow adding or replacing. This means that everytime the include_path is set, one has to know and reiterate every previous library directory. These can be kind of complicated for a sophisticated site. In fact, in many cases they cannot be derived without logic and thus are NOT settable in .htaccess, destroying the functionality of this. Awful.

System Root not Document Root. Unlikely most other .htaccess directives which are relative to Document Root, PHP decided to make the file paths absolute, which means that it is difficult or impossible to create include_path values that can handle a complicated tree of applications and active pages.

In our case, one of our main development setups is that we have a single web server that serves files from a variety of directories within the development trees. So fire.localdev runs off one drive while earth.localdev runs off another. In order to keep their libraries separate, the library paths MUST not be set using absolute (server root based) paths.

I came up with two solutions for this, one ugly and one not so bad. The ugly one is to include the whole list of possible relative directories:

php_value include_path .:./lib:../lib:../../lib:../../../lib:../../../../lib

you get the idea. Beautiful, no? no.

The other, slightly less ugly, version is to add entries to the sections in httpd.conf:

<VirtualHost ...>
ServerName fire.localdev
DocumentRoot /www/fire.dev.root
php_value include_path ".:/www/fire.dev.root/lib"
</VirutalHost>

<VirtualHost ...>
ServerName earth.localdev
DocumentRoot /www/earth.dev.root
php_value include_path ".:/www/earth.dev.root/lib"
</VirutalHost>


Posted by Earth at April 7, 2005 03:19 AM
Comments
Post a comment