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

richard@gorbutt.com's avatar

Forge Server - App decided .env would not get read..

So I had a weird one. I have a one week old DO droplet with a copy of my app on. Although PROD, it's not released. Well, over the weekend, it just fell over. Whoops errors all around.

After a few red herrings I realized that any env('ANY_SETTING') would always return null. Didn't matter what it was, all return NULL. Would not connect to mysql and so on and so forth. Nothing was changed that I did. No new code was sent to the server, no changes to nginx or anything.

I tried php artisan config:clear, config:cache, clear-compiled and all that. Trawled the log files looking for permissions errors, nginx access errors and zippo. Nada. Nothing.

Even in artisan tinker, all env('xx') commands return null.

Finally I just copied the .env contents to a clipboard, blew away the site and re-installed. Pasted back the .env and all is well with the world.

Anyone else seen this? Droplet a week old and PHP 7.2, MariaDB 10.2.11.

Looking through Laracasts, a few have seen this but all seemed to be cured with a config:clear etc.

I appear to be ok now and I'll probably add an .env check in the scheduler but weird.

0 likes
6 replies
Cronix's avatar

I don't use DO, but from what I know they've restarted their servers recently (last week or so) in order to apply security patches for the Meltdown and Spectre security flaws in intel chips. Not sure if that has anything to do with it but thought I'd mention it as a possibility. You should have received an email from them saying when your droplet would be rebooted.

richard@gorbutt.com's avatar

Thanks @Cronix, I've had those emails for my Linode ones & not DO. However as it's a new DO droplet, I just ran uname -r and it appears to be a patched kernel so it may be new droplets are already taken care of for round 1 of patching!

ejdelmonico's avatar

All 7 of my DO servers still have there .env files intact after the patch so I don't think it's you issue. Besides, it is only a few data centers that have had the patch. How did you add your .env? Copy the file over or enter the key/value through Forge control panel?

richard@gorbutt.com's avatar

I don't believe it is the patch as I believe when I span it up last week it was already applied.

The .env file was populated through the Forge control panel and everything worked for a few days. Then "something" happened and it seemed not to read. I poked around the server, nothing obvious in the logs, no access denied issues, just all env calls returned null. Ownership and permissions looked ok on .env.

After deciding I was spending too much time in the rabbit hole I blew it away.

Although this was a PROD build ready for release, I don't recall changing anything on the box so that is what makes me curious. If I did change something, however tiny, what stumps me is no sign of any errors in logs regarding the reading of the .env. Oh well, life's mystery.

ejdelmonico's avatar

@gorby I just found an old note that I made about your very problem although it's a bit late now. I was using php artisan config:cache and I had read about issues with fully flushing out the previous cache so I switched to php artisan config:clear after installing composer dependencies.

richard@gorbutt.com's avatar

@ejdelmonico Thanks. I found those things in my search and tried it a few times. Both commands etc. In the end I'm putting it down to one of those things. While I don't believe I changed anything, it's possible I did without thinking. However I would love to know what :-) I did. There were some security updates requiring a restart but I had that on all my Forge provisioned boxes and they rebooted fine.

Cosmic Ray shower is my excuse now I think!!!

Please or to participate in this conversation.