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 need
root privileges to operate on files there as it is in your case.
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
Install laravel using composer:
composer global require "laravel/installer=~1.1"
Setup folder permissions for laravel:
Temporary setup in
Add self to group
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
Make default ownership of folders in
$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.
laravel new /var/www/html/new-project