Method of Setting File Permission Correctly in Laravel5
- 2021-12-11 07:02:14
- OfStack
Preface
Setting the appropriate file permissions for any Web application is an important part of Web hosting. In this tutorial, you will learn how to properly configure file permissions on an Laravel application hosted on an Linux Web server.
First, determine the user name of the server running Web. Here are some of the defaults
Nginx Use Account on Linux-www-data Apache on Debian system uses account-www-data Apache Usage Account on RedHat System-apacheWe assume that our Web server is running under the account www-data. Now recursively change the owners and group owners of all files and directories.
sudo chown -R www-data:www-data /path/to/laravel
Now set permission 644 for all files and 755 for all directories. Execute the following command.
sudo find /path/to/laravel -type f -exec chmod 644 {} \;
sudo find /path/to/laravel -type d -exec chmod 755 {} \;
For Laravel to work properly, you need to provide the Web server with read and write permissions to store, cache, and any other directories. Therefore, run the following command:
cd /path/to/laravel
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
Your Laravel application is now protected with appropriate permissions. However, since all files have the owner and group owner of the Web server, you may encounter problems making changes through FTP/sFTP. To fix this problem, add your users to the Web server user group:
sudo usermod -a -G www-data <a href="https://www.linuxidc.com/topicnews.aspx?tid=2" target="_blank" title="Ubuntu">Ubuntu</a>
Summarize