6

I have a laravel project on an ubuntu virtualbox. I used to run composer update and all worked fine. I don't know of any changes that could have affected this but now when I run composer update I get

file_get_contents(/home/user/.composer/config.json): failed to open stream: Permission denied

Does anyone know why? When I run sudo composer update , it works.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
user3494047
  • 1,643
  • 4
  • 31
  • 61

3 Answers3

11

Your permissions got changed somehow (perhaps not related with running composer). Setting the owner of that file as your user should fix the issue:

sudo chown user /home/user/.composer/config.json

The above assumes that the username is user from the home path. As a side note, it works when running it as a super user using sudo because there's no permissions restrictions in that case.

Bogdan
  • 43,166
  • 12
  • 128
  • 129
0

It seems you don't have valid permissions for this file. Try running:

sudo chmod 0777 /home/user/.composer/config.json

EDIT

Of course, you should do it only in development environment (you mentioned you use Virtualbox). You should not do it in production environment.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • While this is a valid solution, I would suggest you explain the pitfalls of giving full access to a file for any user. Because while in this case it might be used in a dev environment where it's not an issue, some people might take the advice and use it on production servers, not knowing/understanding the security risks it implies. – Bogdan Dec 29 '15 at 13:17
  • @Bogdan That's true, I've added info to my answer – Marcin Nabiałek Dec 29 '15 at 13:22
0

Run below command.

sudo composer update