文件写入权限错误作为用户www-data

时间:2015-05-28 17:49:43

标签: php python permissions

我试图通过运行python脚本作为用户www-data来写入文件。当我使用以下代码运行脚本时:

sudo python my_script.py

它写得很好。当我将PHP脚本作为www-data运行时,它不会写入。权限:

folder(PiControl....contains status_log file): drwxrwxrwx
file(status_log....the file I am trying to write to): -rwxrwxrwx User:www-data group:www-data

写入文件Python代码:

#!/usr/bin/python
import datetime

status="on"

with open("status_log", "a") as myfile:
    myfile.write("{} {} {}".format("<br>light is now:", status,datetime.datetime.now()))

我创建了一个网页按钮来运行文件

有人可以告诉我这里要改变什么吗?

1 个答案:

答案 0 :(得分:0)

因为当PHP读取status_log时我在我的主目录中有了symlink'ed我的web文件,他们发现它在我的本地目录中,当www-data写入它时(通过上面的Python)它在/ var /中创建了文件www,而不是/ home,我试图从中读取它。

解决方案是将正在读取的文件的路径更改为其位置:/ var / www