file_put_contents 说权限被拒绝?

发布于 2024-11-07 00:21:01 字数 826 浏览 2 评论 0原文

可能的重复:
file_put_contents 权限被拒绝

我最近转移了服务器,并且 file_put_contents 似乎无法正常工作新服务器。

一切都一样,文件夹已正确 chmodded,但由于某种原因,它没有创建文件并将内容放入其中。

我创建了一个测试供您查看,模拟我们当前的操作方式:

file_put_contents("/home/user/public_html/test/test.progress", "test");

脚本正在运行,

/home/user/public_html/test.php

/test folder is chmodded to 755 (777 makes no difference)

我收到以下错误:

Warning: file_put_contents(/home/user/public_html/test/test.progress) [function.file-put-contents]: failed to open stream: Permission denied in /home/user/public_html/test.php on line 2

我是否需要更改服务器上的任何设置才能使其正常工作?怎么了?

Possible Duplicate:
file_put_contents permission denied

I have recently transferred server, and it seems that file_put_contents is not working on the new server.

Everything is the same, the folders are chmodded correctly, but for some reason it is not creating the files and putting the contents in it.

I have created a test for you to view, emulating how we are currently doing it:

file_put_contents("/home/user/public_html/test/test.progress", "test");

the script is being ran at

/home/user/public_html/test.php

/test folder is chmodded to 755 (777 makes no difference)

I am getting the following error:

Warning: file_put_contents(/home/user/public_html/test/test.progress) [function.file-put-contents]: failed to open stream: Permission denied in /home/user/public_html/test.php on line 2

Do I need to change any settings on the server for this to work? What is wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人心善变 2024-11-14 00:21:01

您可能使用了错误的用户。
检查 PHP 是否使用与您尝试写入的目录相同的用户。 PHP 经常使用 www-data(www-data 是 Ubuntu 上的 Web 服务器使用的用户,例如 Apache 和 Nginx)),因此如果目录被 chmodded 为 755,则意味着创建该目录的用户可以写入该目录,但是其他人只能阅读。 chown 到 php 用户或 chmod 到 777。

我个人运行 PHP fastcgi,它以唯一用户运行,所以我没有这个问题,考虑切换到 fastcgi。

You are probably using the wrong user.
Check if PHP uses the same user that owns the directory you are trying to write. PHP often uses www-data (www-data is the user that web servers on Ubuntu use such as Apache and Nginx for example)) so if the directory is chmodded to 755 it means that the user created the directory can write to it, but others can only read. chown to the php user or chmod to 777.

I personally run PHP fastcgi, it runs with an unique user so I don't have this problem, think about switching to fastcgi.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文