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

COACHTHEM's avatar

Not able to access custom env() values after executing php artisan config:cache

In laravel 5.5 app I have created custom config variables in my config/app.php for example

return [
    'PROFILE_CDN_URL' => env('CDN_URL').'uploads/profileimages/'
];

and then I am able to access the value by calling config('app.PROFILE_CDN_URL') but when in production after executing php artisan config:cache the value is printed as null.

Can anyone help please. Thanks in advance.

0 likes
6 replies
rin4ik's avatar

try this

php artisan cache:clear
php artisan config:clear
1 like
COACHTHEM's avatar

Hey actually after executing php artisan config:cache my calls to env() method does not work.. for e.genv('APP_NAME') call return null value.

36864's avatar
36864
Best Answer
Level 13

Do not use the env helper outside configuration files.

The whole point of caching your configuration is to not have to fetch environment variables and such. Their values will be cached.

As for why your config setting is null, we'll need some more information.

Post the actual file you created and its filename, along with the exact line where you're trying to retrieve a value from that file.

1 like
COACHTHEM's avatar

@36864 I am able to access the config values after after caching.. Just because I executed config:cache command I thought config values are not accessed. It is actually the env() values that are not accessible after caching config.

So in this case I will have to access all .env values in config file and from config I can access it anywhere in the project.

36864's avatar

@COACHTHEM That is correct. If you look at the framework, this is what's being done all around. Your config/app.php file, for example, fetches the APP_NAME environment variable and saves its value in a handy PHP array that is accessible anywhere through the config helper.

1 like

Please or to participate in this conversation.