我在运行OS X 10.5.6,Apache 2,PHP 5的Mac上运行多个PHP应用程序。我为每个项目设置了子域名,为每个子域名设置了主机文件条目,在Apacheconfiguration中设置了虚拟目录块。 所以
project1.localhost转到/ Library / WebServer / Documents / Project1
project2.localhost进入/ Library / WebServer / Documents / Project2
等等…
但是,这种方法并不真正“隔离”networking应用程序。 例如,如果我包含这样的脚本:
<?php include("/includes/include.php"); ?>
它从我的电脑的基本目录引用了脚本。 所以它访问
C:/includes/include.php
有没有办法让我参考
C:/Library/WebServer/Documents/Project2/includes/include.php
基本上,使其不知道自己的目录之外的任何东西。 另外,有没有办法使用php.ini的每个子域的基础呢?
我相信可以为每个虚拟主机设置一个php.ini
<VirtualHost *:80> ... PHPINIDir /full/path/to/php/ini/ </VirtualHost>
这样你可以自定义open_basedir等等
通过在httpd.conf文件中添加open_basedir指令文件夹块,可以限制脚本查看特定文件夹树上的任何内容。 它应该看起来像:
<DIRECTORY / full / path / to / folder / contained / script />
php_admin_value open_basedir“/ full / path / to / top / folder / of / desired / tree /”
</ DIRECTORY>
有一件事 – 如果你没有用/来结束路径,那么这是一个通配符匹配。 换句话说,“/ var / etc / my”与“/ var / etc / myFolder”以及“/ var / etc / myMothersFolder”匹配,而“/ var / etc / my /名称。
关于应用程序隔离〜这是关于保护 PHP脚本,以便他们不能访问其他人? 请详细说明 –
关于php.ini – 我不知道任何方式来使用每个目录特定的php.ini,但你可以肯定创建一个php包含一堆ini_set()行,也许这样的东西..
<?php // in your header or along top of all php modules in your pap require_once ( '/path/to/includes/ini_set.php' ); // ... ?>
和ini_set.php脚本:
<?php // one of these for each override of defaults set in php.ini file -- ini_set ( $varname, $newvalue ); ini_set ( $varname, $newvalue ); ini_set ( $varname, $newvalue ); ?>
如果您有兴趣了解更多关于ini_set()函数的信息,请参阅php.net上的文档页面: http : //us3.php.net/ini_set
希望这有些有用〜
最好的方法是通过FCGI(mod_fcgid)使用PHP。 这样你就可以使用不同的用户和不同的php.ini来运行PHP。
下面是一个如何在Ubuntu上设置这样一个配置的例子: http : //www.howtoforge.com/how-to-set-up-apache2-with-mod_fcgid-and-php5-on-ubuntu-8.10
如果你想使用完整的路径名,你可以使用:
<?php include dirname( __FILE__ ) . '/includes/include.php'; ?>
可能的解决方案为php.ini文件
尝试相对路径! 喜欢:
<?php include("./includes/include.php"); ?>
要么
<?php include("includes/include.php"); ?>