file_put_contents说权限被拒绝了? [英] file_put_contents saying permission denied?

查看:123
本文介绍了file_put_contents说权限被拒绝了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

file_put_contents权限被拒绝

我最近转移了服务器,似乎file_put_contents不能在新服务器上运行。

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

一切都是一样的,文件夹是正确的chmodded,但由于某种原因,它不是创建文件和放置其中的内容。

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");

脚本正在运行

/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

我是否需要更改服务器上的任何设置才能使用此功能?有什么问题?

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

推荐答案

您可能使用了错误的用户。检查php是否使用拥有您尝试编写的目录的同一用户。 Php经常使用wwwdata,因此如果目录被chmodded为755,则意味着用户创建的目录可以写入,但其他人只能读取。 chown到php用户或chmod到777。

You are probably using the wrong user. Check if php uses the same user which owns the directory you are trying to write. Php often uses wwwdata so if the directory is chmodded to 755 it means that the user created the directory can write it, but others can only read. chown to the php user or chmod to 777.

我个人在fastcgi上运行php并且它运行一个独特的用户因此我没有这个问题,你可能会认为关于切换到fcgi。

I personally run php on fastcgi and it runs with an unique user so I don't have this problem, you may think about switching to fcgi.

这篇关于file_put_contents说权限被拒绝了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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