php 如何修复错误:mkdir():运行作曲家时权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30266250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix Error: mkdir(): Permission denied when running composer
提问by iliketolearn
I have a ec2 image and get the following error when trying to create a new laravel project.
我有一个 ec2 映像,并在尝试创建新的 Laravel 项目时收到以下错误。
[ErrorException] mkdir(): Permission denied
[ErrorException] mkdir(): 权限被拒绝
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?
我可以用我的 ec2-user 用户名写入文件夹,但我需要为 Composer 添加写入权限吗?
回答by Oscar
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.
出于安全原因,让我们保持root
所有者身份,只允许自己在我们将要工作的区域内读取、写入和执行。
Change directories
cd /var/www/
Change group ownership
sudo chown -Rv root:$USER .
Add priviledges to our group
sudo chmod -Rv g+rw .
For the grand finale, go ahead and create your new laravel project
composer create-project laravel/laravel
projectName--prefer-dist
更改目录
cd /var/www/
更改组所有权
sudo chown -Rv root:$USER .
为我们的群组添加特权
sudo chmod -Rv g+rw .
对于大结局,继续创建您的新 Laravel 项目
composer create-project laravel/laravel
项目名--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:
解决方案背后的解释:默认情况下你有两个用户;root
和$USER
(这是全局变量,但实际名称是您输入的用户名)。创建的每个用户也都带有一个组。因此,如果我的用户名是john
,则我有一个名为 的组john
。有很多方法可以解决这个问题,但出于以下几个原因,我更喜欢这条路线:
I still want
root
to be the owner of the files for security reason.I am working in a localhost so there shouldn't be any other (guest)users writing on my files.
root
出于安全原因,我仍然想成为文件的所有者。我在本地主机上工作,所以不应该有任何其他(来宾)用户在我的文件上写入。
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.
为了实现这一点,我们需要编辑组所有权并添加适当的权限。我们将保持others
原样,只允许他们读取和执行文件。
So lets get started:
让我们开始吧:
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/
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 .
我喜欢在我正在更改的目录中以避免错误,所以首先我们需要输入我们将在其中工作的目录。
cd /var/www/
我们将需要更改我们将在其中工作的目录的组所有权。从我们所在的目录以及我们将在此目录下创建的所有未来目录和文件开始。所以基本上从现在开始的所有儿童目录都将归我们组所有。
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 theroot
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'.
chown
=命令CH安格自己的呃。
-R
= Recursive - 这基本上是声明对该目录中的所有目录执行相同的命令。
-v
= 详细 - 我们在这里声明是为了通过向我们展示实际发生的事情来让我们保持最新状态。
root:$USER
= 这是我们正在设置所有权。冒号 (:) 前的第一个词表示root
will 是唯一的所有者。冒号 (:) 之后的第二个字表示组所有者将是$USER
(当前用户)。
.
= 这只是意味着“在这里,在这个目录中”。
- 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, besidesroot
). As I mentioned before, this does not allow other users to create any changes what so ever.sudo chmod -Rv g+rw .
- 现在我们要为我们的组添加正确的权限。请记住,这是我们允许
root
成为主要所有者的地方,同时只允许我们自己创建更改(当然,除此之外root
)。正如我之前提到的,这不允许其他用户进行任何更改。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
chmod
=命令CH安格MODifications,在这种情况下,权限。
-Rv
= 递归和详细
g
= 这说明谁将收到修改。在我们的例子中,g-group 的其他选项是 u-user 和 o-other。
+
= 表示添加
r
= 象征阅读
w
= 象征写
- Now we are done. Try creating a new laravel project.
composer create-project laravel/laravel
projectName` --prefer-dist
- 现在我们完成了。尝试创建一个新的 Laravel 项目。
composer create-project laravel/laravel
项目名称` --prefer-dist
Note:If this is not working, enter the command ls -al | grep $USER
while inside the /var/www/
directory.
注意:如果这不起作用,请ls -al | grep $USER
在/var/www/
目录中输入命令。
If you get this:
drwxrw-r-x
如果你得到这个:
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.
您缺少x
该组的可执行 ( ) 权限。第一个x
是给用户的,最后一个x
是给其他人的。x
小组应该有中间人。
Run the following command and you should be all set to go:
运行以下命令,你应该准备好了:
sudo chmod -Rv g+x .
sudo chmod -Rv g+x .
Now if you run ls -al | grep $USER
, you should get:
现在如果你运行ls -al | grep $USER
,你应该得到:
drwxrwxr-x
drwxrwxr-x
回答by Jens A. Koch
add "www" group and add your user to this group
sudo groupadd www sudo usermod -a -G www ec2-user
logout/login
set ownership and write permissions
sudo chown -R root:www /var/www sudo chmod 2775 /var/www find /var/www -type d -exec sudo chmod 2775 {} + find /var/www -type f -exec sudo chmod 0664 {} +
添加“www”组并将您的用户添加到该组
sudo groupadd www sudo usermod -a -G www ec2-user
注销/登录
设置所有权和写权限
sudo chown -R root:www /var/www sudo chmod 2775 /var/www find /var/www -type d -exec sudo chmod 2775 {} + find /var/www -type f -exec sudo chmod 0664 {} +
Referencing: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html
参考:http: //docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html
回答by Stefan Hanke
I ran into the similar ErrorException, when creating an additional project inside the Homestead/Vagrant environment. I had previously added folders and path to the Homestead.yaml.
在 Homestead/Vagrant 环境中创建附加项目时,我遇到了类似的 ErrorException。我之前已经向 Homestead.yaml 添加了文件夹和路径。
The answers of Oscar and Jens A. Koch pointed into the right direction, but go too far on my dev-machine.
Oscar 和 Jens A. Koch 的答案指出了正确的方向,但在我的开发机器上走得太远了。
Working narrower solution inside Homestead-Box:
在 Homestead-Box 内工作更窄的解决方案:
sudo mkdir <ProjectDir>
sudo chgrp vagrant <ProjectDir>
sudo chmod g+wx <ProjectDir>
composer create-project --prefer-dist laravel/laravel <Project>
回答by Ahmed Shaaban Elgendy
Run the following commands
运行以下命令
cd /var/www
sudo chown -R $USER:www-data html/
sudo chmod -R 775 html/
回答by NicuVlad
I had the same problem and executing the command using sudojust worked for me:
我遇到了同样的问题,使用sudo执行命令对我有用:
sudo composer create-project laravel/laravel mydir
回答by veritaS
This Problem with a Vagrantbox
流浪盒的这个问题
If you tried to install something with composer in a new vagrant box, it is possible that when installing the vagrant you have specified the path you are allowed to use.
如果你尝试在一个新的 vagrant 盒子中安装 composer 的东西,可能在安装 vagrant 时你已经指定了你被允许使用的路径。
So check your personal .yml file in order to check this under \ansible\vars
因此,请检查您的个人 .yml 文件,以便在 \ansible\vars 下进行检查
there you have something like this
你有这样的事情
vagrant_local:
vm:
name: oxideshop
hostname: oxideshop.local
aliases:
- www.oxideshop.local
app_shared_folder:
source: oxideshop
target: /var/www/oxideshop
You have to make sure, that the app_shared_folder target is the same you use for the composer installation.
您必须确保 app_shared_folder 目标与您用于 Composer 安装的目标相同。
Example:
例子:
composer create-project oxid-esales/oxideshop-project /var/www/oxideshopdev-b-6.1-ce
作曲家创建项目 oxid-esales/oxideshop-project /var/www/oxideshopdev-b-6.1-ce
回答by Jyotirmoy Bhattacharjee
Make sure that you have read/write folder permission. LIKE: sudo chown -R USER NAME:www-data /PROJECT PATH/USER NAME/PROJECT NAME/
确保您具有读/写文件夹权限。喜欢:sudo chown -R 用户名:www-data /PROJECT PATH/USER NAME/PROJECT NAME/
Example:
例子:
$ sudo chown -R tubai:www-data /home/tubai/firstlara/
回答by Y. Joy Ch. Singha
Make sure that you have read/write folder permission. It works to me.
确保您具有读/写文件夹权限。它对我有用。
Like in ubuntu
就像在 ubuntu 中一样
var/www/html
So if you want to make dir in html
folder then first give permission to html
folder. Then you are done. Thanks.
因此,如果您想在html
文件夹中创建 dir,请先授予html
文件夹权限。然后你就完成了。谢谢。
回答by la-sudo
cd to the directory where you currently want to install laravel and change directory access with
cd 到您当前要安装 laravel 的目录并使用以下命令更改目录访问权限
sudo chmod -R 777 ./
type your password and you are good to resume to the installation
输入您的密码,您可以继续安装