Encrypting Laravel (9.x) .env file

What is Laravel .env ?

In Laravel, the .env file is a configuration file that holds various environment-specific configuration settings for your application. It's a plaintext file where you can define key-value pairs, with each pair representing a configuration variable and its corresponding value.

We can access .env values in your Laravel application using this env() function.
Let’s think if you need to access the app name.

env(“APP_NAME”)

This .env file should be kept secure, and the file should not be shared publicly. Additionally, Laravel provides the php artisan key:generate command to generate a secure application key that is used for encryption purposes.

Encrypting Environment File

This feature supported since laravel 9.x
php artisan env:encrypt

That artisan command will encrypt the values in your .env file and generate a new one .env.enc file.

Decrypting Environment File

php artisan env:decrypt

This will decrypt the .env.enc file and output it to the console

if you wish to learn more(reference)...

https://laravel.com/docs/9.x/configuration#encrypting-environment-files

0
Subscribe to my newsletter

Read articles from Code With Shashika directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Code With Shashika
Code With Shashika

I am a Senior Web Developer | Software Engineer (Laravel, WordPress) who is experienced for more than 4 years.