Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kitman's avatar

.ENV DEPLOYMENT FOR PRODUCTION SERVER

hI,

I want to ask how do people deploy there .env files on production server

  1. using ci/cd tool to cpy .env.example .env
  2. devops login the server and manual copy and rename form .env.example to .env
  3. Others ways

If using the 1 way it will have security issues because we are uploading to DB password and stuff to git, how to solve that problem.

If using the 2 way does that mean as a programmer everytime I create add/change a new variable(eg: third party api link) I have to tell the devops to add one on the production server, and also if I have multiple servers then I have to manual do it couple times which does not make much sense plus if the programmer forgot to tell the devops about it will create a problem as well ?

0 likes
3 replies
rameezisrar's avatar

@kitman, of course, you don't add .env to git. You will create a .env file with cmd command and then will paste the code from your local .env and then update it according to the production settings.

kitman's avatar

@rameezisrar, But then the problem is if I using AWS I have a load balance it will auto scales up and down the servers according to the traffic, It won't be possible for a devops to wake up 3am and to set the env manually in new production server that AWS just create

mac03733's avatar

so far iv just been using git hooks to push to production, this way i only setup th .env manually once .. then for all future changes i make it uses the same .env

  • cant you have a script that copies the .env file everytime the new server is created

Please or to participate in this conversation.