dongre1907 2014-02-27 07:51
浏览 149
已采纳

如何给apache写入主目录的权限?

My server is in /var/www/html I have a php script in /var/www/html/fileio_test/io_test.php

<?php

$logging = <<< LOG
This is a test
LOG;

$testfile = fopen('/home/djameson/test.txt', 'a'); 
fwrite ($testfile, $logging);
fclose($testfile);

?>

When I try to run this script I get

Warning: fopen(/home/djameson/test.txt): failed to open stream: Permission denied in   /var/www/html/fileio_test/io_test.php on line 7

Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/html/fileio_test/io_test.php on line 8

Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/html/fileio_test/io_test.php on line 9

How do I let apache write to my home directory? The server runs on fedora 20.

  • 写回答

4条回答 默认 最新

  • dongqufi82315 2014-02-27 08:14
    关注

    As your file residing in your Home directory, I would suggest one of following approaches.

    1. Give 0777 permission to file itself.

      chmod 0777 /home/djameson/test.txt
      
    2. Change Ownership to apache user www-data and give owner-write permission.

      sudo chown www-data:www-data /home/djameson/test.txt
      chmod 0744 /home/djameson/test.txt
      
    3. Add your user to www-data group or vice-verse add www-data user to your group. And then group write permission.

      sudo usermod -a -G www-data djameson
      chmod 0764 /home/djameson/test.txt
      

    NOTE : I am assuming apache user name & group name is www-data & www-data respectively. You must change accordingly your server apache username/group name.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?