PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Encrypting environment variables in Laravel

Encrypting environment variables in Laravel

Starting from Laravel 9 version, there's a cool feature everyone could find useful: encrypting your .env file. No more environment variables on your server, you can just commit your environment files and leave your automations deploy the decrypted file, providing the encription key. Starting from the beginning, you can encrypt your .env file using this artisan command:

$ php artisan env:encrypt

this commmand will create a new .env.encrypted file, and will print the cipher and key in the console. If you don't specify a key and cipher parameter, Laravel will use your environment LARAVEL_ENV_ENCRYPTION_KEY and LARAVEL_ENV_ENCRYPTION_CIPHER parameters.

Encrypt using custom key and cipher

You can override the encryption key and cipher by passing the --key and --cipher options to the command. You can use one of the ciphers supported by the Laravel Encrypter.

$ php artisan env:encrypt --key=securekey --cipher=AES-256-CBC

Encrypt an enviroment specific file

You can also encrypt the environment file for a specific environment. For example, if you want to encrypt the .env file for the production environment, you can do so by passing the --env option to the command.

$ php artisan env:encrypt --env=production

Decrypting environment files

Using your cipher and encryption key, you can print another .env file with the decrypted variables, using the command:

$ php artisan env:decrypt --key=base64:fl6T1hQRtyu= --force

or, if you want to decrypt a specific file:

$ php artisan env:decrypt --key=h786BJPUmY&693 --env=production

using custom key and cipher You can override the encryption key and cipher by passing the --key and --cipher options to the command. You can use one of the ciphers supported by the Laravel Encrypter.

$ php artisan env:encrypt --key=securekey --cipher=AES-256-CBC

Encrypt an enviroment specific file

You can also encrypt the environment file for a specific environment. For example, if you want to encrypt the .env file for the production environment, you can do so by passing the --env option to the command.

$ php artisan env:encrypt --env=production

Decrypting environment files

Using your cipher and encryption key, you can print another .env file with the decrypted variables, using the command:

$ php artisan env:decrypt --key=base64:fl6T1hQRtyu= --force

or, if you want to decrypt a specific file:

$ php artisan env:decrypt --key=fbre747HFEUbj --env=production

Comments (0)

loading comments