1

As an update. I just figured that it works okay for one level. For example, mkdir('/var/www/laravel/storage/first', 777, true) but doesn't work when there are multiple levels like mkdir('/var/www/laravel/storage/first/second/third', 777, true) And it seems wrong, doesn't it? Because the 'recursive' parameter is set to true.

Another important update. mkdir simply fails to create folders with 777. It first creates one parent folder with dr----x--t and can't create children. I suspect some php config option or umask, I don't know. Looking into it.


The issue is that PHP returns "Permission denied" when I'm trying to create a folder (e.g. /var/www/laravel/storage/new/directory/name) even if I set all permissions to 777.

My setup is on DO's droplet, Ubuntu 18. It's Laravel website located at /var/www/laravel and served by nginx.

I've run chown -R www-data:www-data /var/www

The output of ps aux|grep nginx|grep -v grep is:

root      2710  0.0  0.0 141284  1576 ?        Ss   14:04   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data  2712  0.0  0.0 143584  7636 ?        S    14:04   0:00 nginx: worker process
www-data  2714  0.0  0.0 143584  6368 ?        S    14:04   0:00 nginx: worker process
www-data  2715  0.0  0.0 143584  6368 ?        S    14:04   0:00 nginx: worker process
www-data  2716  0.0  0.0 143584  6368 ?        S    14:04   0:00 nginx: worker process

And here you can see the owner:

drwxrwxr-x 14 www-data www-data   4096 Mar  4 14:26 ./
drwxrwxrwx  5 www-data www-data   4096 Mar  4 17:45 ../
-rw-rw-r--  1 www-data www-data    106 Mar  4 14:16 .babelrc
-rw-rw-r--  1 www-data www-data    234 Mar  4 14:16 .editorconfig
-rw-rw-r--  1 www-data www-data    651 Mar  4 14:16 .env.example
drwxrwxr-x  8 www-data www-data   4096 Mar  7 13:44 .git/
-rw-rw-r--  1 www-data www-data    111 Mar  4 14:16 .gitattributes
-rw-rw-r--  1 www-data www-data    129 Mar  4 14:16 .gitignore
drwxrwxr-x 21 www-data www-data   4096 Mar  7 13:44 app/
-rw-rw-r--  1 www-data www-data   1686 Mar  4 14:16 artisan
drwxrwxr-x  3 www-data www-data   4096 Mar  4 14:16 bootstrap/
-rw-rw-r--  1 www-data www-data   1573 Mar  4 14:16 composer.json
-rw-rw-r--  1 www-data www-data 185669 Mar  4 14:27 composer.lock
drwxrwxr-x  2 www-data www-data   4096 Mar  5 16:31 config/
drwxrwxr-x  6 www-data www-data   4096 Mar  4 14:16 database/
-rw-rw-r--  1 www-data www-data    597 Mar  4 14:16 package.json
-rw-rw-r--  1 www-data www-data   1134 Mar  4 14:16 phpunit.xml
drwxrwxr-x  5 www-data www-data   4096 Mar  6 15:52 public/
drwxrwxr-x  5 www-data www-data   4096 Mar  4 14:16 resources/
drwxrwxr-x  2 www-data www-data   4096 Mar  4 14:16 routes/
-rw-rw-r--  1 www-data www-data    563 Mar  4 14:16 server.php
drwxrwxr-x  6 www-data www-data   4096 Mar  7 12:52 storage/
drwxrwxr-x  4 www-data www-data   4096 Mar  4 14:16 tests/
drwxrwxr-x 46 www-data www-data   4096 Mar  4 14:27 vendor/
-rw-rw-r--  1 www-data www-data    716 Mar  4 14:16 webpack.config.js
-rw-rw-r--  1 www-data www-data    549 Mar  4 14:16 webpack.mix.js
-rw-rw-r--  1 www-data www-data   1630 Mar  4 14:16 yarn-error.log
-rw-rw-r--  1 www-data www-data 176590 Mar  4 14:16 yarn.lock

Permissions were set like so:

find /var/www/laravel/ -type f -exec chmod 664 {} \;
find /var/www/laravel/ -type d -exec chmod 775 {} \;

SELinux doesn't seem to be installed. getenforce command returns installation suggestion.

What else needs to be checked?

UPDATE 1

Permissions for the target forlder:

cd /var/www/laravel/storage
ll

Output:

drwxrwxr-x  6 www-data www-data 4096 Mar  7 12:52 ./
drwxrwxr-x 14 www-data www-data 4096 Mar  4 14:26 ../
drwxrwxr-x  3 www-data www-data 4096 Mar  4 14:16 app/
drwxrwxr-x  3 www-data www-data 4096 Mar  7 12:52 f/
drwxrwxr-x  6 www-data www-data 4096 Mar  4 14:16 framework/
drwxrwxr-x  2 www-data www-data 4096 Mar  4 15:18 logs/

UPDATE 2

The PHP's exec('whoami') returns 'www-data'

UPDATE 3

For folder creating in PHP I use mkdir($pathInfo['dirname'], 777, true) And path is absolute.

13
  • Where do you try to create a folder?
    – Jos
    Mar 7, 2019 at 15:46
  • Under storage. So full path is /var/www/laravel/storage/new/directory/name Mar 7, 2019 at 15:48
  • In order to create a directory a process needs write permission for the containing directory.
    – Jos
    Mar 7, 2019 at 15:51
  • But as I can see it, the www-data has full permissions for the /var/www and below Mar 7, 2019 at 15:54
  • 1
    stackoverflow.com/questions/5165183/… could help
    – Lety
    Mar 7, 2019 at 16:38

0

You must log in to answer this question.

Browse other questions tagged .