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

r10maro90's avatar

How to set file path in .env?

I got a json file from a Google API service account thats in the root folder. The environment variable was set with full path to the file like so:

GOOGLE_APPLICATION_CREDENTIALS="C:/Users/marod/Desktop/text2speech/tapp/credentials.json"

It worked fine for now. But I know when I push to production it won't find the file.

So I tried doing it like:

GOOGLE_APPLICATION_CREDENTIALS="/tapp/credentials.json"

but it just gives error message:

"Google\ApiCore\ValidationException Could not construct ApplicationDefaultCredentials"

Is their better way to reference this file so that it always locates the json file even in production?

Any help would be appreciated.

0 likes
6 replies
tykus's avatar
tykus
Best Answer
Level 104

Are you expecting the same .env configuration to work in production as in development - if yes, then you're missing the point of DotEnv; they should not be shared. Just set the correct and appropriate environment variables in production on the production server; and do not include them in your version control system.

r10maro90's avatar

Okay, so when it’s pushed to production, lust link to the file path of the json file in .env? Sorry I’m still a beginner.

tykus's avatar

Correct.

Ideally, your .env should not be included in git (or whatever VCS you may use). It means that there are potentially sensitive credentials stored somewhere other than on the production server itself.

r10maro90's avatar

Oh I see. So in production this format:

GOOGLE_APPLICATION_CREDENTIALS="/tapp/credentials.json"

Should work then?

tykus's avatar

Providing you have the credentials.json file at that absolute path, yes.

Please or to participate in this conversation.