Linux – Permission denied creating folder after setting parent folder as www-data user

apache-2.4linuxPHPUbuntu

in my phpinfo configuration, i see the following:

User/Group  www-data(33)/33

In my directory /var/www/html/pluto-php/public/ I see the following for the data directory inside this path:

4 drwxrwxrwx 2 www-data www-data 4096 Sep 19 23:25 data

I also see the following for the pluto-php directory

4 drwxr-xr-x  8 root root  4096 Sep 16 21:49 pluto-php

I set the owner and group for the data dir to www-data. Somehow, after all of this, I still get this error in my php code when running a php script which creates a directory inside the data directory:

Warning: mkdir(): Permission denied in /var/www/html/pluto-php/vendor/pluto/src/Pluto/Stdlib/FilesystemUtils.php on line 32

I tried doing apache2ctl restart and that did nothing.

I've followed along every tutorial on google search and im stuck here.

UPDATE:

Here is my process list

    root@yonaton-Lenovo-V570:/var/www/html# ps aux | grep apache
    root      3234  0.0  0.6 409908 37092 ?        Ss   Sep28   0:09 /usr/sbin/apache2 -k start
    www-data  8516  0.3  0.2 410888 16988 ?        S    10:41   0:00 /usr/sbin/apache2 -k start
    www-data  8517  0.0  0.1 409940 10632 ?        S    10:41   0:00 /usr/sbin/apache2 -k start
    www-data  8518  0.0  0.1 409940 10632 ?        S    10:41   0:00 /usr/sbin/apache2 -k start
    www-data  8519  0.0  0.1 409940 10632 ?        S    10:41   0:00 /usr/sbin/apache2 -k start
    www-data  8520  0.0  0.1 409940 10632 ?        S    10:41   0:00 /usr/sbin/apache2 -k start
    www-data  8521  0.0  0.1 409940 10632 ?        S    10:41   0:00 /usr/sbin/apache2 -k start
    root      8523  0.0  0.0  21292  1088 pts/1    S+   10:41   0:00 grep --color=auto apache

Best Answer

www-data must have write access to the entire tree.

You can execute chown -R www-data:yourgroup /var/www/html/pluto-php, where yourgroup is the group name of your user (avoid root for security reasons). If you don't specify your groupname, you won't be able to write and read in the data directory.

Next add the right permissions by executing chmod -R 775 /var/www/html/pluto-php.