ixudra
336
7
Servers

Linux file permissions

Posted 3 months ago by ixudra

Updated my Laravel website to version 5.7, now suddenly I have permission issues when compiling my auto-discover file.

        // /var/www/project/htdocs/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php
     
        /**
         * Write the contents of a file, replacing it atomically if it already exists.
         *
         * @param  string  $path
         * @param  string  $content
         * @return void
         */
        public function replace($path, $content)
        {
            // If the path already exists and is a symlink, get the real path...
            clearstatcache(true, $path);
     
            $path = realpath($path) ?: $path;
     
            $tempPath = tempnam(dirname($path), basename($path));
     
            // Fix permissions of tempPath because `tempnam()` creates it with permissions set to 0600...
            chmod($tempPath, 0777 - umask());        // => Error occurs here
     
            file_put_contents($tempPath, $content);
     
            rename($tempPath, $path);
        }

File permissions:

$ ls -al bootstrap/
total 8
drwxrwxr-x  5 vagrant www-data  160 Apr 13 14:52 ./
drwxrwxr-x 36 vagrant www-data 1152 Apr 13 14:38 ../
-rwxrwxr--  1 vagrant www-data 1654 Apr 13 14:52 app.php*
-rwxrwxr--  1 vagrant www-data 1079 Mar 18  2018 autoload.php*
drwxrwxr-x  7 vagrant www-data  224 Apr 13 14:55 cache/

$ ls -al bootstrap/cache/
total 4
drwxrwxr-x 7 vagrant www-data 224 Apr 13 14:55 ./
drwxrwxr-x 5 vagrant www-data 160 Apr 13 14:52 ../
-rwxrwxr-- 1 vagrant www-data  14 Mar 18  2018 .gitignore*
-rw-rw-r-- 1 vagrant www-data   0 Apr 13 14:55 packages.phpQSsjXI
-rw-rw-r-- 1 vagrant www-data   0 Apr 13 14:46 packages.phpSJ4MQu
-rw-rw-r-- 1 vagrant www-data   0 Apr 13 14:48 packages.phpVyLbgt
-rw-rw-r-- 1 vagrant www-data   0 Apr 13 14:52 packages.phpZ9EzqP

PHP user: www-user

$ groups www-user
www-user : www-user www-data

For as far as I can see, it should be in order. The user belongs to a group that has write and execute permissions so I don't understand how I'm getting an exception. I could just do a chmod -R 777 but that's a bad idea in general. How can I solve this in a "clean" way?

Please sign in or create an account to participate in this conversation.