How to Debug Laravel Environment variables ?

A tool that can summarise all environment variables across multiple environments, and let developers know which files are using environment variables the wrong way.

Neha Soni , 28 November, 2020

why you need to debug environment variables ?

Before diving deep into the reading, to know the purpose of this article is very important for readers. Here are two stories which are enough to perceive why one should explore this appliance. Following are-

Story 1-
We had built an application which was using an email service with different credentials at staging and production environments. At the time of deployment we found that at one of those environments, email was not working due to credentials mismatch. We used env(variable_name) to get the credentials values, but it didn’t work. Later, we found that this function only works in a development environment, it doesn’t work in a production environment due to config cache. What an ugly bug, wasn’t it?
Story 2-
We had almost three environment files in one of our Laravel applications and after deployment at production we came to find that the queue started to fail. At that time we needed to compare the environments’ variables at one place. Later, we found that env files were using different APP_NAME we didn't know that some variables like APP_NAME should be the same in all ENV files, and the APP_NAME was used in the namespacing queue. Tremendous!
Both stories revolve around the environment variables’ status supervised by us.
From there, a thought emerged that-

  1. What about a tool that can bring a small, crystal clear, or well-managed picture of all our environment variables situated in multiple environments, instead of comparing those manually?
  2. What if developers come to know which files are using any of the environment variables?
Let’s have a look at our thought’s real picture, a small development.


Env checker is a small size Laravel appliance which is invoked by just an artisan command to bring all environments’ variables’ status in a single frame.

How does it work?

We are assuming that you already have configured your env files. Below is the guideline to follow in order to make this tool work-
  1. Install this in your Laravel application via the following command-
    composer require readybytes/env-checker
  2. Open the terminal, and run the following command-
    php artisan env:check
You should see the output like this-
Let’s understand some abbreviations of output-
  1. “N/A” - This represents that the respected variable is not found in the respected file.
  2. “-” - This represents that the variable is declared but no value is assigned to it.
  3. “Null” - This is self-explanatory.
  4. “Files which are using env variables” - This is indicating the path of those files (exclude config folder’s files) which are having any of the environment variables with the line number and variable name.
Tip - If you have run this command in any of your code editors, you can click on any of the files which are having environment variables, and the file will be open with output :-D

Last but not least-

Try this package to manage your environmental variables. Feel free to give suggestions and ideas to improve it in the comment section.
Thanks for reading.

Explore this package in your application by using the above guidelines. Try now by clicking on below button.

Try Now
blog comments powered by Disqus