samasend/laravel-key-rotate

Rotate your Laravel application key with ease

v1.0.0 2024-03-30 23:52 UTC

This package is auto-updated.

Last update: 2024-10-31 00:29:02 UTC


README

Github Actions Total Downloads Latest Stable Version License

Laravel Key Rotate is a package that extends Laravel's built-in key:generate command, providing a simple and efficient way to rotate your Laravel application's key.

This is particularly useful for maintaining the security and integrity of your application by ensuring that the encryption key is regularly updated.

Prerequisites

  • PHP >= 8.2
  • Laravel >= 11.x

Installation

You can install the package via composer:

composer require samasend/laravel-key-rotate

Usage

To rotate your application key, simply run the following artisan command:

php artisan key:rotate

This command will generate a new application key and update your .env file. The previous key will be stored in the APP_PREVIOUS_KEYS environment variable, allowing for graceful key rotation.

How It Works

The key:rotate command extends Laravel's built-in key:generate command. When run, it generates a new application key as usual. However, instead of simply replacing the old key, it stores the old key in the APP_PREVIOUS_KEYS environment variable. This allows for a smooth transition to the new key, as the old key is still available for decrypting any data that was encrypted with it.

Ideally, this feature should have been implemented in Laravel core, but it's not. So, this package is here to help you.

License

This package is open-sourced software licensed under the MIT license.