file_put_contents(./ config .json):未能打开流:权限被拒绝

时间:2023-01-16 20:37:26

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

我正试着在Ubuntu 16.04服务器上安装“最快”,但这导致了一个错误:

$ 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:

我以用户kramer65登录,所以我不知道为什么它不能写入我的home文件夹。我对被拒绝的许可的正常反应是使用sudo,但是作曲家总是说:

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

不要运行Composer作为根/超级用户!有关详细信息,请参阅https://getcomposer.org/root

Any idea how I can solve this?

知道我怎么解决这个问题吗?

5 个解决方案

#1


73  

I had this problem to install laravel/lumen.

我有安装laravel/lumen的问题。

I can resolve with the following command:

我可以用以下命令来解决:

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

#2


7  

To resolve this, you should open up a terminal window and type this command:

要解决这个问题,您应该打开一个终端窗口,输入以下命令:

sudo chown -R user ~/.composer (with user being your current user, in your case, kramer65)

sudo chown -R用户~/.composer(用户是您的当前用户,在您的案例中是kramer65)

After you have ran this command, you should have permission to run your composer global require command.

在运行此命令之后,您应该拥有运行composer global require命令的权限。

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:

您可能还需要从当前目录中删除.composer文件,要做到这一点,请打开终端窗口,输入以下命令:

sudo rm -rf .composer

sudo rm射频.composer

#3


1  

In my case, .composer was owned by root, so I did sudo rm -fr .composer and then my global require worked.

在我的例子中,.composer属于root用户,所以我做了rm -fr .composer,然后我的全球需求工作了。

Be warned! You don't wanna use that command if you are not sure what you are doing.

警告!如果你不确定自己在做什么,就不要使用这个命令。

#4


1  

I faced this issue as well but in my case, I was in wrong directory. Check the directory you are working

我也遇到了这个问题,但在我的情况下,我在错误的目录。检查您正在工作的目录

#5


0  

This might be super edge case, but if you are using Travis CI and taking advantage of caching, you might want to clear all cache and retry.

这可能是super edge的情况,但是如果您使用Travis CI并利用缓存,您可能需要清除所有缓存并重试。

Fixed my issue when I was going from sudo to non sudo builds.

修正了从sudo到非sudo构建时的问题。

#1


73  

I had this problem to install laravel/lumen.

我有安装laravel/lumen的问题。

I can resolve with the following command:

我可以用以下命令来解决:

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

#2


7  

To resolve this, you should open up a terminal window and type this command:

要解决这个问题,您应该打开一个终端窗口,输入以下命令:

sudo chown -R user ~/.composer (with user being your current user, in your case, kramer65)

sudo chown -R用户~/.composer(用户是您的当前用户,在您的案例中是kramer65)

After you have ran this command, you should have permission to run your composer global require command.

在运行此命令之后,您应该拥有运行composer global require命令的权限。

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:

您可能还需要从当前目录中删除.composer文件,要做到这一点,请打开终端窗口,输入以下命令:

sudo rm -rf .composer

sudo rm射频.composer

#3


1  

In my case, .composer was owned by root, so I did sudo rm -fr .composer and then my global require worked.

在我的例子中,.composer属于root用户,所以我做了rm -fr .composer,然后我的全球需求工作了。

Be warned! You don't wanna use that command if you are not sure what you are doing.

警告!如果你不确定自己在做什么,就不要使用这个命令。

#4


1  

I faced this issue as well but in my case, I was in wrong directory. Check the directory you are working

我也遇到了这个问题,但在我的情况下,我在错误的目录。检查您正在工作的目录

#5


0  

This might be super edge case, but if you are using Travis CI and taking advantage of caching, you might want to clear all cache and retry.

这可能是super edge的情况,但是如果您使用Travis CI并利用缓存,您可能需要清除所有缓存并重试。

Fixed my issue when I was going from sudo to non sudo builds.

修正了从sudo到非sudo构建时的问题。