A Laravel package for managing multiple environment configurations (.env files) with an intuitive web interface. Easily switch between different environment profiles, create backups, and manage your application's configuration.
- π Multiple Environment Profiles: Create and manage multiple .env configurations
- π¨ Modern Web Interface: Vue 3 + Tailwind CSS interface with Monaco Editor
- π Dark/Light Mode: Built-in theme support with system preference detection
- πΎ Automatic Backups: Automatically backup .env files before changes
- π·οΈ Application Names: Optionally tag profiles with application names
- π Secure: Configurable middleware protection
- π¦ Easy Installation: Simple composer installation with publish commands
- π Laravel 10/11/12 Support: Compatible with latest Laravel versions
- π API Support: RESTful API endpoints for programmatic access
- PHP 8.2 or higher
- Laravel 10.0 or higher
- Install the package via Composer:
composer require laravel-ready/env-profile-manager
- Publish the package resources:
php artisan env-profile-manager:publish
Or publish specific resources:
# Publish config file
php artisan vendor:publish --tag=env-profile-manager-config
# Publish views (if you want to customize)
php artisan vendor:publish --tag=env-profile-manager-views
# Publish assets
php artisan vendor:publish --tag=env-profile-manager-assets
# Publish migrations
php artisan vendor:publish --tag=env-profile-manager-migrations
- Run the migrations:
php artisan migrate
- (Optional) Add CSRF token meta tag to your layout if not already present:
<meta name="csrf-token" content="{{ csrf_token() }}">
The configuration file is published to config/env-profile-manager.php
. Here are the available options:
return [
// Web route prefix
'route_prefix' => 'env-profile-manager',
// API route prefix
'api_prefix' => 'api/env-profile-manager',
// Middleware for web routes
'middleware' => ['web', 'auth'],
// Middleware for API routes
'api_middleware' => ['api', 'auth:sanctum'],
// Layout to extend for views
// Set to null to use the package's default layout
// Example: 'layouts.app' to use your application's layout
'layout' => 'env-profile-manager::layouts.default',
// Maximum number of .env backups to keep
'max_backups' => 10,
// Enable/disable features
'features' => [
'api' => true,
'web_ui' => true,
'backups' => true,
],
];
After installation, navigate to /env-profile-manager
(or your configured route prefix) to access the web interface.
Features available in the web interface:
- View and edit current .env configuration
- Create new profiles from current configuration
- Load saved profiles
- Activate profiles (overwrites current .env)
- Delete profiles
- Real-time syntax highlighting with Monaco Editor
If API is enabled in configuration, the following endpoints are available:
GET /api/env-profile-manager
- List all profiles and current .env contentPOST /api/env-profile-manager
- Create a new profileGET /api/env-profile-manager/{id}
- Get a specific profilePUT /api/env-profile-manager/{id}
- Update a profileDELETE /api/env-profile-manager/{id}
- Delete a profilePOST /api/env-profile-manager/{id}/activate
- Activate a profileGET /api/env-profile-manager/current-env
- Get current .env contentPUT /api/env-profile-manager/current-env
- Update current .env content
You can also use the package programmatically:
use LaravelReady\EnvProfiles\Models\EnvProfile;
use LaravelReady\EnvProfiles\Services\EnvFileService;
// Create a new profile
$profile = EnvProfile::create([
'name' => 'Production',
'app_name' => 'My Laravel App',
'content' => file_get_contents(base_path('.env.production')),
]);
// Activate a profile
$profile->activate();
// Use the EnvFileService
$envService = app(EnvFileService::class);
$currentEnv = $envService->read();
$envService->write($newContent);
-
Protect Routes: The package uses middleware configuration to protect routes. Make sure to configure appropriate middleware.
-
Sensitive Data: Be careful when storing sensitive data in profiles. Consider encrypting sensitive values.
-
Backups: The package automatically creates backups before modifying .env files. Configure
max_backups
to control disk usage.
To customize the views, publish them and edit as needed:
php artisan vendor:publish --tag=env-profile-manager-views
Views will be published to resources/views/vendor/env-profile-manager/
.
By default, the package uses its own layout (env-profile-manager::layouts.default
). You can use your application's layout by changing the configuration:
'layout' => 'layouts.app',
Or set it to null
to use the package's default layout:
'layout' => null,
If using a custom layout, make sure it has a @yield('content')
section and includes the necessary @stack('styles')
and @stack('scripts')
directives.
Make sure your layout includes the style and script stacks:
@stack('styles')
@stack('scripts')
Ensure your layout includes the CSRF token meta tag:
<meta name="csrf-token" content="{{ csrf_token() }}">
Check that the web server has write permissions for:
- The
.env
file - The Laravel base directory (for creating backups)
Contributions are welcome! Please feel free to submit a Pull Request.
This package is open-sourced software licensed under the MIT license.