Laravel Composer Update Error - Permission Denied

2019-05-21 11:29发布

问题:

I'm having error during updating composer. It's a Laravel 4 project which I've downloaded from .... and first time I updated it, it was fine and got updated. but due some reason I deleted that replace it with a fresh copy of that project, but now when I started to update it, it gives me the following error:

[ErrorException]                                                           
copy(/home/username/.composer/cache/files/symfony/security-core/3a27d7b34ee6  
2cb0fdf5ad970e7777912ef4722f.zip): failed to open stream: Permission denied

In between first and second update of this composer I did the following:

  1. Tried to installed Vagrant and homestead, but failed due to some internet connection problem.
  2. Updated Composer failed
  3. Uninstalled vagrant and reinstall composer.
  4. Reinstalled Composer
  5. Updated composer (success)
  6. Tried to install vagrant and homestead (success)
  7. Update composer (failed)
  8. uninstalled vagrant
  9. Reinstalled Composer
  10. Update Composer (failed)

The above mentioned error is getting occured again and again. I also tried 'composer clearcache' but doesn't worked. One thing which I noticed that it's been 16-19 months I'm using composer and never heard of such errors, but since I tried to install vagrant it created hurdles and errors for me.

  • I'm using Ubuntu 15.04
  • Updating Laravel 4.0 project
  • Updating Laravel 5

both project got updated before installing vagrant and homestead, but not now. /var/www is under the group of 'www-data' and 'username' also the part of this group.

Any help plz!!!!!!!!!!!!!!!

回答1:

I found the solution. If you see the error then it would be clear that I don't had access to the:

 "/home/username/.composer/cache/files/symfony/security-core/3a27d7b34ee62cb0fdf5ad970e7777912ef4722f.zip".

When I explore this directory, I found that its owner is 'root' or 'sudo'.

So I deleted the '.composer' directory and then started to update in my laravel project directory, every thing was fine and perfect! No problem at all!



回答2:

I know its an old topic, but for mac users this might be useful, since commands in macOS are a little bit different from linux distros and I had a hard time figuring this out.

  1. cd into ~ directory
  2. sudo chmod -R 777 .composer

Done. Now you can install/update composer.



回答3:

I just run sudo before an all when ok

sudo composer create-project laravel/laravel=5.3 /Users/peter/Sites/blog --prefer-dist



回答4:

I had the same issue with a mac, Composer warn me about running commands with super user permissions, so I've just changed the owner of files directory in the repo /Users/MyUserName/.composer/cache like so:

sudo chown -R MyUserName files/

Hope this helps.