Staging & deploys
Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.
MZPanel gives you a full deploy workflow from the dashboard and the API: deploy sites from a git repo into atomic release folders with one-click rollback, spin up a throwaway environment per pull request, clone a site on the same server or to another server, clone a whole project environment, and for WordPress, push changes from staging back to live. You drive it from a site’s Deploy and Staging tabs (open any site from Sites), from Projects, or over MCP. Git deploys, previews, push-to-live and cross-server copies are on the Pro plan and up. Same-server clones work on every plan. Docker apps and stacks have their own build and release flow (Docker app builds from Git or an uploaded folder, and auto-deploy of an app or stack on git push, are on every plan): see Docker apps & stacks.
Atomic deploys & rollback
Section titled “Atomic deploys & rollback”For PHP-framework (Laravel / Symfony), Node, Python, Go and static sites, MZPanel deploys into release folders with an atomic symlink switch — the Capistrano-style pattern — from the site’s Deploy tab.
- Each deploy builds into a new release folder; a
currentsymlink is flipped atomically to point at it, so there’s no downtime and no half-applied state. - Persistent files (
.env, uploads,storage/) live in ashared/directory symlinked into every release, so they survive deploys. - Your build command (e.g.
composer install,npm run build) runs in the new release folder. If a build step fails, the symlink is not switched — the old release keeps serving. - The last few releases are kept, so rollback is just flipping the symlink back — instant, no rebuild.
- PHP sites: after the flip the site’s own PHP-FPM pool is reloaded, so OPcache serves the new release at once.
- Laravel: with no build command set, the default build runs
composer install --no-dev,storage:link,migrate --forceandoptimize; the queue workers restart after the flip. See Laravel.
The Deploy tab shows the release timeline (which release is active) with a per-release Rollback.
Git-deploy from a repo
Section titled “Git-deploy from a repo”Point a deploy at a git repository and branch: MZPanel clones it, runs your build command, and flips the release symlink. Build output streams live to the dashboard. The build runs on your server via the agent — your source code never passes through MZPanel’s infrastructure.
Private repositories. Connect the account once under
Git connections (GitHub App or personal access token). In the
Deploy tab, pick the repository under From a connected account before you
enable atomic deploys. deploy.init then carries gitConnectionId, the site
remembers the connection, and every later Deploy (deploy.run) clones with a
fresh token without sending it again. The repository must be an https:// URL on the
connection’s provider. The token is never written to the site’s registry or to
.git/config. Re-running deploy.init with another repository and no connection
forgets the old one. Sites created from a private repository
(site.create with gitConnectionId) already
remember their connection.
Containerized workloads (Docker apps and Compose stacks) build from git a different way — with a Dockerfile or Nixpacks auto-detect. See Docker apps & stacks for that path.
PR preview environments
Section titled “PR preview environments”Open a pull request and MZPanel can deploy a throwaway preview environment for
it, then tear it down when the PR is closed or merged. Each preview gets its own
domain with HTTPS — for example pr<n>-<app>.box.mzpanel.com — so reviewers can
click through the change before it ships. You can also create and destroy previews
by hand from the Deploy tab.
Previews are triggered by the pull_request webhook from a connected GitHub repo
(a per-repo webhook or a GitHub App installation).
Previews on a spare server
Section titled “Previews on a spare server”A busy server doesn’t have to carry every preview. When a Docker app’s server has a tag and another server with the same tag has more free memory, the app’s PR preview is built there instead, and later pushes and the close event follow it. The preview gets the app’s Git source, builder, Dockerfile, build context, port and memory limit. It stays on the app’s own server when:
- the app has build arguments or a saved registry login (they never leave its server);
- either server runs an agent older than 0.2.145;
- no preview domain can be issued, or no other same-tag server is online with room for a build (1.5 GB RAM and 3 GB disk free);
- the other servers are homelab boxes or have Exclude from automatic placement on.
Stack previews always stay on the stack’s server. Previews remain a Pro feature and the per-server preview limit counts spare-box previews against the app’s server.
Clone a site: same server, another server, or a whole environment
Section titled “Clone a site: same server, another server, or a whole environment”- Same server, new domain (every plan, every site type): the Clone action on a
site copies files, database and config under a new domain. WordPress URLs are
search-replaced for the new domain. Job kind
site.clone(domain,target). - To another server (Pro, every site type): choose a target server in the clone
drawer. WordPress, static, PHP and runtime sites are copied with their files,
database and config, then served under the new domain on the target. Overwriting an
existing site on the target is WordPress-only. MCP
sites_clone_xserver(POST /v1/servers/{id}/clone-xserverwithdstServerId,sourceDomain,newDomain, optionaloverwrite). To move a Docker app or stack with its domains, use Moves & clones. - A whole project environment (Pro): Clone environment on a project creates a
new environment with its shared variables, a live copy of each app and stack, and a
site clone for each site, with domains from a pattern such as
staging.{domain}. MCPprojects_environment_clone(call withdryRun: truefirst to see the planned names and domains), then followprojects_environment_clone_get.
WordPress: staging and push-to-live
Section titled “WordPress: staging and push-to-live”For WordPress, the loop is clone, edit on staging, push to live. Clone the site to a staging domain on the same server (above), make your changes there, then push selected pieces back to production from the staging site’s Staging tab.
The push is not all-or-nothing — you choose exactly what goes:
| Piece | Options |
|---|---|
| Files | Whole webroot, just wp-content, themes + plugins, uploads, or none (via rsync) |
| Database | All tables, selected tables (e.g. wp_posts + wp_postmeta), or none — with reverse search-replace of the staging domain back to production |
| wp-config / secrets | Never pushed — production credentials stay intact |
Safety is built in: a push can take a snapshot of production first (so you can roll back), and a dry-run shows the file and table changes before anything is written. A maintenance window is enabled briefly during the database import.
How it works
Section titled “How it works”Every action here dispatches a job to the server’s agent, which runs it natively
against your webroot — no mz shell-out, and nothing leaves the box.
| Action | Job | Agent runs |
|---|---|---|
| Clone (same server) | site.clone | site clone <domain> --to <new domain> |
| Clone to another server | sites_clone_xserver route | site bundle on the source, site clone-import on the target |
| Dry-run / push to live | site.push | site push <staging> --to <prod> (rsync + optional DB) |
| Enable atomic deploys | deploy.init | scaffolds releases/, shared/, current |
| Deploy a release | deploy.run | clone → build command → atomic symlink flip |
| Rollback | deploy.rollback | re-points current at a kept release |
| List releases | deploy.list | reads the release timeline |
| Create / destroy preview | deploy.preview-create / -destroy | per-PR preview env under pr<n>-… |
Release history and the active symlink live on the box; MZPanel’s control plane only records the connected repo/branch and preview webhook wiring.
Automate it
Section titled “Automate it”The REST API and MCP are on every plan; the Pro gates above still apply
(403 tier_required). Every on-box step is a job: jobs_schema with the kind, then
jobs_create and jobs_get.
| Goal | Calls |
|---|---|
| Enable atomic deploys on a site | deploy.init ({"domain", "repo", "branch", "build"}) |
| Enable atomic deploys from a private repo | deploy.init with gitConnectionId (an id from GET /v1/git/connections) and an https:// repo on that provider |
| Deploy the latest commit | deploy.run, then jobs_get (or follow the job stream in the dashboard). A site with a remembered connection needs no gitConnectionId; pass one only to switch connections |
| Roll back | deploy.list to pick a release, then deploy.rollback (opt-in scope backups:restore) |
| PR preview by hand | deploy.preview-create / deploy.preview-destroy (destroy needs sites:delete) |
| Clone on the same server | site.clone |
| Copy to another server | sites_clone_xserver |
| Clone a project environment | projects_environment_clone (dryRun: true first), projects_environment_clone_get |
| WordPress push-to-live | site.push (try dryRun first; needs backups:restore because it overwrites live data) |
Each action maps to an mz command on the box — the same engine the dashboard
drives. SSH in and run them directly, or let an on-box AI (e.g. Claude Code) run them:
mz site clone example.com --to staging.example.com --mode new --jsonmz site push staging.example.com --to example.com \ --files wp-content --db --dry-run --json # preview; drop --dry-run to applymz deploy run app.example.com --json # build + atomic releasemz deploy rollback app.example.com --to <release>Pass a sub-action and --json for machine output. See
The mz CLI and the command catalog.
Gotchas & troubleshooting
Section titled “Gotchas & troubleshooting”- Push-to-live is same-server, WordPress-only. A staging push runs on one box,
from a WordPress staging copy to a WordPress production site. To copy a site to
another server use
sites_clone_xserver; to move a Docker app or stack use Moves & clones. - Atomic deploys are for non-WordPress sites. WordPress writes to its webroot at runtime, so it uses Clone → Staging, not the release-folder Deploy tab.
- Rollback is code-only. Flipping the symlink back does not undo database migrations — keep them backward-compatible.
- Private repo errors.
400 bad_git_connection= the connection is not in this workspace or the repo is not anhttps://URL on its provider;502 git_token_failed= no token could be obtained from the connection (re-verify it under Connect → Git); adeploy.initthat endsclone_failedmeans the token cannot read the repository, and the site is left unconverted. Site previews (deploy.preview-create) do not use the connection yet, so a preview of a private repository fails to clone. - Fork PRs are ignored on purpose. Previews build only for branches in the same repository, so untrusted fork code never runs on your box.
- Auto-posting the preview URL back to the PR is still being finalized. For now, copy the preview URL from the Deploy tab.
- Offline servers. Clone, push, deploy and previews all run as agent jobs. Over the
API or MCP, a job sent while the agent is offline is queued and runs when it
reconnects (kept up to 24 hours) unless you add
?durable=0; kinds that carry secrets or environment values are refused with409 server_offlineinstead. The dashboard sendsdurable=0, so there an offline click endsexpired_offlinerather than running hours later. Cross-server clones (sites_clone_xserver) need both servers online. See Jobs.
Related
Section titled “Related”- Docker apps & stacks — git-build with Dockerfile/Nixpacks, releases and rollback for containers.
- Git connections — connect repos for private deploys and deploy-on-push.
- Server sites — the site list these tabs open from.
- Projects · Moves & clones — environments and cross-server moves.
- The mz CLI — driving the box from the command line.