views:

37

answers:

1

I'm trying to set an Alias in Apache to use for PHP files where all my PHP scripts reside. Usually, we write:

Alias /php-bin/ "/var/www/php-bin/"

Unfortunately this doesn't work for PHP:

<?php require /php-bin/file.php; ?>

Apache still understands the Alias (I made some tests), PHP however doesn't find the Alias the way it's supposed to.

I use PHP as an Apache module and not as a CGI. Anyone got a clue?


SOLUTION

Either use include_path setting in php.ini or symlink the directory so that the require function in PHP will find the files without using the Apache Alias. The last solution would in my case above include creating a new folder in my filesystem named /php-bin and then symlink it to /var/www/php-bin.

+2  A: 

Could it be because include and require use filesystem references, and the leading / refers to the filesystem root directory. PHP doesn't refer back to the Apache alias, or treat the web server htdocs directory as root: it treats your include directory reference as an absolute (when you use a leading /) or relative using the include_path setting when it's a relative reference.

EDIT

You could try adding /var/www/php-bin/ to the include_dir in your php.ini, then simply using require 'file.php' (dropping the /php-bin/ directory reference) in your code.

Mark Baker
That makes sense. In that case, would it be possible to use the same function as the Alias in this case provides but in a different way, possibly in php.ini or something?
fast-reflexes
VERY WELL! Thank you very much! And for future reference, I assume you mean "include_path". Thanks again!
fast-reflexes
<blush> Yes, include_path
Mark Baker