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 a开发者_StackOverflows 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.
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.
精彩评论