By default, the Laravel installation comes with the .env.example file, which has the default value APP_URL=. I see a lot of people forget to replace it with the actual URL of your app, why is this important?

To be precise, this value is actually used in config/app.phplike that:


'url' => env('APP_URL', '

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

The funny thing is that your app will still work even if you don’t change this URL. The problem will appear when using certain functions that call config(‘app.url’) or directly env(‘APP_URL’).

Inside Laravel itself you can find these:

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

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


But it’s not just that. A lot of external packages rely on APP_URL setting. For example, the very popular Spatie media library for file uploads (which we use in our QuickAdminPanel), uses APP_URL configured to form the URLs of the actual files to be returned.

For example, if you call this:


$user->getFirstMediaUrl('main_photo');

It will use APP_URL to form the final URL. And if you leave it to instead of the 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 installing the project – on your local computer and on all servers – in staging or live.

Learn more about setting up Laravel in the official documentation.



Technology

Another Tech Information

Similar Posts