How To Set the Correct File and Folder Permissions for Laravel Applications on Ubuntu Server

Setting the proper file permission for any web application is an important part of web hosting. In this tutorial, you will learn how to properly configure file permissions on a Laravel application hosted on a Ubuntu web server.

First of all, Identify the user name under which the webserver is running. In Ubuntu, both Apache and Nginx use the www-data account.

Now change the owner and group-owner for all files and directories recursively.

sudo chown -R www-data:www-data /path/of/laravel-app

Now set permission 644 for all files and 755 for all directories. In order to set the permission just execute the following command.

sudo find /path/of/laravel-app -type f -exec chmod 644 {} \;
sudo find /path/of/laravel-app -type d -exec chmod 755 {} \;

To make Laravel work properly, you need to give read and write permissions to the web server for storage, cache, and any other directories. So run the following commands:

cd /path/of/laravel-app
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache 

Now, your Laravel application is secured with proper permissions. But as all the files have owner and group-owner to web server, you may face an issue during changes via FTP/sFTP. To solve this problem add your user to the webserver user group:

sudo usermod -a -G www-data ubuntu

That's it and now we have successfully configured the proper permissions for our Laravel application.

Get in touch 👋

Feel free to email me about anything. Want some advice? Give some feedback?

You can also reach me around the web: GitHub, LinkedIn, Twitter, DEV, Facebook, Instagram, CodePen