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

greevesh's avatar

ENV variables remain the same after clearing cache

I've been doing some email testing with mailtrap. I've now decided to change my .env credentials to those from my mailgun account. I've also changed my app name.

Yet after doing so and clearing my cache using php artisan config:clear and php artisan cache:clear. My email is still being sent on mailtrap with my old app name. Even though I changed the credentials from mailtrap to mailgun.

I thought this would be all I have to do for my changes to take place. What else do I have to do?

Thanks

0 likes
12 replies
Snapey's avatar

This should be it, but a handy tip to know is using tinker to check config

open tinker and type

>>> config('app.name')

You will see exactly what the Laravel app thinks is the name, taking into account any cached config

1 like
claudsonm's avatar

First for my experience, the artisan commands can trick you a bit. If you are using the file system as the cache driver, make sure you have permissions to delete the files within the storage/framework/cache folders.

For example: running php artisan cache:clear on terminal looks good but no real effect is noticed. When entering tinker and running Cache::clear() all the unix permission issues are visible, it just happens the command line was suppressing them.

Second, the app name was changed. When using Redis as the cache mechanism the app name is part of the key stored in the cache. Although it's a brand new one and things should be pointed to the new key-value pairs, I would clear the Redis database just in case.

1 like
greevesh's avatar

@snapey

Thanks for the tip. I'll definitely be using that. However, when I run that command in tinker it shows my new app name. Yet, when using ```{{ config('app.name') }} in my email template, it sends me the email with the old app name. This doesn't make sense to me. How about you?

greevesh's avatar

@claudsonm

I've ran Cache::clear() in tinker and it returns true. So it's definitely been cleared? I've never used Redis and I'm not sure how I would clear it anyway. Unless that's what Laravel uses by default?

Thanks for your help

greevesh's avatar

@snapey @claudsonm

So, I finally managed to get my new env credentials to display in my email template. Strangely, it was by running php artisan config:cache.

But when I clear my cache with php artisan config:clear my old credentials reappear. Isn't this the exact opposite to what's supposed to happen?!

Snapey's avatar

what do you have in config/mail.php? have you edited it at all?

claudsonm's avatar

It looks odd. But do notice that by running php artisan config:cache, the php artisan config:clear is also run under the hood. In fact, is the first thing that is executed. You can check for yourself at the file Illuminate/Foundation/Console/ConfigCacheCommand.php.

Happy that you figured out.

1 like
greevesh's avatar

Also when you run the command the config cleared message shows up first.

Thanks for your help!

greevesh's avatar

I'm getting the exact same problem now with Stripe. Config:clear will allow me to change my app.name but not my stripe.key. I'm checking in Tinker with config('stripe.key'). What's going on here??

Snapey's avatar

are you running in some form of VM such as homestead?

greevesh's avatar

No. I'm running it on localhost. I've tested it on a couple of different apps and the same thing happens. When you run config('db.connection') null is returned.

But when you run config('mail.host') your host is returned (in my case smtp.mailtrap.io).

I'm guessing that the value of some keys can't be accessed through tinker for security reasons?

Please or to participate in this conversation.