Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to install Prestissimo to an Ubuntu 16.04 server, but that leads to an error:

$ composer global require "hirak/prestissimo:^0.3" Changed current directory to /home/kramer65/.composer     [ErrorException]   file_put_contents(./composer.json): failed to open stream: Permission denied   require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] [<packages>]... 

I'm logged in as user kramer65, so I wouldn't know why it can't write to my home folder. My normal reaction to a permission denied is to use sudo, but composer then always says:

Do not run Composer as root/super user! See https://getcomposer.org/root for details

Any idea how I can solve this?

like image 955
kramer65 Avatar asked Dec 18 '16 20:12

kramer65


People also ask

How do I change the composer json file?

To update your packages json file is. Run composer update (on your local machine) to update the required packages and re-generate a composer. lock file. Commit the updated composer.

Where is composer json file?

composer. json is a JSON file placed in the root folder of PHP project. Its purpose is to specify a common project properties, meta data and dependencies, and it is a part of vast array of existing projects.

What is composer installed json?

Description. A installed. json file was discovered. Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

How to solve Composer install permissions issue in Ubuntu 20 04?

I'm using Ubuntu 20.04. Does anyone know what should I do? This issue can easily be solved by creating the lock file and then modifying the ownership. composer install is trying to create a .composer.lock file in your project directory, so php should have permission to do that.

Why is Composer install not working?

composer install is trying to create a .composer.lock file in your project directory, so php should have permission to do that. A quick hack is to use sudo composer install , but this is not the recommended way.

How to solve Composer install lock file issue?

This issue can easily be solved by creating the lock file and then modifying the ownership. composer install is trying to create a .composer.lock file in your project directory, so php should have permission to do that.

How do I remove composer from Ubuntu?

You may also need to remove the .composer file from the current directory, to do this open up a terminal window and type this command: For me, in Ubuntu 18.04. I needed to chown inside ~/.config/composer/ Then global commands work. In my case I don't have issues with ~/.composer.


1 Answers

I had this problem to install laravel/lumen.

It can be resolved with the following command:

$ sudo chown -R $USER ~/.composer/ 
like image 147
Samuel Martins Avatar answered Oct 05 '22 04:10

Samuel Martins