Bỏ qua để đến nội dung
Laravel Run a Laravel app as a PHP site — production .env, database, migrations, the scheduler and queue workers, allowlisted artisan commands and atomic deploys — from the dashboard, the mz CLI, MCP or REST.

Laravel

Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.

A Laravel app runs as a PHP site with the framework set to Laravel: nginx serves public/, the site’s own PHP-FPM pool runs the code, and MZPanel looks after the parts a Laravel app needs around it: a production .env, the database, migrations, the scheduler, queue workers and the usual artisan housekeeping. Laravel is one of the PHP frameworks next to plain PHP and Symfony. It is on every plan, Free included, like every other site type.

The Laravel jobs below (site.laravel, site.laravel-status, site.artisan and the laravelScheduler / laravelQueue switches of site.create) need an agent newer than 0.2.174. Older agents answer exit 127: update the agent first.

  1. Open a server’s Sites list and press New site.
  2. Pick PHP / Laravel, enter the Domain and choose Framework → Laravel. The document root defaults to /public.
  3. Optionally set a Git repository (your app instead of a fresh skeleton) and its Branch, the PHP version and a database name. For a private repository, pick it under From a connected account (see Private repositories).
  4. Keep SSL on auto and create the site.

The agent then:

  • creates the app (composer create-project, or clones your repository);
  • creates a database: a MariaDB database and user when MariaDB is installed on the box (dbName / dbUser pick the names), otherwise a SQLite file;
  • writes a production .env: APP_ENV=production, APP_DEBUG=false, APP_URL=https://<domain>, an APP_KEY and the database settings;
  • runs the migrations;
  • turns on the scheduler and one queue worker (both can be switched off at create time or later).

If any of these steps fails, the job fails with scaffold_failed (it no longer reports success over a broken app); the message names the step.

A PHP site (plain PHP, Laravel or Symfony) can be created from, and atomically deployed from, a private repository through a Git account connected under Git connections (Connect → Git): a GitHub App installation or a personal access token (GitHub, GitLab or Bitbucket). It works the same way as Docker app builds. There are no SSH deploy keys to set up.

  • In New site, pick the account and the repository under From a connected account. The URL and the default branch are filled in. Over the API, send gitConnectionId (the connection’s id) with an https:// gitRepo, plus gitBranch if you need a branch other than the default.
  • For each clone, the control plane gets a fresh token from the connection: a GitHub App installation token (user x-access-token) or the stored PAT (user = the connection’s account). The token is never stored in the job, the site registry or .git/config, and is masked in every output line. On the server it reaches git only through a short-lived GIT_ASKPASS script.
  • The repository must be an https:// URL on the connection’s provider (github.com, gitlab.com or bitbucket.org). Other URLs are refused with 400 bad_git_connection.
  • The site remembers its connection. Later deploy.run jobs get a fresh token without sending gitConnectionId again. deploy.init to the same repository keeps the connection. deploy.init to a different repository without a connection forgets it. Deleting the site forgets it too.
  • Members a site is shared with cannot pick a connection (403 site_permission). Their deploys use the connection the owner set up.
  • Without gitConnectionId, nothing changes: public repositories and ssh:// / git@host:path URLs clone as before.

The server’s agent must include private-repository support (released after 0.2.180). With an older agent the clone fails with an authentication error; update the agent.

The app’s environment is the .env file in the app folder (or shared/.env once the site uses atomic deploys, see below). Read and replace it with the same jobs as a Node.js / Python / Go site’s environment: site.env-get {domain} returns the whole file; site.env {domain, env} replaces it (env = the full dotenv text, up to 20,000 characters).

site.env is never queued for an offline server (409 server_offline): the queue would hold the values in clear. After changing .env, run config:cache (or optimize) so a cached config picks it up.

  • The scheduler is a cron entry owned by the site (/etc/cron.d/mz-site-<user>-scheduler) that runs php artisan schedule:run every minute as the site’s user, inside the same sandbox as other site cron jobs. It shows under the site on the Cron page; switch it on or off with site.laravel, not by editing the entry.
  • Queue workers are systemd units owned by the site that run php artisan queue:work (1 to 8 processes). They are restarted after every atomic deploy.

These are part of the site, not Supervisor daemons, so they count against no plan limit and are removed with the site.

Change them with site.laravel:

GoalJob body
Read the state{"type": "site.laravel-status", "domain": "app.example.com"}
Scheduler off{"type": "site.laravel", "domain": "app.example.com", "scheduler": false}
Queue on, 4 workers{"type": "site.laravel", "domain": "app.example.com", "queue": true, "queueProcs": 4}
Queue off{"type": "site.laravel", "domain": "app.example.com", "queue": false}

Leave out a field to keep its current value. Both jobs answer the status object:

{ "ok": true, "domain": "app.example.com", "framework": "laravel",
"app_dir": "<the app folder>", "atomic": false,
"laravel_version": "12.x", "php_version": "8.4",
"env": { "APP_ENV": "production", "APP_DEBUG": "false",
"APP_URL": "https://app.example.com", "DB_CONNECTION": "mysql" },
"scheduler": { "enabled": true },
"queue": { "enabled": true, "procs": 1, "active": "active" } }

queue.active is the worker unit’s state: active, inactive, failed, or empty when the queue is off.

site.artisan runs one artisan command from a fixed list as the site’s user, in the app folder, and streams its output. There is no free-form command line.

CommandWhat it does
migrateRun pending migrations (production-safe, no prompt)
migrate:statusList migrations and whether they ran
optimize / optimize:clearBuild or clear every cache (config, routes, views, events)
config:cache / config:clearCache or clear the config (run after a .env change)
route:cacheCache the routes
view:cacheCompile the Blade views
cache:clearFlush the application cache
queue:restartAsk the queue workers to restart after their current job
storage:linkCreate the public/storage symlink
downMaintenance mode: the site answers 503 to every visitor until up
upLeave maintenance mode
aboutPrint the app’s environment overview

The job ends with {"ok": true, "command": "migrate", "exit_code": 0}. A command that exits non-zero fails the job and keeps its output in the log.

With a Git repository and the Releases tab (deploy.*, Pro, see Staging & deploys), each deploy builds a new release folder and flips the current symlink. For a Laravel site:

  • .env and storage/ live in shared/ and are linked into every release, so they survive deploys and rollbacks;
  • when you set no build command, the default Laravel build runs: composer install --no-dev, storage:link, migrate --force and optimize;
  • after the flip, the site’s own PHP-FPM pool is reloaded (OPcache sees the new code) and the queue workers restart.

A rollback switches the code back instantly but does not undo migrations. Keep them backward compatible.

Terminal window
mz site create app.example.com --type php --framework laravel \
--git https://github.com/acme/app.git --db-name app --laravel-queue off --json
mz site laravel-status app.example.com --json
mz site laravel app.example.com --queue on --queue-procs 2 --json
mz site artisan app.example.com migrate --json
mz site artisan app.example.com down --json # maintenance mode

Every action is an async job: jobs_create {id: <server UUID>, body: {...}} over MCP, POST /v1/servers/{id}/jobs over REST. Read the exact fields with jobs_schema {type} first, then poll jobs_get (or pass wait).

GoalJob bodyToken level
Create a Laravel site{"type": "site.create", "domain": "app.example.com", "siteType": "php", "framework": "laravel", "phpVersion": "8.4", "gitRepo": "https://github.com/acme/app.git", "dbName": "app", "laravelScheduler": true, "laravelQueue": true}operate
Create from a private repo{"type": "site.create", "domain": "app.example.com", "siteType": "php", "framework": "laravel", "gitRepo": "https://github.com/acme/private-app.git", "gitBranch": "main", "gitConnectionId": "<connection id>"}operate
Read the Laravel state{"type": "site.laravel-status", "domain": "app.example.com"}read
Scheduler / queue / worker count{"type": "site.laravel", "domain": "app.example.com", "scheduler": true, "queue": true, "queueProcs": 2}operate
Run migrations{"type": "site.artisan", "domain": "app.example.com", "command": "migrate"}operate
Rebuild caches after an .env change{"type": "site.artisan", "domain": "app.example.com", "command": "optimize"}operate
Read / replace .env{"type": "site.env-get", "domain": "app.example.com"} · {"type": "site.env", "domain": "app.example.com", "env": "APP_ENV=production\n…"}operate
Enable atomic deploys from a private repo (Pro){"type": "deploy.init", "domain": "app.example.com", "repo": "https://github.com/acme/private-app.git", "branch": "main", "gitConnectionId": "<connection id>"}operate
Deploy a release (Pro){"type": "deploy.run", "domain": "app.example.com", "ref": "main"} (the remembered connection is used)operate

Notes for AI agents:

  • laravelScheduler and laravelQueue are used only with siteType: "php" and framework: "laravel"; left out, both are on.
  • site.artisan with command: "down" takes the site offline for visitors. Confirm with the user first and run up afterwards.
  • site.env replaces the whole file: read it with site.env-get, change the lines, send it back.
  • None of these kinds is plan-gated except deploy.* (Pro).
  • For a private repository, list the org’s Git connections first (GET /v1/git/connections, status connected) and pass the id as gitConnectionId. Never put a token in gitRepo. gitToken is not an input of these kinds.

A failed create rolls itself back: the Linux user, PHP pool, vhost, database and DB user it made are removed, so you can retry with the same domain.

CodeMeaningFix
scaffold_failedcomposer create-project / clone / composer install failed; error.detail holds the output tailFix the cause (repository access, composer.json requirements, disk space) and create the site again
composer_unavailableComposer could not be installed or verified on the serverCheck outbound HTTPS to getcomposer.org, then retry
ext_missingA PHP extension Laravel needs could not be installedInstall it with php.ext-install, then retry
db_failedThe MariaDB database or user could not be createdCheck MariaDB is running (db.status); retry or pass another dbName
bad_db_name / bad_db_userdbName / dbUser is not a valid MySQL identifierUse letters, digits and _
env_failed / key_generate_failedThe .env could not be written or APP_KEY generatedCheck disk space and the site’s file ownership
migrate_failed / optimize_failedphp artisan migrate --force / optimize failed; error.detail holds the outputFix the migration or config error in the app, then run site.artisan again
config_cache_failedsite.env saved the .env but config:cache then failedFix the value it complains about and save again
no_appsite.artisan on a site with no Laravel app deployed yetDeploy the app first
bad_git_url / bad_git_branchgitRepo is not an https://, ssh://, git@host:path or file:// URL, or the branch name is invalidFix the URL. For a private repository, use a Git connection (gitConnectionId)
400 bad_git_connectionThe Git connection does not exist in this workspace, or the repository is not an https:// URL on the connection’s providerPick a connected account at Connect → Git and use the repository’s https clone URL
502 git_token_failedNo token could be obtained from the connection (GitHub App uninstalled, PAT missing or unreadable)Re-verify or reconnect the account at Connect → Git, then retry
bad_args (job)The agent got a token with a non-https repository URLUse the https:// clone URL
site_user_existsThe site’s Linux user already exists but no site is registered for the domain (not left by an MZPanel create)Remove that user on the server (userdel -r <user>) or use another domain
db_existsThe database or DB user named by dbName / dbUser already existsPick another dbName / dbUser; MZPanel never takes over an existing database
not_laravelsite.laravel, site.laravel-status or site.artisan on a site that is not PHP with framework LaravelUse a Laravel site; for other sites use site.env and the site’s own tools
bad_commandsite.artisan with a command outside the list (the API rejects it as 400 bad_request first)Pick a command from the table above
exit 127The agent is older than the Laravel supportUpdate the agent
  • 500 error after deploy? Read site.logs {domain} and storage/logs/laravel.log in Files. A missing APP_KEY or a stale config cache are the usual causes: run config:clear, then optimize.
  • Jobs pile up in the queue? Check queue.active in site.laravel-status. failed means the worker keeps crashing: read the log, fix, then queue:restart.
  • Sites — creating sites of every type.
  • Site tools — the Manage drawer.
  • Staging & deploys — atomic releases, previews, rollback.
  • PHP — PHP versions, extensions and per-site php.ini.