尝试包含文档根目录之外的文件 (Plesk 10)
好吧,我已经尝试了一切,这是迄今为止最好的地方,我想在这里创建文档根 httpdocs/[folder]/html
并且我有我想要去的 php 包含文件位于根 之上(需要 '../[folder]/file.php']
,但无法访问超出 /var/www/vhosts/example.com/httpdocs
代码> 我知道我受到限制。 open_basedir
因为该值仍然是 phpinfo()
中的 httpdocs/[folder]/html
但对于我来说我无法改变它这
是我到目前为止尝试过的: 我已经看到了这个 - 如何包含文档根目录之外的文件? - 并创建了一个仍然位于conf目录中的“vhost.conf”,重新配置了该文件,重新启动了apache......什么都没有。这是一篇好文章,但似乎有点过时了。
我将 php.ini 本身编辑为 open_basedir = '/var/www/vhosts/example.com/httpdocs
,将其上传回原来的位置,重新配置,重新启动 -
我什么也没拉出 'httpd.ini'。通过添加来自其他conf文件(vhost.conf)的相同行来编辑它,然后将其放回 - 什么都没有,然后我尝试按照godaddy所说的进行操作 - http://help.godaddy.com/article/1616 并添加行 php_admin_value open_basedir none' 到 'httpd.conf
- 也没有运气。
现在是 0435,我几乎睁不开眼睛 - 这个网站预计将于明天 2000 年推出!预先感谢任何愿意/能够阅读和/或提供帮助的人。
更新:感谢您的快速回复,以下是我能给您的最佳答案:
它会给你一个错误吗?
是的,我收到服务器错误并通过我的服务器错误日志,具体来说:
PHP 警告:require() [function.require]:open_basedir 限制生效。文件(/var/www/vhosts/[example.com]/httpdocs/[文件夹]/[安全 php 文件所在的文件夹]/[file.php])不在允许的路径内:
所以我99.99% 确定是因为 open_basedir 限制。
您确定您的网络服务器已设置为 vhosts/ 的所有者吗?
我很确定,我对控制服务器有点陌生,我真的不知道这到底意味着什么,但我通过 Godaddy 有一个虚拟专用服务器,运行 Parallels Plesk v10.3.1,我执行了上述文件移动外壳 SSH。
在 Plesk 中,我可以将“文档根”更改为 /var/www/vhosts/example.com
以下的任何内容,Plesk 会将“open_basedir”更改为我设置的任何内容。例如,如果我在 Plesk 中将文档根设置为“httpdocs”,则“open_basedir”将更改为同一文件夹,并且一切正常。问题是我不想公开访问 /httpdocs/[folder]
中的所有内容
我的目标是我想将“文档根”更改为 /httpdocs/[folder]/html< /code> 和 'open_basedir 到
/httpdocs
但由于某种原因我无法更改 open_basedir
中的本地值。我想这样做是出于安全目的,这样人们只能直接访问不重要的 php 文件,但 php 本身我想给予对文件夹的更多访问权限。
您是否尝试包含使用相对或绝对路径?
我试图包含/要求“文档根”上方的文件的 php 文件中的路径看起来与此格式完全相同:
require '../[安全 php 文件所在的文件夹]/file.php';
如果我理解正确的话,我没有使用服务器的整个路径。
Okay, I've tried everything, this is by far the best place it seems, I want to make Document Root here httpdocs/[folder]/html
and I have php include files that I want to go above the root (require '../[folder]/file.php']
but not be able to access further than /var/www/vhosts/example.com/httpdocs
. I know I'm being limited by open_basedir
because the value is still httpdocs/[folder]/html
in phpinfo()
but for the life of me I can't change that local value!
This is what I've tried so far:
I've seen this - How to include file outside document root? - and created a 'vhost.conf' that is stil sitting in the conf directory, reconfigured the file, restarted apache...nothing. It's a good post but it seems a little out of date.
I edited php.ini itself to open_basedir = '/var/www/vhosts/example.com/httpdocs
, uploaded it back up to where it was, reconfigured, restarted - nothing
I pulled out 'httpd.conf' edited it by adding the same lines from the other conf file,(vhost.conf), put it back in - nothing, I then tried to do what godaddy says here - http://help.godaddy.com/article/1616 and added the line php_admin_value open_basedir none' to 'httpd.conf
- with no luck either.
It is now 0435 and I can barely keep my eyes open - this site is suppose to launch tomorrow at 2000! Thanks in advance to anyone who is willing/able to read and/or help.
Update: Thanks for a quick response, here are the best answers I can give you:
Does it give you an error?
Yes, I get a server error and through my server error log, specifically:
PHP Warning: require() [function.require]: open_basedir restriction in effect. File(/var/www/vhosts/[example.com]/httpdocs/[folder]/[folder where secure php files exist]/[file.php]) is not within the allowed path(s):
So I'm 99.99% sure its because of the open_basedir restriction.
Are you sure that your webserver is set as the owner of vhosts/ ?
I'm pretty sure, I'm kinda new to controlling servers and I don't really know what that means exactly but I have a virtual dedicated server through Godaddy, running Parallels Plesk v10.3.1, I did the above file moving going through Shell SSH.
In Plesk, I can change the 'Document root' to anything below /var/www/vhosts/example.com
and Plesk will change the 'open_basedir' to anything I set. For example, If I set the document root to 'httpdocs' in Plesk then 'open_basedir' is changed to the same folder and everything works fine. The problem is I don't want public access to everything in /httpdocs/[folder]
My goal is I want to change 'document root' to /httpdocs/[folder]/html
and 'open_basedir to /httpdocs
but I can't change that local value in open_basedir
for some reason. I want to do this for security purposes so people can only directly access the non important php files, but php itself I want to give more access to folders.
Are you trying to include using relative or absolute paths?
My paths in the php file that I'm trying to include/require to files above 'document root' looks exactly like this format:
require '../[folder where secure php files exist]/file.php';
If I'm understanding you correctly, I'm not using the entire path of the server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案:(已更改为答案):
显然,在 Plesk 10 中,Plesk 的程序将“文档根”路径设置为“open_basedir”,但没有用户友好的方式来设置更改 Plesk 10 中的“open_basedir”!!!
因此,这有点麻烦,你必须首先转到这里:
然后更改文件中的这两行(第 11 行和 29 行):
echo "php_admin_value open_basedir {$OPT['dir']}/:/tmp/\n";
到此:
echo "php_admin_value open_basedir /var/www/vhosts/[your.domain]/httpdocs/:/tmp/\n";
或您希望停止限制的任何位置。
然后确保您通过 SSH 运行这些行:
但我现在遇到了一个新问题。 “文档根目录”指向正确的文件夹:
没有任何错误,但是当服务器到达:
require '../[folder]/[file.php]';
它会跳过它,就像它根本不存在一样!没有给我错误消息或任何东西。它还跳过我所有嵌入的 css 文件、js 文件、图像、视频...它不会进入任何目录!我感觉这是一个“php.ini”设置或者 Plesk 正在做的一些奇怪的事情。
已解决:最后一个问题是因为我从未访问过根目录以上的文件。 PHP 可以超越根目录,但你不能这样做:
HTML 中的
src="../img/imagefile.jpg"
。
因此,在重组我的所有网站文件后,我的网站现在已启动并运行!感谢所有的帮助,希望有人不会再这样做了。另外,我看到 Plesk 正在更新此帖子,因为这是一个大问题。为 Parallels 工作的人说,http://forum.parallels.com/showthread.php ?t=113236 这将是下一个版本中的一个选项,所以在那之前是黑客时间!
ANSWER: (This was changed to the answer):
Apparently, in Plesk 10, Plesk's program sets whatever the 'document root' path will be, to the 'open_basedir' BUT there is no user friendly way to change 'open_basedir' in Plesk 10!!!
So instead it is a little bit of a hack, you have to first go here:
Then change both of these lines in the file, (line 11 and 29):
echo "php_admin_value open_basedir {$OPT['dir']}/:/tmp/\n";
to this:
echo "php_admin_value open_basedir /var/www/vhosts/[your.domain]/httpdocs/:/tmp/\n";
or to wherever you want the restriction to stop.
Then make sure your run these lines is SSH:
But I'm having a new problem now. The 'document root' is pointing to the correct folder:
without any error however when the server gets to a:
require '../[folder]/[file.php]';
It skips through it like its not even there! Not giving me an error msg or anything. It's also skipping all my embedded css files, js files, images, videos...its not going to any of the directories! I have a feeling it's a 'php.ini' setting or something weird that Plesk is doing.
Solved: The last issue was because I never worked with accessing files above the root. PHP is allowed to go above the root but you can't do this:
src="../img/imagefile.jpg"
in HTML.
So after restructuring all my site files my website is now up and running! Thanks to all that helped, hopefully someone won't have to do that again. Also, I saw a post where Plesk is updating this because it is a big issue. Someone who works for Parallels said, http://forum.parallels.com/showthread.php?t=113236 this will be an option in the next version, so until then it's hack time!!