env() returns null (config cached) Laravel Origin: Application & API OSI layer 7 · Application Last updated 4 Nov 2026

Laravel: .env changes ignored / env('X') returns null after php artisan config:cache

After config:cache, Laravel no longer reads .env, so env() calls outside config files return null and edits to .env have no effect.

Exact message you may see env() returns null after config:cacheLaravel .env changes not working.env not being read Laravel config cachedenv('APP_DEBUG') returns nullLaravel changes to .env file not taking effect
Seen on: Laravel PHP

Meaning

When config is cached, .env isn't loaded; only values compiled into config/*.php exist. Use config('app.x') in app code and call env() only inside config files. After changing .env run php artisan config:clear (or config:cache again).

Common causes

  • env() used in controllers/models instead of config()
  • .env edited but config cache not rebuilt
  • Different .env on the server
  • Cache stored from another environment
  • config/*.php missing the key

⚡ Quick fix

  1. Read values via config('services.key') and define them in config files
  2. php artisan config:clear after editing .env
  3. Rebuild caches on deploy: php artisan config:cache

Detailed fix by platform

Laravel

  1. php artisan optimize:clear clears config, route, view and event caches

How to diagnose

  1. Cached — bootstrap/cache/config.php exists?
  2. Usage — env() outside config?
  3. Deploy — Cache step?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

503 Service Unavailable (maintenance mode stuck) — Laravel: Be right back. / 503 Service Unavailable after php artisan down (Laravel)503 Service Unavailab…Attempt to read property "x" on null — Laravel/PHP 8: ErrorException: Attempt to read property "name" on null (Laravel)Attempt to read prope…Can't connect to Redis from another host (bind 127.0.0.1) — Redis: Could not connect to Redis at 10.0.0.5:6379: Connection timed out (Redis)Can't connect to Redi…Command "x" is not defined — Laravel: Symfony\Component\Console\Exception\CommandNotFoundException: Command "make:livewire" is not defined. Did you mean one of these? (Laravel)Command "x" is not de…ERR CONFIG SET failed (possibly related to argument) — Redis: (error) ERR CONFIG SET failed (possibly related to argument 'maxmemory') - can't set immutable config (Redis)ERR CONFIG SET failed…ERR This instance has cluster support disabled — Redis: (error) ERR This instance has cluster support disabled (Redis)ERR This instance has…Laravel: Allowed memory size exhausted (request) — Laravel/PHP: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in vendor/laravel/framework (Laravel)Laravel: Allowed memo…Laravel: Connection could not be established with host — Laravel: Symfony\Component\Mailer\Exception\TransportException: Connection could not be established with host "smtp.mailtrap.io:2525": stream_socket_client(): Unable to connect (Email / SMTP)Laravel: Connection c…env() ret…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.