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

timmyc's avatar

env() not accessing .env on Forge deploy

I've recently run into a problem where I get the following error in Forge when I deploy:

Loading composer repositories with package information
Installing dependencies from lock file
Nothing to install or update
Generating autoload files
> php artisan clear-compiled
> php artisan optimize
Generating optimized class loader
Compiling common classes
PHP Fatal error:  Uncaught Exception: Bugsnag Error: Invalid API key ...

etc.

I discovered that the issue comes into play when the deployment attempts to use the env() function. For example, this "Bugsnag" error is actually occurring because my Bugsnag API key sits in my .env file, accessed by env() inside my Bugsnag config file. If I hard-code the key, all is well, but it moves to the next error (e.g., can't connect to DB because it doesn't pick up user/password from .env file).

I thought potentially a permissions issue, but all looks normal. Here are the results of "ls -l .env":

-rw-r--r-- 1 forge forge 2824 May  2 12:16 .env

Any ideas why this might be happening?

0 likes
0 replies

Please or to participate in this conversation.