Saturday, October 31, 2020

Laravel Permissions

 As per laravel docs:
----------------------
Directory Permissions

After installing Laravel, you may need to configure some permissions. Directories within the storage
and the bootstrap/cache directories should be writable by your web server or Laravel will not run.

Solution:
--------------
step1 - setting root directory owner and group
-------

sudo chown -R ubuntu:www-data /path/to/your/laravel/root/directory

step2 - setting file and folder permissions:
-------

sudo find /path/to/your/laravel/root/directory -type f -exec chmod 664 {} \;    
sudo find /path/to/your/laravel/root/directory -type d -exec chmod 775 {} \;

step3 - then give the webserver the rights to read and write to storage and cache
-------

sudo chgrp -R www-data storage bootstrap/cache

step4 - then you need to give read and write permissions to the webserver for storage, cache and any other directories the webserver needs to upload or write too
-------

sudo chmod -R ug+rwx storage bootstrap/cache

Now, you're secure and your website works, AND you can work with the files fairly easily