在php.ini中我已经设置
open_basedir = /home/user/web/
现在我想在一个需要包含/ usr / share / phppgadmin文件的子域上运行phppgadmin。
所以我在这个主机的nginx-config中添加了下面一行:
fastcgi_param PHP_VALUE open_basedir="/home/user/web/:/usr/share/phppgadmin/";
并重新启动了nginx。 但是,由于以下错误,我无法访问该网站:
(错误)31440#0:* 1在stderr中发送了FastCGI:“PHP警告:include_once():open_basedir限制有效,文件(/usr/share/phppgadmin/libraries/lib.inc.php)不在允许的path( / home / user / web /)在/usr/share/phppgadmin/info.php在第10行
可能是第二条路不在这里列出的原因? 还有什么需要添加open_basedir到虚拟主机? 我只使用/ sites-available中的默认文件。
编辑总是想到重新启动fpm …
service php5-fpm restart
对于你的特殊情况,你应该考虑在默认的open_basedir
添加/usr/share
,因为任何东西都可以被世界读取。
另外, open_basedir
很容易绕过,除非你已经locking了shell_exec
, exec
, system
和类似的PHP函数,所以不考虑使用它的安全(我知道,它很糟糕)。
如果你想知道如何轻松绕过它,可以使用system('php -n ascript.php');
。 -n
将不会读取PHP.ini,因此不会应用open_basedir
。
只是FYI,如果你有nginxconfiguration为多个虚拟主机设置(所以,configuration在/etc/nginx/sites-enabled/example.com
),那么你可能需要设置fastcgi_param PHP_VALUE open_basedir=
there:
location ~ \.php$ { try_files $uri =404; fastcgi_param PHP_VALUE open_basedir="/var/www/:/new/path"; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; fastcgi_index index.php; include fastcgi_params;