0

I have 2 user userA and www-data in group www-data, on my web server I have php script that create folder and file

<?php
mkdir('dynamicDir');
file_put_contents('dynamicDir/z.txt', 'test');

output permission

drwxr-sr-x  2 www-data www-data   4096 Aug 19 23:33 dynamicDir

but when I run python script on shell using user userA

import os
os.remove('dynamicDir/z.txt')

I get error

Traceback (most recent call last):
  File "p.py", line 4, in <module>
    os.remove('dynamicDir/z.txt')
PermissionError: [Errno 13] Permission denied: 'dynamicDir/z.txt'

for already created folder/file I can use chmod -R g+rwx mydir/parentOfMyDir but how for dynamic directory?

1 Answer 1

0

I found 2 solutions:

  1. change php-fpm user in /etc/php/7.4/fpm/pool.d/www.conf

from

user = www-data
group = www-data

to

user = userA
group = www-data

change permission for web root and session (if you have) folder

chown -R userA:www-data /var/www/html
chown -R userA:www-data /var/lib/php/sessions
  1. using setfacl, read more

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .