Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ixudra's avatar

Linux file permissions

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?

0 likes
7 replies
bobbybouwmann's avatar

What kind of error do you get? Do you run a command? Or something else?

ixudra's avatar

@bobbybouwmann Sorry, that was not clear. I try to open my index page (or any page really) and I get the standard chmod(): Operation not permitted error. If I comment out the chmod() in the vendor file (bad idea, I know), the file is generated properly and I can continue development. Nevertheless, should be resolved since this makes no sense to me

ixudra's avatar

@bobbybouwmann Storage is not the problem. I checked the path, he's trying to write in /var/www/project/htdocs/bootstrap/cache

bobbybouwmann's avatar

Mmh, it seems to be the correct permissions then! Maybe setting the user and group to www-data fixes it?

ixudra's avatar

@bobbybouwmann Been quiet around this issue for a while but I've been running into this again and again, lately. Tried resolving it with sudo chown -R www-data /var/www/app but I get an error for every file: chown: operation not permitted. I even logged in as super user but that didn't make any difference. Any suggestions?

Btw, I use a puphpet vagrant box, if that helps...

Please or to participate in this conversation.