Creating directories with correct permissions for Laravel [duplicate]
Solution 1:
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.
- Location of created projects should be in
/var/www/html
folder but can be anywhere. - Install composer and set that up globally so you can install
laravel
globally with it. - The permissions in
/var/www/html
need to be set up such that you don't needroot
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:
-
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
-
-
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-datasudo 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
Solution 2:
mkdir -m a=rwx myDir
or
mkdir --mode=a=rwx myDir
Run mkdir --help
for more info.