Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kaushal's avatar

what is the use of APP_ENV=local and APP_DEBUG=true in .env file

How it is diffrentiate in local and live??

0 likes
3 replies
MichalOravec's avatar

In development use this settings

APP_ENV=local

APP_DEBUG=true

In production use this settings

APP_ENV=production

APP_DEBUG=false

When you make your application you want to see all errors, but in production it's not good behaviour. So you don't want to show it to all users, instead of user can see error 500, and after you can fix it on localhost.

6 likes
javleds's avatar

As @michaloravec said, the APP_DEBUG flag is the difference between showing the application errors (full stack trace) and show a generic "user-friendly" error page.

The APP_ENV flag is not a boolean, this is because you can have many environments in your project, for example, production, development, staging, testing, etc. I am not sure if this flag is actually used in the core of laravel, but you can take advantage of it and use it if you want to "change" the behavior of the app while you are in a specific environment. For example if you are working with PayPal, you don't want to charge real money while you are building the application, then you can use the flag in order to switch between your sandbox and production credentials:

class PayPalCheckout 
{
  
  /** @var string */
  private $url;
  
  /** @var string */
  private $apiKey;
  
  /** @var string */
  private $secret;

  public function __construct()
  {
    if (config('app.env') === 'production') {
      // Initialize the attributes for production
    } else {
      // Initialize the attributes for sandbox
    }
  }

}
2 likes

Please or to participate in this conversation.