Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "chmod(): Operation not permitted" on "composer update"

When I run 'composer update' I get this error:

Writing lock file
Generating autoload files


  [ErrorException]                  
  chmod(): Operation not permitted  

*It works just fine with sudo, but then I have to reset the owner & permissions, Which is really annoying...
**I also tried to reset the owner of ~/.composer to www-data with 777, no effect.
***I'm using Ubuntu 16.04 LTS + Apache/2.4.18 & php7.0.26


Any idea?
like image 664
Pini Avatar asked Nov 04 '25 10:11

Pini


1 Answers

chmod will only work without sudo if the owner of the file is the same as the one running the composer update command.

The problem is that the error message doesn't tell you which file it's trying to chmod.

This depends on the project.

Running the command in verbose mode will give you more details:

composer update -v

In my case, it gave me a stack trace, showing which file called chmod(), and the line number.
However, it didn't give me the path of the file passed to chmod().
I had to add a simple echo right before the call to chmod() (without forgetting to remove it afterwards).

Once you know which file/folder is responsible for the error message, change its owner with chown.

In my case (Magento 2.3), the culprit was the bin/magento file, which needs to be owned by the user running the composer commands.

like image 119
Sébastien Avatar answered Nov 06 '25 02:11

Sébastien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!