Laravel debugbar in production


In this article, we are going to show you how you can use a Laravel debugbar library in your production website. Debug Bar is used mainly for debugging environments but there can be situations where you might face an error in production. But debug bar displays all the queries and models of your Laravel application. So you do not want to show it to all of your live users. It should only be displayed to you, the owner of the website.

What we will do:

  1. Install Laravel
  2. Install Debug bar
  3. Enable for a specific user only

Video Tutorial:

Install Laravel

First, we are going to install a fresh Laravel project. You can use it in your existing project as well. Open the command prompt or terminal at the root of your Laravel project. Download Laravel from Github, you need to extract the files. Copy and paste all the files in your htdocs project folder, make sure to copy the hidden files as well.

Then create a copy of the .env.example file and rename it to just .env. Then move all the files from the public folder to the root folder. At this point you can delete the folder downloaded from GitHub, it is not needed anymore.


Now open the .env file and set the app debug to false and app environment to “production” because we will be going into production.


Then we will set up the MySQL configurations, we are not going to use MySQL but it is required to run the Laravel project.


You can enter as per your MySQL server details.


Then we need to open the index.php file and do the following changes in it:

// change
if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
    require __DIR__.'/../storage/framework/maintenance.php';
// to
if (file_exists(__DIR__.'/storage/framework/maintenance.php')) {
    require __DIR__.'/storage/framework/maintenance.php';

// change
require __DIR__.'/../vendor/autoload.php';
// to
require __DIR__.'/vendor/autoload.php';

// change
$app = require_once __DIR__.'/../bootstrap/app.php';
// to
$app = require_once __DIR__.'/bootstrap/app.php';

Then we need to run a command in our terminal to install the Laravel:

COMPOSER_MEMORY_LIMIT=-1 composer update

COMPOSER_MEMORY_LIMIT=-1 is prepended before the command because sometimes we may face an error that says “allocated memory exhausted”. The command will take a few minutes.

Once it is installed, you need to generate an application key which you can generate with the command:

php artisan key:generate

You can see your application key in the .env file.


Now open your project in the browser, and you will see that it has been installed perfectly and is running. Now we need to install debug bar in it.

Install Laravel Debugbar in production website

Download debug bar library (Github) by running the following command in your terminal:

COMPOSER_MEMORY_LIMIT=-1 composer require barryvdh/laravel-debugbar

This will take a few minutes but once installed, you can refresh your browser. The debug bar will not be displayed because the app is in production, so we have to manually display it. But we also want it to be displayed on all pages, throughout the application.

So we will go to the app > providers > AppServiceProvider.php and update it as per the following code:


namespace App\Providers;

use Illuminate\Support\ServiceProvider;

use Auth;

class AppServiceProvider extends ServiceProvider
     * Register any application services.
     * @return void
    public function register()

     * Bootstrap any application services.
     * @return void
    public function boot()
        if (Auth::check() && Auth::user()->email == "")

Make sure to add the backslash before it, otherwise, it will generate an error because Laravel works in namespaces. Enter your email address in the if condition. Now you will start seeing a debug bar in your production but only when you are logged in with the above-provided email address.


So that was all, if you face any problems in following this, kindly do let me know in the comments section below.

How useful was this post

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post

Leave a Reply