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.
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.
I found out that the php scripts are run with apache user, so I did this:
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.
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.
Please advise.
Probably some rights are not correct in the folder containing the file.
Also, maybe the group for apache user is not named
apacheor the group rights are not correctly assigned.Reassign your user group:
And test giving general read permissions to the whole path:
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.