PHPackages                             iperamuna/laravel-self-deploy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. iperamuna/laravel-self-deploy

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

iperamuna/laravel-self-deploy
=============================

Simple self-deployment scripts and commands for Laravel applications.

v1.7.7(4mo ago)0100MITPHP

Since Feb 11Pushed 4mo agoCompare

[ Source](https://github.com/iperamuna/laravel-self-deploy)[ Packagist](https://packagist.org/packages/iperamuna/laravel-self-deploy)[ RSS](/packages/iperamuna-laravel-self-deploy/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (14)Versions (28)Used By (0)

Laravel Self Deploy
===================

[](#laravel-self-deploy)

[![Latest Version on Packagist](https://camo.githubusercontent.com/63cf4861173b2cbb8e1fea2ceeff34d1715b71a5aefe21771f3f3629b8d7d762/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f69706572616d756e612f6c61726176656c2d73656c662d6465706c6f792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iperamuna/laravel-self-deploy)[![Total Downloads](https://camo.githubusercontent.com/f7e1c738550bdbd711c873b9bd6ec4e6454ff22b96ee46da1151bf7cee938580/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f69706572616d756e612f6c61726176656c2d73656c662d6465706c6f792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iperamuna/laravel-self-deploy)[![License](https://camo.githubusercontent.com/d3c734061661a8f108cc0319ad27ba0ccbece21ace08e72843de8824c0ba705e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f69706572616d756e612f6c61726176656c2d73656c662d6465706c6f792e7376673f7374796c653d666c61742d737175617265)](https://img.shields.io/packagist/l/iperamuna/laravel-self-deploy)

A simple, opinionated Laravel package for managing self-hosted "Blue/Green" style deployments using Artisan commands and shell scripts. It allows you to define deployment configurations in a config file, generate deployment artifacts (Blade templates -&gt; Shell scripts), and trigger them locally or on a server.

Features
--------

[](#features)

- **Configuration-driven**: Define your environments (e.g., `production`, `staging`) and deployments in `config/self-deploy.php`.
- **Blade-powered Scripts**: Uses Blade templates for your shell scripts, allowing you to inject config variables (like paths, service names) dynamically.
- **Artifact Generation**: Compiles Blade templates into executable `.sh` files.
- **Deployment Trigger**: Run all generated deployment scripts in the background via a single Artisan command.
- **Systemd Supervision**: Supports running deployments as transient systemd units for better process isolation, automatic cleanup, and live monitoring.
- **Resource Management**: Configure CPU Niceness and IO scheduling to prevent deployments from impacting web server performance.
- **Timezone Awareness**: Configure specific timezones for deployment logs to match your local application time.
- **Blue/Green Ready**: The default template is set up for a Blue/Green deployment strategy using Systemd and Nginx upstream switching.
- **Pretty Configuration**: Automatically formats your `config/self-deploy.php` with double-newline spacing formatted as a standard PHP array.
- **Log Viewer Ready**: Optimized single-line log headers and trailing newlines for seamless integration with Laravel Log Viewer packages.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require iperamuna/laravel-self-deploy
```

Publish the configuration and base view:

```
php artisan vendor:publish --tag=self-deploy-config
php artisan vendor:publish --tag=self-deploy-views
```

Configuration
-------------

[](#configuration)

Edit `config/self-deploy.php` to define your environments and deployments.

```
return [
    'deployment_configurations_path' => resource_path('deployments'),
    'deployment_scripts_path' => base_path('.deployments'),
    'environments' => [
        'production' => [
             'app-production' => [
                 'deploy_path' => '/var/www/my-app',
                 'blue_service' => 'my-app-blue.service',
                 'green_service' => 'my-app-green.service',
                 // ... other custom variables for your script
             ]
        ]
    ]
];
```

Usage
-----

[](#usage)

### 1. Create a Deployment Configuration File

[](#1-create-a-deployment-configuration-file)

Create a Blade template for a specific deployment configuration. This command now supports **interactive environment and deployment creation**.

#### Interactive Mode (Recommended)

[](#interactive-mode-recommended)

```
php artisan selfdeploy:create-deployment-file
```

The command will guide you through:

1. **Select or Add Environment**: Choose an existing environment or create a new one.
2. **Select or Add Deployment**: Choose an existing deployment configuration or create a new one.
3. **Multi-Server Setup**: Specify if this deployment spans multiple servers.
    - **Interactive Server Keys**: If multi-server, enter your server identifiers (e.g., `web-01`, `worker-01`).
    - Keys are automatically converted to `snake_case` and must be at least 4 characters.
    - **Hint**: Ensure `SELF_DEPLOY_SERVER_KEY` is defined in each server's `.env` to match these keys.
4. **Add Config Keys**: Dynamically add key-value pairs for your deployment.
    - **Validation**: Keys must be unique and at least 4 characters.
    - **Snake Case**: All keys are automatically formatted to `snake_case`.
    - **Default Values**: Enter default values for each key (blank values accepted as empty strings).
    - Press `d` to finish adding keys.
5. **Multiple Artifact Generation**: For multi-server setups, individual Blade templates are created as `{configuration}-{serverkey}.blade.php`.
6. **Generate Bash Script**: Optionally generate the deployment script(s) immediately.

**Example: Creating a Multi-Server Setup Interactively**

```
❯ php artisan selfdeploy:create-deployment-file

 Select Environment or Add New production
 Select Deployment Configuration or Add New + Add New Deployment Configuration
 Enter deployment configuration name laravel-app
 Does this deployment have multiple app servers? Yes

 INFO Enter Server Keys one by one. Press "Enter" on an empty line or "d" to finish.

 Server Key (or "d" to done) web-01
 Server Key (or "d" to done) web-02
 Server Key (or "d" to done) d

 INFO Enter configuration key names. Press "d" to finish.

 Config Key deploy_path
 Default value for [deploy_path] /var/www/app

 Config Key branch
 Default value for [branch] main

 Config Key d

 INFO Deployment configuration [laravel-app] updated in [production].
 Created: resources/deployments/laravel-app-web_01.blade.php
 Created: resources/deployments/laravel-app-web_02.blade.php

 # Example Content of laravel-app-web_01.blade.php
 {{ $self_deploy_server_key }}
 {{ $deploy_path }}
 {{ $branch }}

 Do you want to generate the Bash script now? Yes

```

### 2. Publish (Generate) Deployment Scripts

[](#2-publish-generate-deployment-scripts)

Compile your Blade templates into executable `.sh` scripts in your configured `deployment_scripts_path`.

> **Note**: This command requires `sudo` privileges to ensure scripts are marked as executable and owned correctly.

```
# Interactive (Select deployment & optional server)
sudo php artisan selfdeploy:publish-deployment-scripts

# All deployments in production (Smart Filtering applies)
sudo php artisan selfdeploy:publish-deployment-scripts --all --environment=production --force
```

**Smart Filtering**: If you run with `--all` on a server where `config('app.server_key')` is set, only the script matching that server key will be generated for multi-server deployments.

### 3. Run Deployments

[](#3-run-deployments)

Trigger all `.sh` scripts found in your `deployment_scripts_path` directory.

#### Command Parameters

[](#command-parameters)

The `run` command supports triggering all scripts or a single specific script:

```
# Run ALL generated scripts (default)
php artisan selfdeploy:run

# Run only a SINGLE script by name (relative to .deployments)
php artisan selfdeploy:run --script=app-production

# Run only a SINGLE script by absolute path
php artisan selfdeploy:run --script=/home/user/my-custom-script.sh
```

Additionally, you can pass optional commit details directly to your deployment scripts:

```
php artisan selfdeploy:run {commit-hash?} {commit-msg?}
```

These are passed as `$1` and `$2` respectively to the generated scripts, allowing you to include external metadata (like a GitHub commit) in your logs.

**Example with commit details**

```
php artisan selfdeploy:run a6bcf12 "feat: add commit support"
```

#### Live Log Monitoring

[](#live-log-monitoring)

- **--tail**: Automatically opens `tmux` and tails journals for started units.
- **--force**: Skips the log tailing prompt (finishes after triggering scripts).
- **Tmux Integration**: If `tmux` is installed, it opens a session named `plcargo-logs` with a **horizontal split** showing binary-safe unit journals.
- **Fallback**: If `tmux` is missing, it tails journals one after another.

To automatically regenerate scripts before running:

```
php artisan selfdeploy:run --publish
```

### Available Shell Helpers

[](#available-shell-helpers)

The base deployment script provides several helper functions you can use in your Blade templates:

- `log "message"`: Logs a message with a timestamp.
- `run "command"`: Logs "RUN: command" and then executes it.
- `log_cmd "command"`: Logs the command with a timestamp and then executes it (useful for systemctl commands).

### Execution Modes

[](#execution-modes)

You can control how scripts are executed in your `config/self-deploy.php`:

#### 1. Shell Mode (Default)

[](#1-shell-mode-default)

Runs scripts in the background using standard shell execution (`&`). Simple and cross-platform.

#### 2. Systemd Mode (Recommended for Production)

[](#2-systemd-mode-recommended-for-production)

Runs each script as a transient systemd unit. This is ported from professional deployment actions and provides:

- **Isolation**: Each deployment runs in its own unit.
- **Resource Limiting**: Prevents high-CPU/IO tasks from lagging the main site.
- **Live Logs**: Watch the deployment with `journalctl -u [unit-name] -f`.

To enable Systemd mode:

```
'execution_mode' => 'systemd',

'systemd' => [
    'nice' => 10,
    'io_scheduling_class' => 'best-effort',
    'io_scheduling_priority' => 7,
    'user' => env('SELF_DEPLOY_USER'), // Optional: Run as specific user
    'env' => [
        'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
    ],
],
```

Multi-Server Orchestration
--------------------------

[](#multi-server-orchestration)

If you have multiple app servers for a single environment, you can manage them using the `hosts` configuration and the `remote-deploy` command.

### 1. Configure Hosts

[](#1-configure-hosts)

Add `hosts`, `ssh_user`, and `remote_path` to your environment configuration in `config/self-deploy.php`:

```
'environments' => [
    'production' => [
        'hosts' => ['192.168.1.10', '192.168.1.11'],
        'ssh_user' => 'deploy',
        'remote_path' => '/var/www/my-app',
        'app-production' => [
            'deploy_path' => '/var/www/my-app',
            // ...
        ]
    ]
]
```

### 2. Trigger Remote Deployment

[](#2-trigger-remote-deployment)

Run the `remote-deploy` command from your local machine (or CI/CD server) to reach out to all configured hosts via SSH and trigger their local self-deployments.

```
php artisan selfdeploy:remote-deploy production
```

This command will:

1. Connect to each host via SSH as the configured `ssh_user`.
2. `cd` into the `remote_path`.
3. Run `php artisan selfdeploy:run --force`.

To automatically regenerate scripts on remote servers before deploying:

```
php artisan selfdeploy:remote-deploy production --publish
```

Roadmap
-------

[](#roadmap)

- Add support for remote server execution (SSH).
- Implement rollback functionality.
- Add web interface for managing deployments.
- Support for Docker-based deployments.
- Slack/Discord/Telegram notifications integration.

Development
-----------

[](#development)

To run the package tests:

```
composer test
```

Or run Pest manually:

```
vendor/bin/pest
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance78

Regular maintenance activity

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

27

Last Release

121d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e7f282b7449477d5baaf64bdb40fcb7d9c8c638fb96a431413c7293344e3182f?d=identicon)[iperamuna](/maintainers/iperamuna)

---

Top Contributors

[![iperamuna](https://avatars.githubusercontent.com/u/3013395?v=4)](https://github.com/iperamuna "iperamuna (52 commits)")

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/iperamuna-laravel-self-deploy/health.svg)

```
[![Health](https://phpackages.com/badges/iperamuna-laravel-self-deploy/health.svg)](https://phpackages.com/packages/iperamuna-laravel-self-deploy)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[laravel/boost

Laravel Boost accelerates AI-assisted development by providing the essential context and structure that AI needs to generate high-quality, Laravel-specific code.

3.5k21.5M588](/packages/laravel-boost)[livewire/flux

The official UI component library for Livewire.

9527.8M127](/packages/livewire-flux)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

725172.4k14](/packages/tallstackui-tallstackui)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
