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

pveltrop's avatar

Laravel caching and retrieving wrong value from env

I've just changed my APP_ENV to local (from production) in my .env file, and no matter what I try, Laravel keeps saying my application is in production. I've ran config:clear, cache:clear, optimize:clear, even removed my cache folder, nothing works.

Even when I comment everything in my .env file, when I run php artisan tinker, then env('APP_ENV'), the output is production. So somehow, Laravel is reading this from another place even after clearing all cache?

If I uncomment everything again and try to read any other env variable, such as DB_HOST, APP_NAME, then I get the correct values in tinker.

When I run config:cache, env gets set to production aswell in bootstrap/cache/config.php, instead of local.

0 likes
5 replies
Snapey's avatar

if you are using php-fpm, it should be restarted

pveltrop's avatar

@Snapey I've restarted my docker container, also removed its volume then restarted, doesnt work unfortunately. My cache folder is also empty in my project.

pveltrop's avatar

@Snapey Yes I try dumping this in tinker and a simple testroute, same result. Whats even weirder is that all my other env variables get read correctly in tinker, it's just APP_ENV which won't update.

pveltrop's avatar
pveltrop
OP
Best Answer
Level 1

Found the issue. Since I'm using docker-compose, I conditionally install xdebug depending on the APP_ENV value when building my php container. So I pass my APP_ENV to my php dockerfile as an argument:

ARG APP_ENV
ENV APP_ENV=$APP_ENV

...

RUN if [ $APP_ENV = "local" ] ; then \
    # Xdebug
    pecl install xdebug-3.0.2  \
    && docker-php-ext-enable xdebug  \
fi

After removing ENV APP_ENV=$APP_ENV from my Dockerfile, I was able to fix this issue. Just having ARG APP_ENV in my Dockerfile was enough to pass my env value to docker.

Please or to participate in this conversation.