How to set Laravel permissions in Ubuntu
Solution 1:
Here we will give 755 permission for storage and boot folder
//in the project folder
sudo chmod -R 755 bootstrap/cache
sudo chmod -R 755 storage
755 means read and execute access for everyone and also write access for the owner of the file. When you perform chmod 755 filename command you allow everyone to read and execute the file, the owner is allowed to write to the file as well. So, there should be no permission to everyone else other than the owner to write to the file, 755 permission is required.
Solution 2:
For give all files and folder ownership as the webserver user. run below command.
sudo chown -R www-data:www-data /var/www/your-project-path
OR
// in project folder
sudo chown -R www-data:www-data ./
chown
is used for setting the ownership of folder or file. The explanation of -R
had been answered (it recursively descends to all sub-folders).
So the last thing is about www-data written repeated.www-data:www-data
the first one is user, the second is group. Your username can be added as a member of www-data
group, by this command sudo adduser user www-data
, user can be replaced with your username. That command will result in user www-data
.
Here, set 644 permission for all files and 755 for all directories. run below command.
sudo find /var/www/your-project-path -type f -exec chmod 644 {} \;
sudo find /var/www/your-project-path -type d -exec chmod 755 {} \;
OR
// in project folder
sudo find . -type f -exec chmod 644 {} \;
sudo find . -type d -exec chmod 755 {} \;
Here, we will give proper read and write permission for files and folder.
cd /var/www/your-project-path
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
chgrp command in Linux is used to change the group ownership of a file or directory. All files in Linux belong to an owner and a group. You can set the owner by using “chown” command, and the group by the “chgrp” command.
permission all the files have owner and group-owner to web server. “systemusername” is a system username. you have to replace with your system username.
sudo usermod -a -G www-data systemusername