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

noirtempest's avatar

Ably API Key is Missing

I'm using Laravel and React JS. In development, everything works fine, but in production, I keep getting an error saying the Ably API key is missing, even though it's present in the .env file in production. I've already checked and confirmed that it's there.

backend:

0 likes
5 replies
vincent15000's avatar

Have cached the configuration files in production ?

php artisan optimize
vincent15000's avatar

@noirtempest The problem is that you are using the env() helper whereas you have cached the configuration.

The env() helper doesn't work when the configuration is cached.

You should retrieve the ABLY_API_KEY in a configuration file and then use the config() helper to retrieve the value.

// in a configuration file (for example services.php)

'ably' => [
		'api_key' => env('ABLY_API_KEY'),
],

And then in your controller.

config('services.ably.api_key');
1 like
JussiMannisto's avatar
Level 50

You are using the env() helper outside the config files. That's a no-no and the reason why the value doesn't work when config is cached.

https://laravel.com/docs/11.x/helpers#method-env

Add a config entry and use that instead, e.g. config('app.ably-api-key'). Then rebuild to config cache by running php artisan config:cache or php artisan optimize.

2 likes

Please or to participate in this conversation.