Keep the .env file in production server on git deploy

70 Views Asked by At

In my Git repository, for security reasons, I do not have the .env file; however, in the production environment, this file already exists at the root and is configured (and it's not versioned). My goal is that when I deploy to Cloudways, this production file is retained, and I don't have to reconfigure it again with each deployment.

However, when I perform the pull via Cloudways, this production file gets deleted. How can I prevent Git from deleting it?

1

There are 1 best solutions below

0
Vijay Raghavan Aravamudhan On

In such cases, I prefer to keep the "to be retained" files in a different folder - and as part of your deployment process, you can create symbolic links once the code has been deployed into appropriate folders. For eg (concept-wise), this is how capistrano manages different releases.

<app installation folder>
 |
 |- release1 # date + time-stamped folder names
 |- release2
 |- .
 |- .
 |- .
 |- current # symbolic link to the appropriate release folder
     |- configFile # symlink from ../shared/<file>
 |- shared # folder where the common files can live irrespective of which is the current release

In the above example, your file (that should not change across releases) can go into the shared folder.