Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Tutorials»How to Setup Laravel File Permissions Correctly

    How to Setup Laravel File Permissions Correctly

    RahulBy RahulMay 5, 20192 Mins ReadUpdated:October 4, 2021

    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 Linux web server.

    First of all, Identify the user name under which the webserver is running. Here are some default cases

    • Nginx on Linux uses account – www-data
    • Apache on Debian systems uses account – www-data
    • Apache on Redhat systems uses account – apache

    Setup Laravel File Permissions

    Assuming that the webserver is running with www-data user on your system . So all files should have the same user ownership as the webserver user. Use the chown command to set owner and group-owner for all files and directories recursively.

    sudo chown -R www-data:www-data /path/to/laravel 
    

    Next, set 644 permission for all files and 755 for all directories. We can achieve this with chmod command and find commands together as below:

    sudo find /path/to/laravel -type f -exec chmod 644 {} \; 
    sudo find /path/to/laravel -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/to/laravel 
    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 
    

    Read our another tutorial to properly create an SFTP account for the web server document root.

    Conclusion

    In this tutorial, You have learned to properly configure file permissions for the Laravel applications.

    Laravel permission
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Remove a directory from Git Repository
    Next Article How to sort du -h command output by size

    Related Posts

    What is the /etc/aliases file

    2 Mins Read

    What is the /etc/nsswitch.conf file in Linux

    2 Mins Read

    How to Setup Squid Proxy Server on Ubuntu and Debian

    Updated:June 17, 20225 Mins Read

    How to Delete a Let’s Encrypt Certificate using Certbot

    Updated:June 3, 20222 Mins Read

    How to Install Latest Git on Ubuntu 22.04

    Updated:May 31, 20222 Mins Read

    How To Install LibreOffice on Ubuntu 22.04

    Updated:May 23, 20222 Mins Read

    4 Comments

    1. Arslan on October 2, 2021 2:42 pm

      thank you Man ,
      you made my day

      Reply
    2. Bill on June 18, 2021 6:01 pm

      Probably want to make those permissions 664 and 775 respectively, given that you’re adding the current user to the group at the end there.

      Reply
    3. hreherher on April 8, 2021 12:10 pm

      +1

      Reply
    4. Piotr on July 15, 2019 2:06 pm

      That article are not worth to read. You make a lot of mistakes.

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    • What is difference between var, let and const in JavaScript?
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.