How to configure folder permissions for Laravel?

Laravel is a famous PHP framework which provide a variety of features for professional programming for PHP fans. My purpose is not learning of this framework on this essay. I intent to share my knowledge about configuration of Laravel permissions. A challenge that was very annoying for me.

Ubuntu is my server and I also use Nginx as web server. In following I explain each step ordinary.

1. Firstly, What I typically do, is changing all files/folders group to www-data with sudo chgrp -R www-data laravel-folder. This way I am still an owner and webserver has group permissions.

2. When www-data has group ownership, sudo chmod -R g+w app/storage allows webserver to write to a storage subfolder. Or alternatively you can do sudo chmod -R 775 app/storage. Don’t use 777, there is no need to allow everyone to write to your folders.

3. For all new assets I always collectively change group ownership. Or, if there are new files in many places, just again do sudo chgrp -R www-data laravel-folder. One command and everything has proper group ownership. There is no need to change default permissions of public folder (755). Nginx will not save files there.

4. All files sent by users should be located in storage. You can make a subfolder for avatars, another one for other user files. This is why this folder is called storage (self-explanatory). It is writeable by webserver so nginx can create files/folders there.

5. When you adjust permissions / group ownership like I described above, there should be no problem with artisan or CLI commands.

I suggest you read this How to Install Laravel with an Nginx Web Server on Ubuntu 14.04 article.

I hope essay has been useful for you. Do not deprive me of your opinion.