如何修复错误:mkdir():运行作曲家时权限被拒绝 [英] How to fix Error: mkdir(): Permission denied when running composer

查看:164
本文介绍了如何修复错误:mkdir():运行作曲家时权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ec2图像,尝试创建新的laravel项目时出现以下错误。


[ErrorException] mkdir() :权限被拒绝


以下是命令:

  composer create-project laravel / laravel mydir 

我可以用我的文件夹写入文件夹ec2-user用户名,但是我需要为作曲家写权限吗?

解决方案

快速解答:



出于安全原因,让 root 作为所有者,只允许自己读取,写入和执行


  1. 更改目录



    < blockquote>

    cd / var / www /



  2. 更改组所有权


    sudo chown -Rv root:$ USER。



  3. 添加特权我们组的边缘


    sudo chmod -Rv g + rw。



  4. 对于总决赛,继续并创建新的laravel项目


    composer create-project laravel / laravel projectName -prefer-dist



恭喜,我们完成了。 :)



深度说明



解决方案的解释:
默认情况下,您有两个用户; root $ USER (这是全局变量,但实际名称是您输入的用户名)。创建的每个用户也都带有一个组。因此,如果我的用户名是 john ,则我有一个名为 john 的组。
有很多方法可以解决此问题,但是由于某些原因,我还是选择了此路线:


  1. 我仍然想要 root 出于安全原因成为文件的所有者。


  2. 我在本地主机上工作,因此


为实现这一目标,我们将不存在任何其他(来宾)用户需要编辑组所有权并添加适当的权限。我们将保留 others 的原样,只允许他们读取和执行文件。



所以让我们开始吧:


  1. 为了避免出错,我喜欢进入要对其进行更改的目录中,因此首先我们需要输入


    cd / var / www /



  2. 我们将需要更改将要使用的目录的组所有权。我们将进入该目录,并在此目录下创建所有将来的目录和文件。因此从现在开始,基本上所有子目录都将归我们小组所有。


    sudo chown -Rv root:$用户。







chown =命令 ch ange own er。



-R =递归-基本上是说要对该目录中的所有目录执行相同的命令。



-v =冗长-我们在这里表示是为了向我们展示实际情况,以保持最新。



root:$ USER =这是我们正在设置所有权的情况。冒号(:)之前的第一个单词指出 root 将是单个所有者。冒号(:)之后的第二个单词表示组所有者将是 $ USER (当前用户)。



=这仅表示在此目录中。






  1. 现在,我们将为我们的组添加正确的特权。请记住,这是我们允许 root 成为主要所有者的地方,而仅允许我们自己进行更改(当然,除了 root )。如前所述,这不允许其他用户进行任何更改。


    sudo chmod -Rv g + rw。







chmod =命令 ch ange mod 修改,在这种情况下为特权。



-Rv =递归&详细



g =这说明谁将收到修改。在我们的案例中,g-group其他选项是u-user和o-other。



+ =表示添加



r =表示已读



w =表示写






  1. 现在我们完成了。尝试创建一个新的laravel项目。


    composer create-project laravel / laravel projectName` --prefer-dist



注意:如果此方法无效,请输入命令 ls -al | grep $ USER 放在 / var / www / 目录中。



如果您得到了:
drwxrw-rx



您缺少该组的可执行文件( x )特权。第一个 x 供用户使用,最后一个 x 供其他用户使用。该组应该有中间的 x



运行以下命令,您应该都准备就绪:



sudo chmod -Rv g + x。



现在,如果您运行 ls -al | grep $ USER ,您应该得到:



drwxrwxr-x


I have a ec2 image and get the following error when trying to create a new laravel project.

[ErrorException] mkdir(): Permission denied

Here is the command:

composer create-project laravel/laravel mydir

I can write to the folder with my ec2-user username but do I need to add permission for composer to write?

解决方案

Quick Answer:

For security reasons, lets keep root as the owner and just allow ourselves to read, write, and execute within the area which we will be working in.

  1. Change directories

    cd /var/www/

  2. Change group ownership

    sudo chown -Rv root:$USER .

  3. Add priviledges to our group

    sudo chmod -Rv g+rw .

  4. For the grand finale, go ahead and create your new laravel project

    composer create-project laravel/laravelprojectName--prefer-dist

Congratulations, We're done. :)

In-Depth Explanation

Explanation behind the solution: By default you have two users; root and $USER(this is the global variable, but the actual name is whatever you put as your username). Every user created comes with a group as well. So if my username is john, I have a group called john. There are many ways to solve this problem but I perfer this route for a few reasons:

  1. I still want root to be the owner of the files for security reason.

  2. I am working in a localhost so there shouldn't be any other (guest)users writing on my files.

In order to achieve this we will need to edit the group ownership and add the proper permissions. We will leave the others as is and only allow them to read and execute the files.

So lets get started:

  1. I like being in the directory that I am making changes to in order to avoid mistakes so first we will need to enter the the directory which we will be working in.

    cd /var/www/

  2. We will need to change the group ownership of the directories which we will be working in. Starting from the directory which we are in and all the future directories and files we will create underneath this directory. So basically any children directories from now on will be own by our group.

    sudo chown -Rv root:$USER .

chown = command to change owner.

-R = Recursive - This is basically stating to perform the same command to all the directories within this directory.

-v = verbose - we are stating here to keep us updated by showing us what is actually happening.

root:$USER = This is were we are setting the ownership. The first word before the colon(:) states the root will be the single owner. The second word after the colon(:) states that the group owner will be $USER(the current user).

. = This just means 'here, in this directory'.

  1. Now we are going to add the right privileges to our group. Keep in mind this is where we allow root to be the primary owner while ONLY allowing ourself's to create changes(of course, besides root). As I mentioned before, this does not allow other users to create any changes what so ever.

    sudo chmod -Rv g+rw .

chmod = command to change modifications, in this case, privileges.

-Rv = Recursive & Verbose

g = this states who will receive the modifications. In our case g-group Other options are u-user and o-other.

+ = symbolizes add

r = symbolizes read

w = symbolizes write

  1. Now we are done. Try creating a new laravel project.

    composer create-project laravel/laravelprojectName` --prefer-dist

Note: If this is not working, enter the command ls -al | grep $USER while inside the /var/www/ directory.

If you get this: drwxrw-r-x

You are missing the executable(x) privilege for the group. The first x is for the user and last x is for others. There should be middle x for the group.

Run the following command and you should be all set to go:

sudo chmod -Rv g+x .

Now if you run ls -al | grep $USER, you should get:

drwxrwxr-x

这篇关于如何修复错误:mkdir():运行作曲家时权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆