简体   繁体   English

当我尝试从我的主文件夹中获取文件内容时,权限被拒绝

[英]Permission denied when I try to get file contents from my home folder

I run a cron job with a system user called system_user and I make the cron job save its output to the file outputFile.txt in my system_user's home folder /home/system_user/outputDir/outputFile.txt . 我使用名为system_user的系统用户运行cron作业,并将cron作业保存到system_user的主文件夹/home/system_user/outputDir/outputFile.txt的文件outputFile.txt

This all works, but now I need to access this file within my php script which is located in /var/www/html/scripts/phpScriptFile.php and I'm getting a permission denied error. 这一切都有效,但现在我需要在我的php脚本中访问这个文件,该脚本位于/var/www/html/scripts/phpScriptFile.php ,我收到了一个权限被拒绝错误。

I found out that the php scripts are run with apache user, so I did this: 我发现php脚本是用apache用户运行的,所以我这样做了:

sudo chown system_user:apache outputFile.txt

But this did not help. 但这没有帮助。

If the cron outputs the file in let's say /var/www/html/scripts/ folder then I do not get this permission error. 如果cron在/var/www/html/scripts/文件夹中输出文件,那么我不会收到此权限错误。

The reason I tried to move my outputFile.txt out of the /var/www/html folder is that if I leave it then it's possible to access it via http protocol and I don't want anyone seing the content of this file. 我试图将我的outputFile.txt移出/ var / www / html文件夹的原因是,如果我离开它,那么可以通过http协议访问它,我不希望任何人查看该文件的内容。

Please advise. 请指教。

What are the permissions on outputFile.txt? outputFile.txt的权限是什么?

sudo chown system_user:apache outputFile.txt

That leaves system_user as the owner, but changes the group to apache. 这使system_user成为所有者,但将组更改为apache。 For that to work the file must be at least rw-r----- which could be accomplished by chmod 640 outputFile.txt . 要使其工作,文件必须至少为rw-r-----这可以通过chmod 640 outputFile.txt来完成。

Probably some rights are not correct in the folder containing the file. 在包含该文件的文件夹中,某些权限可能不正确。

Also, maybe the group for apache user is not named apache or the group rights are not correctly assigned. 此外,可能apache用户的组未命名为apache或组权限未正确分配。

Reassign your user group: 重新分配您的用户组:

sudo chown system_user:system_user outputFile.txt

And test giving general read permissions to the whole path: 并测试给整个路径的一般读取权限:

chmod o+rx /home/system_user
chmod o+rx /home/system_user/outputDir
chmod o+r /home/system_user/outputDir/outputFile.txt

If this works (should do), then you can try to investigate if the group name was correct move the access rights to the group part. 如果这样做(应该这样做),那么您可以尝试调查组名是否正确移动对组部件的访问权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在我的本地主机中全局安装作曲家,现在我得到“file_put_contents(./composer.json):无法打开流:权限被拒绝”? - Installed composer globally in my localhost, now I get "file_put_contents(./composer.json): failed to open stream: Permission denied"? 使用file_get_contents打开文件时,权限被拒绝; webbrowser可以毫无问题地打开它 - Permission denied when opening file with file_get_contents; webbrowser can open it without problems 修复 file_get_contents 权限被拒绝的错误 - Fixing error with file_get_contents permission denied 外部wsdl的file_get_contents权限被拒绝 - file_get_contents permission denied for external wsdl file_get_contents($ URL)返回“权限被拒绝”错误 - file_get_contents ($URL) returns “Permission Denied” error file_get_contents():无法打开流:权限被拒绝 - file_get_contents(): failed to open stream: Permission denied 尝试在txt文件中写入时php中的权限被拒绝错误 - Permission denied error in php when try to write in a txt file 创建文件夹时权限被拒绝 - Permission denied when creating a folder Vagrant file_put_contents权限被拒绝 - Vagrant file_put_contents permission denied file_put_contents权限被拒绝+ livedocx - file_put_contents permission denied + livedocx
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM