Composer: file_put_contents(./composer.json or ./composer.lock): failed to open stream: Permission denied

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Problem

When I run Composer update in my project then I got this error.

[ErrorException]
  file_put_contents(./composer.lock): failed to open stream: Permission denied

Solution

It can be resolved with the following command:

sudo chown -R $USER ~/.composer/

That’s all.

I hope this article helps you to fix your issue.

Thanks for reading.

Keep Exploring.