Work Permissions and Cron Folders - Permission Denied

I have a folder above the web root that is used to temporarily store user files generated by the php web application. Files can be, for example, PDFs, which will be attached to emails.

Folder permissions are set to rwxr-xr-x (0755). When executing the procedure from the web application, the files are written to this folder without any problems.

Now I also created a cron job that calls a php script to execute the same procedure as above. However, the PDF cannot be saved to the above folder due to failed permissions - the cron job returns an error permission denied.

I tried to set the folder permissions on 0775 and still get access denied. However, when the permissions are 0777, then the cron job works fine.

This seems very strange to me - why does cron get permission rejected at 0755 but it works fine through a web application?

+3
source share
4 answers

The likely answer is that the cron job runs under your user - and the directory belongs to apache (or www-data or to anyone or another user who runs your web server).

To make it work, you can configure the cron job to act as a web server user. Something like that:

su -l www-data -c 'crontab -e'

775 (read-write-execute , - ) , cron.

, - , apache, (apache , , , .

, suphp - - - , .

+6

-. , 3 .

php script , cron, .

chown chgrp, cron .

+1

It depends on which user you defined cronjob.

If you are root (not recommended), it should work. If you are a web user (e.g. www-data on ubuntu), it should work as well.

sudo su - www-data
crontab -e
0
source

If you use cpanel to run php, you can try something like this: "php / home / algo / public_html / testcron.php" ... just write: php (rute from script) /yourscritpt.php "

0
source

All Articles