Search code examples
phpdatabaselaravelfile-permissionsconfiguration-files

How to set Permissions to write into a .env.local.php file


I am writing a setup/quickstart page for my laravel application that allows the user to setup their DB connections. I would like to allow PHP to write a .env.local.php file onto the server, but I'm not sure where to put it, and how to get the permissions to be able to write this file. I would like to avoid setting the entire application to 777 as that probably isn't a good idea, but I'm not sure what I should set it to. Also, what should I set it to after the .env.local.php file has been written?


Solution

  • Usually you need the webserver to have write access to that file, so you can change the group to the one your webserver belongs to:

    chown yourusername:www-data .env.local.php
    

    And make it writable for user and group:

    chmod 660 .env.local.php