I am attempting to set an Alias in Apache for PHP files where my PHP scripts reside. Usually, we write:

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

Regrettably this does not work with PHP:

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

Apache still knows the Alias (I made some tests), PHP however does not discover the Alias the way in which it's designed to.

I personally use PHP being an Apache module and never like a CGI. Anybody got an idea?


Either use include_path establishing php.ini or symlink your directory to ensure that the require function in PHP will discover the files without needing the Apache Alias. The final solution would during my situation above include developing a new folder during my filesystem named /php-bin after which symlink it to /var/www/php-bin.

Can it be because include and require use filesystem references, and also the leading / refers back to the filesystem root directory. PHP does not refer to the Apache alias, or treat the net server htdocs directory as root: it goodies your include directory reference being an absolute (if you use a number one /) or relative while using include_path setting when it is a family member reference.


You could attempt adding /var/www/php-bin/ towards the include_dir inside your php.ini, then simply just using require 'file.php' (shedding the /php-bin/ directory reference) inside your code.