我正试图通过运行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()))
我创建了一个网页按钮来运行文件
谁能告诉我这里要改什么?因为当PHP读取status_log时,我已经从我的主目录中符号链接了我的web文件,他们在我的本地目录中找到了它,当www-data写入它时(通过上面的Python)它在/var/www中创建了文件,而不是我试图从/home中读取它。
解决方案是将正在读取的文件的路径更改为其位置:/var/www