我不能同意apache的权限写入到文件中,我究竟做错了什么? [英] I cannot grant apache permissions to write to a file, what am I doing wrong?

查看:321
本文介绍了我不能同意apache的权限写入到文件中,我究竟做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想授予apache的权限在我家的文件夹中的文件,这样一个PHP页面可能将日志数据写入该文件。下面找到我做了什么,我庆典外壳做到这一点,我想不通,为什么这是行不通的:

I am trying to grant apache permission to a file in my home folder, so that a php page might write log data to that file. Below find what I have done to accomplish this in my bash shell, and I cannot figure out why this won't work:

[root@myserver logs]# mkdir apachelogs
[root@myserver logs]# touch apachelogs/log.log
[root@myserver logs]# chown -R apache:apache apachelogs
[root@myserver logs]# chown -R apache:apache apachelogs/log.log
[root@myserver logs]# chmod 770 apachelogs
[root@myserver logs]# su apache
bash-4.1$ cd apachelogs
bash: cd: apachelogs: Permission denied

所以,我刚才授予Apache的所有权,读,写,执行权限,但显然阿帕奇仍然没有访问该目录,这是验证了我的PHP脚本运行此行code时:

So I have just granted apache ownership, read, write, execute permission, yet clearly apache still does not have access to the directory, and this is verified when my php script runs this line of code:

echo exec(whoami)."\n";
file_put_contents("/home/chilinut/logs/apachelog/log.log","test",FILE_APPEND);

输出是(不奇怪)

The output is (not surprisingly)

apache
E_WARNING: file_put_contents(/home/chilinut/logs/apachelog/log.log): 
failed to open stream: Permission denied

我缺少的是在这里吗?
我不想给文件夹777.我宁愿它有一些像644,我使用 CentOS版本6.4(决赛)

感谢您阅读!

推荐答案

哥们,

这是该文件的父目录的 /home/chilinut/logs/apachelog/log.log 的无权对用户的阿帕奇的一个明显的例子。

This a clear case that the parent directory of the file /home/chilinut/logs/apachelog/log.log doesn't have permission for the user apache.

您必须给写,读权限用户的阿帕奇的父目录also.Try你的情况下

You have to give write, read permission for the user apache for the parent directories also.Try the following in your case

chown chilinut:apache /home/chilinut/
chown -R chilinut:apache /home/chilinut/*
chmod g+rw /home/chilinut/
chmod -R g+rw /home/chilinut/*

现在切换到Apache用户,并尝试执行它。没事的。我曾尝试与一个样本脚本,并执行相同的脚本。

Now switch to apache user and try to execute it. It will be fine. I have tried with a sample script and does the same as your script.

enter code# cat test.sh 
echo | exec whoami ;
echo test >> /home/testleo/public_html/apachelogs/log.log;

正常工作从我的结束。让我们知道,帮助你。 :)

Worked fine from my end. Let us know if that helped you. :)

这篇关于我不能同意apache的权限写入到文件中,我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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