ErrorException failed to open stream: Permission denied on composer install - laravel

I had a laravel app on github and I want to clone on other computer .
After I cloned the repository and run composer install command it shows me this error:
[ErrorException]
copy(/Users/cosminciolacu/.composer/cache/files/symfony/debug/824e1c185cf2cd
10402999589458f4be7ef980e1.zip): failed to open stream: Permission denied
what I missed?

You may need to change the ownership and permissions of the directory you have installed the project in.
cd /path/to/project
sudo chmod -R 775 .
sudo chmod 660 .env

If the first answer did not work, do sudo composer install instead of composer install.
Warning: well, said in comment section.

Related

Jetstream laravel on ubuntu 20.04

how can I create laravel project with jetstream on ubuntu 20.04. On their official page I need to run this command:
composer require laravel/jetstream
Before this I configured environment for laravel and got installed laravel installer globally. After I run this command to get jetstream it says:
[ErrorException] file_put_contents(./composer.json): failed to open stream: Permission denied
I have tried something like:
sudo chown -R $USER ~/.composer/
and
sudo chown -R user ~/.composer/
But then I get this:
No such file or directory
Did you try running it wirh root rights?
sudo composer require laravel/jetstream

Cannot composer dump-autoload - file put contents error?

I'm trying to:
composer dump-autoload
On a Ubuntu 16.04 server.
I get the error:
file_put_contents(/var/www/example.com/site/vendor/composer/autoload_namespaces.php): failed to open stream: Permission denied
I have:
Change permission of storage dir to 755
Made sure the www-data user has correct usage rights
I still get the error. Any ideas on a fix?
First of all
After installing Laravel, you should change the permission of some specific directory.
Use these commands.
// If your project's directory is owned by root then,
sudo chown -R <username> path_to_laravel_project_directory
// Then change these persmissions (from the root of the laravel project directory)
sudo chmod -R 777 storage/
sudo chmod -R 777 bootstrap/cache/
// At the end please generate your project key
php artisan key:generate
// Now you can use
sudo composer dump-autoload
I hope this works.
Try to set these permissions:
sudo chmod -R 755 bootstrap/cache/
sudo chmod -R 755 vendor/composer
sudo chmod -R 755 storage

Laravel error when creating new project: proceed without cache

I'm just starting with laravel. I'm following this laravel guide. My environment is an aws server running php 5.6, I have already installed composer.
https://laravel.com/docs/5.2/quickstart#deleting-tasks
When I type:
composer create-project laravel/laravel quickstart --prefer-dist
I get the following error:
Cannot create cache directory /home/ubuntu/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
How can I fix this? Is this a major problem? If I proceed would I run into trouble after?
Also, is it bad practice to use sudo?
When you installed composer pretty sure you used $ sudo command because of that the ~/.composer folder was created by the root.
Run this to fix the issue:
$ sudo chown -R $USER $HOME/.composer
You can try this method which I used for my project on a LAMP server
sudo composer create-project laravel/laravel quickstart --prefer-dist
After that, you change the permission back to www-data user & group
sudo chown www-data:www-data quickstart\ -R
sudo usermod -a -G www-data ubuntu_user_name

Custom Dokku/Heroku buildpack can't install gems(Permission denied)

When my custom buildpack runs it always fails to install gems manually(gem install foo) because it does not have access to the /var/lib/gems directory.
Error being thrown:
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /var/lib/gems
Is there something I have to setup so my buildpack can install gems like this?
Information:
- Server => Ubuntu 14.04 DigitalOcean Dokku image(Latest)
- Custom Buildpack => Noah-Huppert/buildpack-rack
Try this:
sudo chown -R $USER "/var/lib/gems" or
chmod -R 0777 /var/lib/gems
if you're comfortable with giving all users on the box read/write permissions.

Why does Composer create-project execution for Laravel fail?

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?
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

Resources