klytron / php-deployment-kit
A comprehensive deployment library for PHP applications built on Deployer. Supports Laravel, Yii2, and simple PHP applications.
Fund package maintenance!
www.klytron.com/buy-me-a-coffee
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/klytron/php-deployment-kit
Requires
- php: ^8.1
- deployer/deployer: ^7.0
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^10.0
README
A comprehensive deployment library for PHP applications built on Deployer. Supports Laravel, Yii2, API projects, and simple PHP applications with zero boilerplate.
Features
- π Multi-Framework β Laravel, Yii2, API, and simple PHP deployment recipes
- β‘ Zero-Config Defaults β Smart detection with easy customisation
- π Production Safe β Multiple confirmation prompts, validation, and rollback
- π Laravel Env Encryption β Automatic
LARAVEL_ENV_ENCRYPTION_KEYdecryption before deploy - πΊοΈ Asset Mapping β Maps Vite/Mix assets for database URL compatibility
- πΌοΈ Image Optimisation β Compress images post-deploy
- ποΈ Sitemap Generation β Automatic sitemap creation and verification
- π€ Font Verification β Checks webfonts are accessible after deploy
- π Deployment Timing β Built-in timer and metrics
- ποΈ Interactive or Unattended β Prompted workflow or fully automated via
auto_*flags
Requirements
- PHP 8.1+
- Deployer 7.x (installed automatically as a dependency)
- Git
- SSH access to your deployment server
Installation
Install via Composer:
composer require klytron/php-deployment-kit --dev
Verify the installation:
vendor/bin/dep --version
Optional: Scaffold a deploy.php automatically
# Auto-detect your project type (Laravel / Yii2 / simple PHP) and create deploy.php curl -sSL https://raw.githubusercontent.com/klytron/php-deployment-kit/main/install.sh | bash
Quick Start
1. Create deploy.php in your project root
<?php namespace Deployer; // Core kit require __DIR__ . '/vendor/klytron/php-deployment-kit/deployment-kit.php'; // Laravel recipe (omit for simple PHP or use klytron-php-recipe.php) require __DIR__ . '/vendor/klytron/php-deployment-kit/recipes/klytron-laravel-recipe.php'; // ββ Configure ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ klytron_configure_app('my-app', 'git@github.com:your-username/my-app.git'); klytron_set_paths('/var/www', '/var/www/${APP_URL_DOMAIN}/public_html'); klytron_set_domain('yourdomain.com'); klytron_set_php_version('php8.3'); klytron_configure_project([ 'type' => 'laravel', 'database' => 'mysql', // mysql | mariadb | postgresql | sqlite | none 'supports_vite' => true, 'supports_storage_link' => true, ]); klytron_configure_host('yourdomain.com', [ 'remote_user' => 'deploy', 'branch' => 'main', 'http_user' => 'www-data', 'http_group' => 'www-data', ]); klytron_configure_shared_files(['.env']); klytron_configure_shared_dirs(['storage', 'bootstrap/cache']); klytron_configure_writable_dirs([ 'bootstrap/cache', 'storage', 'storage/logs', 'storage/framework/cache', 'storage/framework/sessions', 'storage/framework/views', ]); // ββ Deployment Flow βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ task('deploy', [ 'klytron:deploy:start_timer', 'klytron:laravel:deploy:display:info', 'klytron:laravel:deploy:configure:interactive', 'deploy:unlock', 'deploy:setup', 'deploy:lock', 'deploy:release', 'deploy:update_code', 'deploy:shared', 'klytron:laravel:deploy:environment:complete', 'deploy:env', 'deploy:vendors', 'klytron:laravel:node:vite:build', 'klytron:laravel:deploy:database:complete', 'deploy:writable', 'klytron:laravel:deploy:cache:complete', 'deploy:symlink', 'klytron:laravel:deploy:finalize:complete', 'klytron:assets:map', 'klytron:assets:cleanup', 'klytron:sitemap:generate', 'klytron:fonts:verify', 'klytron:images:optimize', 'deploy:unlock', 'deploy:cleanup', 'klytron:laravel:deploy:notify:complete', 'klytron:deploy:end_timer', ])->desc('Deploy Laravel application');
2. Deploy
vendor/bin/dep deploy
Documentation
| Guide | Description |
|---|---|
| Installation | Prerequisites, install methods, server setup |
| Quick Start | Step-by-step first deployment |
| Configuration Reference | All klytron_* functions and options |
| Function Reference | API reference |
| Task Reference | All available deployment tasks |
| Laravel Guide | Laravel-specific configuration |
| Yii2 Guide | Yii2-specific configuration |
| Simple PHP Guide | Non-framework PHP projects |
| Dynamic Configuration | Path templates and placeholders |
| Troubleshooting | Common issues and fixes |
Project Structure
php-deployment-kit/
βββ deployment-kit.php # Main entry point β include this in deploy.php
βββ deployment-kit-core.php # Core helper functions
βββ klytron-tasks.php # Framework-agnostic deployment tasks
βββ recipes/
β βββ klytron-laravel-recipe.php # Laravel deployment tasks
β βββ klytron-yii2-recipe.php # Yii2 deployment tasks
β βββ klytron-php-recipe.php # Simple PHP tasks
β βββ klytron-server-recipe.php # Server provisioning tasks
βββ src/
β βββ Commands/ # Laravel Artisan commands
β βββ Exceptions/ # Custom exception classes
β βββ Services/ # Metrics, retry, validation services
β βββ Tasks/ # Task classes (AssetMappingTask, SitemapTask, etc.)
β βββ Validators/ # Configuration validators
β βββ Providers/ # Laravel service provider
βββ templates/ # Starter deploy.php templates
βββ examples/ # Real-world deployment examples
βββ docs/ # Full documentation
Supported Frameworks
| Framework | Recipe |
|---|---|
| Laravel | recipes/klytron-laravel-recipe.php |
| Yii2 | recipes/klytron-yii2-recipe.php |
| API (Laravel) | recipes/klytron-laravel-recipe.php |
| Simple PHP | recipes/klytron-php-recipe.php |
Contributing
Contributions are welcome! Please read CONTRIBUTING.md first.
Security
If you discover a security vulnerability, please see SECURITY.md for how to report it responsibly.
License
MIT β see LICENSE.