function.fopen:无法打开流:PHP中的权限被拒绝 [英] function.fopen: failed to open stream: Permission denied in PHP

查看:157
本文介绍了function.fopen:无法打开流:PHP中的权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过PHP应用程序为我的网站创建XML网站地图.这个想法是创建一个新文件或覆盖一个现有文件.当我调用fopen时,出现以下错误:

I'm trying to create XML sitemaps for my website from my PHP application. The idea is to either create a new file or overwrite an existing file. When I call fopen, I get the following error:

[function.fopen]: failed to open stream: Permission denied

我正在尝试写到Webroot,其权限为:755.这意味着所有者具有写权限,对吗?我需要做什么才能使脚本能够写入此文件夹? 777会是一件坏事,对吧?我可以以所有者身份运行脚本吗?

I'm trying to write to the webroot and its permissions are: 755. This means that the owner has write permission, right? What do I need to do to make my script be able to write to this folder? 777 would be a bad thing, right? Can I run my script as owner somehow?

谢谢.

推荐答案

是的,正如您所说,使用777可能是一个巨大的错误.网络服务器不能与用于创建文件和文件夹的用户一起运行.

Yep, as you've said, using 777 could be huge mistake. The webserver doesn't run with the same user as you use to create files and folders.

您有一些选择:

  • 使用具有写权限的用户(而不是apache用户)作为cronjob运行站点地图创建.
  • 将站点地图放在另一个目录中,并设置一个302 Redirect或符号链接.在这种情况下,如果您遇到一个安全问题,请他人编写您的sitemap.xml,至少他们将无法创建具有更危险扩展名的另一个文件(例如PHP,这可能会导致网站入侵).
  • 制定重写规则,将所有匹配项重定向到sitemap.xml,并重定向到输出相应XML的php脚本.
  • Run the sitemap creation as a cronjob, using an user with rights to write there, other than the apache user.
  • Put the sitemap in another directory, and the set up a 302 Redirect or a symlink. In this case, if you have a security issue that let's someone to write your sitemap.xml, at least they'll not be able to create another file with a more dangerous extensions (like PHP, which may result in a site intrusion).
  • Make a rewrite rule to redirect any hit to sitemap.xml, to a php script that outputs the appropriate XML.

祝你好运!

这篇关于function.fopen:无法打开流:PHP中的权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆