dongzha3058 2017-02-16 21:44
浏览 145

PHP file_put_contents返回'Permission Denied'(由于SELinux设置)

I know this is a common issue but I haven't been able to single out the problem for my specific use case, so bear with me.

I have a simple PHP script send_id which simply sends an ID number and saves it to a TXT file on my RHEL server running Apache 2.4.6 with PHP 5.4.

The error message: Warning: file_put_contents(/var/www/html/id.txt): failed to open stream: Permission denied in /var/www/html/send_id.php on line 6 '1' written to server

The PHP script itself:

$stringData = "$id";
$file = file_put_contents('/var/www/html/id.txt', $stringData.PHP_EOL , FILE_APPEND |LOCK_EX);
echo "'$stringData' written to server";

chmodding to 777 didn't do anything. Additionally, I checked to see ownership rights and noticed that the id.txt file is owned by the root user at both user/group level, and PHP is being run at root level.

Anyone have any suggestions? If its any help, this seems to have happened after a yum update

  • 写回答

3条回答 默认 最新


      相关推荐 更多相似问题


      • ¥15 关于lwip的pbuf数据提取问题
      • ¥50 请求关于BBS数据集的资源分享
      • ¥15 设计一份接口自动化测试报告
      • ¥15 手机安装kali后ifconfig 提示错误
      • ¥15 用C++求矩阵的特征值
      • ¥30 求解答(自动忽略本括号内容)
      • ¥15 根据C语言小型成绩管理系统画一个流程图
      • ¥15 Javaweb的增删改查
      • ¥30 用eclipse和sqlserver做
      • ¥15 unity 发布 kinect 项目后失去焦点的问题