Environment Variables

Using the app:install Artisan command you can install the dotenv component:

php <your-app-name> app:install dotenv

The dotenv component allows you to load environment variables from a .env file. And behind the scenes, it's based on the DotEnv PHP package.

After installing the component, an empty .env.example will be create on the root of your project, and you should rename it manually to .env.

Assuming that your .env contains:


You can access those variables using the env() helper:

echo env('SECRET_KEY') // outputs 234567