如何授予 apache 写入主目录的权限? [英] How to give apache permission to write to home directory?
问题描述
我的服务器在/var/www/html 我有一个 php 脚本在/var/www/html/fileio_test/io_test.php
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);
?>
当我尝试运行这个脚本时,我得到 p>
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
如何让 apache 写入我的主目录?服务器在 fedora 20 上运行.
How do I let apache write to my home directory? The server runs on fedora 20.
推荐答案
由于您的文件驻留在主目录中,我建议采用以下方法之一.
As your file residing in your Home directory, I would suggest one of following approaches.
授予 0777 文件本身的权限.
Give 0777 permission to file itself.
chmod 0777 /home/djameson/test.txt
将所有权更改为 apache 用户 www-data 并授予所有者写入权限.
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
将您的用户添加到 www-data 组,反之亦然将 www-data 用户添加到您的组.然后组写权限.
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
注意:我假设 apache 用户名 &组名是 www-data &www-data 分别.您必须相应地更改您的服务器 apache 用户名/组名.
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.
这篇关于如何授予 apache 写入主目录的权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!