PHP 写入权限被拒绝
我正在 CentOS 7 上运行服务器。 用户apache
|组 apache 对 /var/www/html
具有 775
权限 当我执行想要在 root dir (/var/www/html/)
中创建新文件的 PHP 文件时,出现以下错误 警告:file_put_contents(file.bin):无法打开流:/var/www/html/file.php 中的权限被拒绝
PHP 代码:
<?php
ini_set('display_errors', 'on');
$file = 'file.bin';
$content = "Content";
file_put_contents($file, $content);
?>
我将用更多数据更新问题,但因为我new 我不知道太多关于调试服务器错误的事情。
我尝试过的:
为了执行脚本(php..),我看到用户是 apache,所以我在 /var/www/html/ 上授予了“apache”所有权
tried
777
on./html< 上授予了“apache”所有权/code> (并在它不起作用到 755 后反转操作)
还尝试了
cd /var/www/html
chmod -R 775 .
(来自评论)
I'm running a server on CentOS 7.
User apache
| Group apache has 775
permissions on /var/www/html
When I execute a PHP file that wants to create a new file in root dir (/var/www/html/)
I get the following errorWarning: file_put_contents(file.bin): failed to open stream: Permission denied in /var/www/html/file.php
PHP code:
<?php
ini_set('display_errors', 'on');
$file = 'file.bin';
$content = "Content";
file_put_contents($file, $content);
?>
I will update the question with more data but since I'm new I don't know too many things about debugging server errors.
What I tried:
For executing scripts (php..) I saw the user to be apache so I gave 'apache' ownership on /var/www/html/
tried
777
on./html
(and reversed action after it didn't work to 755)Also tried
cd /var/www/html
chmod -R 775 .
(from comments)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题很可能出在
selinux
上。如果您使用命令(从根目录)关闭selinux:
并且一切都会正常,您需要使用命令(从根目录)打开selinux:
并运行命令:
一切都必须有效。如果此方法没有帮助,我建议您阅读此问题中的答案 。有一个更灵活的
selinux
设置的答案(使用sudo semanage fcontext
)。With a high degree of probability, the issue is with
selinux
.if you turning off
selinux
with the command (from root) :and everything will work, you need to turning on
selinux
with the command (from root):and run the command:
Everything must work. If this method does not help, I advise you to read answers in this question. There is an answer with a more flexible
selinux
settings (with usingsudo semanage fcontext
).