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

richbreton's avatar

L5 .env contains app key but .env is in .gitignore how do I use the same key on different machines?

I just noticed that in my commit my .env was not committed and since my application key is in .env so im not sure how I can deploy to another machine. Im sure it was added to .gitignore for a good reason so im not going to remove it.

Also im having trouble understanding how to use different environments for production in laravel 5 now can someone help?

0 likes
6 replies
JeroenVanOort's avatar

The application key is not meant to be shared. In an ideal world, no developer should ever see the production environment's key. Simply make a file and place it in every environment, without including it version control.

sitesense's avatar

Yup .env is ignored because it contains sensitive information about your app such as database password etc.

You should deploy/distribute the .env file manually.

If you feel the information is safe to share for your particular application, then go ahead and remove the entry from .gitignore, or provide an example .env.example that can be easily renamed.

michaeldyrynda's avatar

The .env file is a workaround intended primarily for use only in development (when changing actual environment variables can be tedious.

In a production environment, you would set these variables within your Apache or nginx configuration using the relevant directives, using the .env file as a last resort only if you can't do the proper way (and if you can't, find better hosting).

Furthermore, the .env file will usually be environment-specific (i.e. Database credentials should be different in prod compres to dev) and this kind of information should never be committed to version control, lest it winds up being farmed for malicious activity.

richbreton's avatar

ah ok so on forge I should just enter this info into the environment vars section then?

bashy's avatar
bashy
Best Answer
Level 65

Yes, that's what they're there for :)

Snapey's avatar

Am I correct in saying that there should be no need to share the key? Its only used for things like session encryption and csrf tokens? Hashed passwords etc don't use it so you won't break anything with a new key?

Please or to participate in this conversation.