How to fix Error: mkdir(): Permission denied when running composer

iliketolearn

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?

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.

  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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to fix Permission Denied (Public key) error?

From Dev

How to fix 'Permission Denied' when using csshX

From Dev

Permission denied @ dir_s_mkdir Error

From Dev

Sudo mkdir fails due to permission denied error

From Dev

composer laravel create-project windows 10 mkdir permission denied

From Dev

how to solve TAR: CANNOT MKDIR PERMISSION DENIED

From Dev

How do I overcome my permission denied error when running with sudo?

From Dev

"Error: Permission denied" when running firebase init and choosing database

From Dev

Error installing rails - permission denied when running 'gem install rails'

From Dev

How do I fix the DISABLE TRIGGER permission denied in database error?

From Dev

How to fix “Permission denied” when trying to edit a file on aws server?

From Dev

Get "Error: EACCES: permission denied, mkdir '/dir/' when trying to generate ASP.NET Web Application

From Dev

laravel mkdir() Permission denied

From Dev

mkdir(): Permission denied Laravel

From Dev

Capistrano mkdir permission denied

From Dev

Warning: mkdir(): Permission denied

From Dev

laravel mkdir() Permission denied

From Dev

PHP: mkdir() permission denied

From Dev

Laravel Composer Update Error - Permission Denied

From Dev

Windows 10: How can I fix "access denied" when using mkdir

From Dev

node application getting "Error: EACCES: permission denied, mkdir '.tmp'

From Dev

Permission denied error for running command on ubuntu

From Dev

permission denied when running wordpress from vagrant

From Dev

Permission denied when running make install

From Dev

Permission denied when running make install

From Dev

Permission denied when running .sh scripts

From Dev

Permission denied when running sh file

From Dev

Permission denied when running a container (docker 1.12.5)

From Dev

Permission denied when running .sh scripts

Related Related

  1. 1

    How to fix Permission Denied (Public key) error?

  2. 2

    How to fix 'Permission Denied' when using csshX

  3. 3

    Permission denied @ dir_s_mkdir Error

  4. 4

    Sudo mkdir fails due to permission denied error

  5. 5

    composer laravel create-project windows 10 mkdir permission denied

  6. 6

    how to solve TAR: CANNOT MKDIR PERMISSION DENIED

  7. 7

    How do I overcome my permission denied error when running with sudo?

  8. 8

    "Error: Permission denied" when running firebase init and choosing database

  9. 9

    Error installing rails - permission denied when running 'gem install rails'

  10. 10

    How do I fix the DISABLE TRIGGER permission denied in database error?

  11. 11

    How to fix “Permission denied” when trying to edit a file on aws server?

  12. 12

    Get "Error: EACCES: permission denied, mkdir '/dir/' when trying to generate ASP.NET Web Application

  13. 13

    laravel mkdir() Permission denied

  14. 14

    mkdir(): Permission denied Laravel

  15. 15

    Capistrano mkdir permission denied

  16. 16

    Warning: mkdir(): Permission denied

  17. 17

    laravel mkdir() Permission denied

  18. 18

    PHP: mkdir() permission denied

  19. 19

    Laravel Composer Update Error - Permission Denied

  20. 20

    Windows 10: How can I fix "access denied" when using mkdir

  21. 21

    node application getting "Error: EACCES: permission denied, mkdir '.tmp'

  22. 22

    Permission denied error for running command on ubuntu

  23. 23

    permission denied when running wordpress from vagrant

  24. 24

    Permission denied when running make install

  25. 25

    Permission denied when running make install

  26. 26

    Permission denied when running .sh scripts

  27. 27

    Permission denied when running sh file

  28. 28

    Permission denied when running a container (docker 1.12.5)

  29. 29

    Permission denied when running .sh scripts

HotTag

Archive