Kritim Yantra
May 07, 2025
When managing Laravel applications, security and developer experience often collide—especially when handling sensitive configuration data. That's where Veil comes in: a powerful Laravel package that gives you precise control over .env
file encryption.
In this blog, you'll learn:
Veil is a Laravel package developed by Intermax Cloudsourcing. It enhances the built-in env:encrypt
and env:decrypt
Artisan commands by allowing you to encrypt only sensitive values in your .env
file instead of the entire file.
By default, Laravel's encryption turns your entire
.env
file into a single block of ciphertext. Veil changes that.
This makes it much easier for teams to collaborate, troubleshoot, and automate while still keeping secrets secure.
Laravel’s php artisan env:encrypt
replaces your entire .env
file with one long encrypted string. That’s secure, but it hides everything—including harmless variables like APP_ENV
or LOG_CHANNEL
.
Veil’s smarter approach encrypts only the values of keys that are truly sensitive (like DB_PASSWORD
, APP_KEY
, or API_SECRET
) while leaving the rest readable.
.env
filescomposer require intermax/veil:^2.3.0
No config files required—Veil works out of the box by extending Laravel’s Artisan commands.
php artisan env:encrypt --only-values
This encrypts only the values of variables like _KEY
, _SECRET
, _PASSWORD
, etc., based on default naming patterns.
php artisan env:decrypt --only-values
This command restores encrypted values to their original form while leaving other variables untouched.
Want to target specific keys?
php artisan env:encrypt --only-values --only="DB_PASSWORD,API_SECRET,APP_KEY"
Before encryption:
APP_ENV=production
APP_KEY=base64:abcdef1234567890
DB_PASSWORD=secret123
After Veil encryption:
APP_ENV=production
APP_KEY="base64:...encrypted..."
DB_PASSWORD="...encrypted..."
Store your encryption key (LARAVEL_ENV_ENCRYPTION_KEY
) in a secure place like HashiCorp Vault or AWS Secrets Manager.
Automate encryption in CI/CD pipelines with:
php artisan env:encrypt --only-values --force
Document encrypted keys and patterns in your README or build scripts.
Tool | Behavior | Config Overhead |
---|---|---|
Laravel Default | Encrypts entire .env file |
None |
Veil (intermax/veil) | Encrypts only sensitive values | Minimal |
laravel-encryptenv | Provides helper secEnv() and separate files |
Medium |
Veil hits the sweet spot for most Laravel teams—combining clarity, flexibility, and solid security.
Veil brings intelligent encryption to Laravel by focusing on what truly matters: protecting secrets without making your environment unreadable. If you're serious about security and want to keep your DX (developer experience) top-notch, Veil is a must-have in your Laravel toolkit.
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google