Skip to content

Instantly share code, notes, and snippets.

@muhozi
Last active October 21, 2024 23:54

Revisions

  1. muhozi revised this gist Apr 26, 2018. 2 changed files with 79 additions and 33 deletions.
    33 changes: 0 additions & 33 deletions Larave-permission.md
    Original file line number Diff line number Diff line change
    @@ -1,33 +0,0 @@
    There are basically two ways to setup your ownership and permissions. Either you give yourself ownership or you make the webserver the owner of all files.

    Webserver as owner (the way most people do it):

    assuming www-data is your webserver user.

    sudo chown -R www-data:www-data /path/to/your/laravel/root/directory
    if you do that, the webserver owns all the files, and is also the group, and you will have some problems uploading files or working with files via FTP, because your FTP client will be logged in as you, not your webserver, so add your user to the webserver user group:

    `sudo usermod -a -G www-data ubuntu`
    Of course, this assumes your webserver is running as www-data (the Homestead default), and your user is ubuntu (it's vagrant if you are using Homestead).

    Then you set all your directories to 755 and your files to 644... SET file permissions

    sudo find /path/to/your/laravel/root/directory -type f -exec chmod 644 {} \;
    SET directory permissions

    sudo find /path/to/your/laravel/root/directory -type d -exec chmod 755 {} \;
    Your user as owner

    I prefer to own all the directories and files (it makes working with everything much easier), so I do:

    sudo chown -R my-user:www-data /path/to/your/laravel/root/directory
    Then I give both myself and the webserver permissions:

    sudo find /path/to/your/laravel/root/directory -type f -exec chmod 664 {} \;
    sudo find /path/to/your/laravel/root/directory -type d -exec chmod 775 {} \;
    Then give the webserver the rights to read and write to storage and cache

    Whichever way you set it up, then you need to give read and write permissions to the webserver for storage, cache and any other directories the webserver needs to upload or write too (depending on your situation), so run the commands from bashy above :

    sudo chgrp -R www-data storage bootstrap/cache
    sudo chmod -R ug+rwx storage bootstrap/cache
    79 changes: 79 additions & 0 deletions Laravel-permission.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    # Setting up proper permissions to a laravel directory

    There are basically two ways to setup your ownership and permissions. Either you give yourself ownership or you make the webserver the owner of all files.

    ## Webserver as owner (the way most people do it):

    Assuming `www-data` is your webserver user.



    ```sh
    sudo chown -R www-data:www-data /path/to/your/laravel/root/directory
    ```


    f you do that, the webserver owns all the files, and is also the group, and you will have some problems uploading files or working with files via FTP, because your FTP client will be logged in as you, not your webserver, so add your user to the webserver user group:

    ```sh
    sudo usermod -a -G www-data ubuntu
    ```


    Of course, this assumes your webserver is running as `www-data` (the Homestead default), and your user is `ubuntu` (it's vagrant if you are using Homestead).

    Then you set all your directories to 755 and your files to 644...

    ***SET file permissions***

    ```sh
    sudo find /path/to/your/laravel/root/directory -type f -exec chmod 644 {} \;
    ```


    ***SET directory permissions***

    ```sh
    sudo find /path/to/your/laravel/root/directory -type d -exec chmod 755 {} \;
    ```



    ## Your user as owner

    I prefer to own all the directories and files (it makes working with everything much easier), so I do:

    ```sh
    sudo chown -R my-user:www-data /path/to/your/laravel/root/directory
    ```


    Then I give both myself and the webserver permissions:

    ```sh
    sudo find /path/to/your/laravel/root/directory -type f -exec chmod 664 {} \;
    ```



    ```sh
    sudo find /path/to/your/laravel/root/directory -type d -exec chmod 775 {} \;
    ```


    Then give the webserver the rights to read and write to storage and cache

    Whichever way you set it up, then you need to give read and write permissions to the webserver for `storage`, `cache` and any other directories the webserver needs to upload or write too (depending on your situation), so run the commands from bashy above :

    ```sh
    sudo chgrp -R www-data storage bootstrap/cache
    ```

    ```sh
    sudo chmod -R ug+rwx storage bootstrap/cache
    ```



    Source: https://stackoverflow.com/questions/30639174/file-permissions-for-laravel-5-and-others
  2. muhozi created this gist Apr 26, 2018.
    33 changes: 33 additions & 0 deletions Larave-permission.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    There are basically two ways to setup your ownership and permissions. Either you give yourself ownership or you make the webserver the owner of all files.

    Webserver as owner (the way most people do it):

    assuming www-data is your webserver user.

    sudo chown -R www-data:www-data /path/to/your/laravel/root/directory
    if you do that, the webserver owns all the files, and is also the group, and you will have some problems uploading files or working with files via FTP, because your FTP client will be logged in as you, not your webserver, so add your user to the webserver user group:

    `sudo usermod -a -G www-data ubuntu`
    Of course, this assumes your webserver is running as www-data (the Homestead default), and your user is ubuntu (it's vagrant if you are using Homestead).

    Then you set all your directories to 755 and your files to 644... SET file permissions

    sudo find /path/to/your/laravel/root/directory -type f -exec chmod 644 {} \;
    SET directory permissions

    sudo find /path/to/your/laravel/root/directory -type d -exec chmod 755 {} \;
    Your user as owner

    I prefer to own all the directories and files (it makes working with everything much easier), so I do:

    sudo chown -R my-user:www-data /path/to/your/laravel/root/directory
    Then I give both myself and the webserver permissions:

    sudo find /path/to/your/laravel/root/directory -type f -exec chmod 664 {} \;
    sudo find /path/to/your/laravel/root/directory -type d -exec chmod 775 {} \;
    Then give the webserver the rights to read and write to storage and cache

    Whichever way you set it up, then you need to give read and write permissions to the webserver for storage, cache and any other directories the webserver needs to upload or write too (depending on your situation), so run the commands from bashy above :

    sudo chgrp -R www-data storage bootstrap/cache
    sudo chmod -R ug+rwx storage bootstrap/cache