By default, Laravel installation comes with .env.example file, which has default value APP_URL=http://localhost. I see many people forget to change it to real URL of your app, why is it important?

To be precise, this value is actually used in config/app.php, like this:

'url' => env('APP_URL', 'http://localhost'),

So, you can call that value by config(‘app.url’).

Funny thing is that your application will still work even if you don’t change that URL. The problem will appear when using some functions that are calling config(‘app.url’) or directly env(‘APP_URL’).

Inside of Laravel itself, you can find these:

Laravel config app url

In short, your email notifications will point to the wrong URL, if you don’t set it properly.

Also, console commands won’t work properly, because console doesn’t really know what the URL is, as it’s not called from the browser.

But it’s not only that. A lot of external packages rely on APP_URL setting. For example, mega-popular Spatie Media Library for file uploads (which we use inside of our QuickAdminPanel), uses configured APP_URL to form the URLs of actual files to be returned.

For example, if you call this:


It will use APP_URL to form the final URL. And if you leave it at http://localhost instead of actual URL, you will probably get a broken file or 404 image on your website.

So, my advice is to always change APP_URL in your .env file immediately after project install – on your local computer, and all servers – staging or live.

Read more about Laravel configuration in the official documentation.