6

I’m a developer. A few days ago I started using Laravel on Ubuntu. When I use the terminal to create a new directory it appears with a padlock on it. Even logged in as root I have to give it permission with chmod.

How can I create directories with all permissions for all kind of users?

3
  • 1
    What is the exact terminal command that you are using? what is the output of the umask command? Dec 6, 2017 at 22:36
  • Actually I’m using laravel, so every time I create a new migration or send files from a form this happens
    – Edson Lima
    Dec 7, 2017 at 0:14
  • using chmod g+s /var/www/app_root_dir can be usesfull in few cases (during developement) - that way every new file and dir created in /var/www/app_root_dir would inherit group of app_root_dir (ie www-data). When you decide to deploy it as production you should defenitley follow laravels documentation recommendations.
    – inemanja
    Oct 17, 2019 at 9:07

2 Answers 2

15

When using laravel on Ubuntu you want to set it up in the following ways that will ensure you don't use or need root access for the created files.

  1. Location of created projects should be in /var/www/html folder but can be anywhere.
  2. Install composer and set that up globally so you can install laravel globally with it.
  3. The permissions in /var/www/html need to be set up such that you don't need root privileges to operate on files there as it is in your case.

Install Composer:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

Check Install:

composer -V

Install laravel using composer:

composer global require "laravel/installer=~1.1"

Check install:

laravel -V

Setup folder permissions for laravel:

  1. Temporary setup in /var/www/html:

    • Add self to group www-data:

      sudo usermod -a -G www-data $USER
      
    • Change ownership of laravel folder:

      sudo chgrp -R www-data /var/www/html/project
      
    • Tip: to setup laravel storage:

      sudo chmod -R 775 /var/www/html/project/storage
      
  2. Permanent solution:

    • Make default ownership of folders in /var/www/html $USER:www-data, so any new creation will assume the permissions of your user and the group www-data

      sudo setfacl -d -R -m u:$USER:rwx,g:www-data:rwx,o:rx /var/www/html
      

Now simply add any user to the www-data group to have them have rwx access to any created laravel project in /var/www/html. A reboot will be required.

Usage:

laravel new /var/www/html/new-project
1
mkdir -m a=rwx myDir

or

mkdir --mode=a=rwx myDir

Run mkdir --help for more info.

Not the answer you're looking for? Browse other questions tagged .