Home » Php » Why does Composer create-project execution for Laravel fail?

Why does Composer create-project execution for Laravel fail?

Posted by: admin November 30, 2017 Leave a comment

Questions:

It appears that unless I use sudo my composer command fails to create a Laravel project.

Without sudo it gives me the following error:

[ErrorException]                                                             
  copy(/Users/H/.composer/cache/files/laravel/laravel/73094f2633f1b90f3ef  
  6de4a8a5b610532510e0e.zip): failed to open stream: Permission denied  

What am I missing here?

Answers:

If you ever execute:

sudo composer <anything>

Some of your composer home files (~/.composer/) will be written by the root and if you can’t delete or write over them again unless you use sudo to become root, so you have 2 options:

1) Change the user of those files back to your own:

sudo chown $USER:$USER -R ~/.composer

Or on a mac

sudo chown -R $USER:staff ~/.composer

2) Delete the whole folder (and lose your cache) to restart from scratch:

sudo rm -rf ~/.composer/cache

or even

sudo rm -rf ~/.composer