Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

PHPadvanceddevopsAI generated

Custom Deployment Automation Tool (Capistrano-like) in PHP

Build a deployment tool in PHP, similar to Capistrano or Deployer, that releases a web application to one or more servers over SSH. Each deployment goes into a new timestamped release folder: the tool fetches the code, installs dependencies, runs build steps, links shared files (like uploads and the .env file), and only when everything succeeded switches a current symlink to the new release in one atomic step, so visitors never see a half-deployed site. Rolling back to the previous release is a single command, and old releases are cleaned up automatically. SSH connections use phpseclib. Test it on your own servers or on containers you run. You'll learn SSH automation from PHP, atomic deployment with symlinks, building a robust CLI, and handling failures safely.

Estimate
~12.5h
Steps
6
Completed by
0
Proposed by
codeseed.app

phpseclib · PHP CLI

Project roadmap

  1. 01

    Design the release structure

    ~1.5h

    Write DESIGN.md: the folders on the server (releases/TIMESTAMP, shared/ for files kept between releases, and current as a symlink to the active release), the deployment steps and which can fail safely, how the symlink is switched atomically (create a temporary symlink, then rename it over current), how rollback works, how many releases are kept, and a lock file so two deployments can't run at once. Done when: DESIGN.md explains the structure and every step.

  2. 02

    Run commands over SSH

    ~2h

    Create a Composer project with phpseclib and symfony/console. Write an SshConnection class that connects with a private key (checking the server's host key against a stored fingerprint), runs commands, returns their output and exit code, and stops the deployment with a clear message when a command fails. Set up test servers with Docker containers running an SSH server. Done when: the tool can connect to a test server and run a command, reporting failures clearly.

  3. 03

    Build the deploy pipeline

    ~3h

    Implement deploy: take the lock, create a new release folder, fetch the code (git clone at a chosen branch or tag, or upload an archive), link shared files and folders, run the build steps from the config (such as composer install --no-dev and a cache warm-up), run an optional health check, then switch current. On any failure, delete the failed release and release the lock. Print each step with its duration. Done when: a sample PHP app deploys to the test server, and a failing build step leaves the old release live.

  4. 04

    Switch atomically and roll back

    ~2h

    Switch current with ln -sfn to a temporary name followed by mv -T, so the change is atomic, and reload PHP-FPM or the web server if configured. Implement rollback (switch current to the previous release), releases (list them with the active one marked), and cleanup (keep the last N). Done when: rollback restores the previous release immediately, and old releases are removed.

  5. 05

    Support multiple servers and environments

    ~2h

    Read a config file (YAML or PHP) with environments (staging and production), each with its servers, paths, branch and steps. Deploy to all servers of an environment, preparing releases on every server first, then switching them all together, and rolling back those already switched if any fails. Add --dry-run showing the commands that would run. Done when: deploying to two test servers switches both, and a failure on one leaves both on the old release.

  6. 06

    Test it

    ~2h

    Write PHPUnit tests for the config parsing and the step planning (with a fake SSH connection recording commands), and integration tests against the Docker test servers: a successful deployment, a failing build, rollback, cleanup, the lock preventing parallel deploys, and multi-server switching. Done when: all tests pass.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~12.5h · 6 steps

Tech stack

phpseclibPHP CLI