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

r10maro90's avatar

How to set path to Google API credentials.json file 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
shamimbdpro's avatar

Hi, Did you found solution? if not the let me know i can help you to solve it.

faizi_856's avatar

@shamimbdpro Hey! I need help. I don't know how to set json file path in variable GOOGLE_APPLICATION_CREDENTIALS in .env laravel file.

faizi_856's avatar

@shamimbdpro While mentioning json file path in .env file, I'm getting the following error: Google\ApiCore\ValidationException: Could not construct ApplicationDefaultCredentials

czs's avatar

@martinbean Can you post a link of how to set it up to use keys and secrets instead?

NorT's avatar

Try in your function before constructing the client putenv("GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json");

Please or to participate in this conversation.