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

eokorie's avatar

Adding URLs to .env file

Hi all,

Is it possible to add urls to a .env file? In .env file, I have the following line:

API_URL=http://localhost/testsite/api.php

However, when I try to view the value of .env variable, it also comes back as null. So my question is, can we use url in the .env file?

Many thanks,

Emmanuel

0 likes
7 replies
joedawson's avatar

You should be fine using that URL. How are you trying to view the value? env('API_URL') should be returning the value.

eokorie's avatar

Hi Joe,

yeah, that is what I am attempting to do.. but it seems to come back as a null value everytime...

thomaskim's avatar
Level 41

If you cached your configurations, you will need to clear it and then re-cache it.

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

Looks like clearing the Config cache fixed the problem... thanks for the help guys :)

1 like
james917's avatar

It worked for me also. I am trying to referencing the url through the controller is that possible?

Please or to participate in this conversation.