Why it’s important to change APP_URL in Laravel .env file
Founder of QuickAdminPanel
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:
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.
- Laravel: How to Add Background Color to Datatables Columns
- 3 Ways to Delete User in Laravel: Block, Hide or Hard-Delete?
- Laravel /public Folder: How to Configure Domains for in Apache/Nginx
- Laravel User Notifications: Send Immediately or Daily Digest
- Demo: Transactions Datatables with Date Range Filter and Chart on Top
Try our QuickAdminPanel Generator!
How it works:
1. Generate panel online
No coding required, you just choose menu items.
2. Download code & install locally
Install with simple "composer install" and "php artisan migrate".
3. Customize anything!
We give all the code, so you can change anything after download.