Laravel Go apps
Laravel for Go, compiled on deploy and switched blue/green. Experimental.
A Laravel Go app compiles to one binary that serves HTTP by itself. Cipi builds it on the server at every deploy with go build, starts the new binary beside the old one and moves Nginx only once it answers: no downtime, and a rollback one command away.
Laravel for Go is in beta, and this app type is experimental: commands and defaults may still change with the framework. Use it for new projects and staging before you rely on it.
$ sudo cipi app create --go --user=blog --domain=blog.example.com --repository=git@github.com:acme/blog.git --engine=pgsql
Create one#
# With a database named after the app, a queue worker and the scheduler sudo cipi app create --go --user=blog --domain=blog.example.com \ --repository=git@github.com:you/blog.git # On MariaDB or MySQL, no worker, no scheduler sudo cipi app create --go --user=api --domain=api.example.com \ --repository=git@github.com:you/api.git --engine=mariadb \ --no-queue --no-scheduler # An API with no database of its own sudo cipi app create --go --user=edge --domain=edge.example.com \ --repository=git@github.com:you/edge.git --no-db # Inertia with server-side rendering sudo cipi app create --go --user=shop --domain=shop.example.com \ --repository=git@github.com:you/shop.git --ssr # The program is not in the repository's root sudo cipi app create --go --user=svc --domain=svc.example.com \ --repository=git@github.com:you/svc.git --go-main=./cmd/server
| Flag | Meaning | Default |
|---|---|---|
--go | The app type. Also Laravel Go in the wizard | |
--repository | Git URL. Required | asked |
--db=NAME / --no-db | The database made with the app, or none | a database named after the app |
--engine | mariadb or pgsql: the database | PostgreSQL where the server has it, otherwise the server's default |
--no-queue | No queue worker | a worker runs |
--no-scheduler | No scheduler | it runs every minute |
--ssr | Inertia server-side rendering | off |
--go-main | The main package, when it is not the repository's root | . |
--build | The frontend build | npm run build; npm run build:ssr with --ssr |
--node-version | The Node major of the frontend build: 22 or 24 | the server's default |
--health-path | The route a new release must answer on | /up |
--branch, --env | As for every app |
The first Laravel Go app installs Go and the Node version of the build.
Trying Laravel's own skeleton? It has one branch, 0.x, and lists the PostgreSQL driver only. Without --branch Cipi deploys the repository's default branch, and the deploy gives the build the driver of the app's database, PostgreSQL or not: a copy of the skeleton deploys as it is.
Until the first deploy has gone through, the domain answers 502: nothing runs behind Nginx before a release has started.
The database#
A Laravel Go app does not choose its database driver when it runs: the driver is Go code of the app, a line of Options.Drivers in bootstrap/app.go, compiled into the binary. The skeleton Laravel publishes lists PostgreSQL's alone. Cipi makes the binary and the app's database agree at every deploy: a driver the build lacks is added to the build.
| The app's database | The driver the binary needs | With Laravel's skeleton as it is |
|---|---|---|
| PostgreSQL | postgres.Driver | Works: the driver is in bootstrap/app.go |
| MariaDB or MySQL | mysql.Driver | Works: the deploy adds the driver to the build |
Every deploy checks it first. Before the frontend and before the build, Cipi asks the go command which packages the binary is built from. When the driver DATABASE_URL asks for is among them, the build is the repository's, with nothing added. When it is not, Cipi adds it to the release's own copy of bootstrap/app.go — the import and the line in the Drivers list — builds with it and says so:
Database driver mysql — added to this build by Cipi (cipimysql.Driver in the Drivers list of this release's bootstrap/app.go)
Nothing is written to your repository: the next deploy does the same, until the repository lists the driver itself. It adds a driver to the build, not to your code: an app that writes SQL for one engine is not made to run on another.
In your own repository, name it anyway. Then go run, your tests and your CI build the driver production runs on:
// bootstrap/app.go — for a database on MariaDB or MySQL
import "go.laravel.com/db/mysql"
Drivers: []db.Driver{postgres.Driver, mysql.Driver},Run go mod tidy and commit go.mod and go.sum with it.
When the deploy stops instead. Cipi adds a driver only where it can see how: one Drivers: []db.Driver{…} list in bootstrap/app.go, and a module the go command can fetch. Otherwise the deploy stops at go:driver — after a few seconds, before anything is compiled — the file is as it was, and the message has the go command's own words and the two lines to write. Nothing changes for visitors.
Which engine a new app gets. PostgreSQL when the server has it, because that is the driver the skeleton lists; otherwise the server's default, which is MariaDB unless you changed it. --engine=mariadb or --engine=pgsql chooses. A server gets PostgreSQL with one command, next to the engine it has:
sudo cipi db install pgsql
Before the first deploy#
Three things about the repository are worth settling before the first deploy. The database driver is not one of them: the deploy sees to it.
| In the repository | Why |
|---|---|
go.sum committed | The build takes the versions it names. Without it, a build with dependencies stops at missing go.sum entry: run go mod tidy and commit the file |
Trust the proxy in bootstrap/app.go | Nginx is in front, on the same server. Without it the visitor's address is 127.0.0.1 and generated URLs start with http:// |
| The health route | New apps answer on /up. If yours moved it, say where: --health-path=/healthz |
// bootstrap/app.go
m.Proxies = []string{"127.0.0.1"}The main package#
Cipi builds the package in the repository's root, where Laravel's skeleton has its main.go. A repository that keeps its program elsewhere says where:
sudo cipi app create --go … --go-main=./cmd/server # at create sudo cipi app edit blog --go-main=./cmd/server # later, then deploy
The build and the driver check both use it. A directory that is not in the repository, or a package that is not main, stops the deploy with its name.
Where things live#
/home/blog/ ├── current -> releases/7 # the release being served ├── releases/6/ 7/ # source, public/, bin/app ├── shared/ │ ├── .env # APP_KEY, APP_URL, DATABASE_URL… │ └── storage/ # uploads, sessions, log files └── .cache/cipi-go/ # Go's module cache and build cache, kept between deploys
The binary is written into each release as bin/app. Every release has its own, so a rollback starts the binary that release was built with.
Environment#
~/shared/.env is linked into every release, and the binary reads it when it starts.
| Variable | Value |
|---|---|
APP_KEY | Generated |
APP_ENV, APP_DEBUG | production, false |
APP_URL | https:// and the app's domain. It follows sudo cipi app edit blog --domain=…, which also restarts the app |
DATABASE_URL | For the database made with the app, on 127.0.0.1 |
| Sessions, cache, queue | In the database. With --no-db: cookie, memory and sync |
| Logs | To stderr: the log of the slot |
INERTIA_SSR, INERTIA_SSR_URL | With SSR on: where the app finds its SSR server |
SERVER_HOST, SERVER_PORT | Not yours: Cipi sets them for each blue/green slot, whatever the file says |
sudo cipi app env blog # edit sudo cipi node restart blog # apply: a zero-downtime restart
Deploy#
$ sudo cipi deploy blog
The commit of the branch, with .env and storage/ linked in.
The go command is asked which packages the build has. The driver DATABASE_URL needs is added to the build when it is missing.
When the repository has a package.json. An API without one skips it.
With the server's Go, or the one go.mod asks for. The module cache and the build cache are shared between deploys: after the first one only what changed is compiled.
Your migrations are compiled into the binary. They run before the switch.
The release starts on the idle slot. When it answers on the health route, Nginx moves to it and the old process gets time to finish its requests.
Restarted on the new release: a worker runs the code it was compiled with.
If the new release never answers, it is stopped and the old one keeps serving: the deploy fails with nothing published.
sudo cipi deploy blog sudo cipi deploy blog --rollback sudo cipi app deploy-config blog --no-migrate sudo cipi app deploy-config blog --keep-releases=3 --build-timeout=3600
A rollback moves the code back, not the database. Add columns in one release and remove them in a later one, so the previous release still runs on the new schema.
Commands of the app#
The commands of a Laravel Go app are compiled into its binary. Run them from the release being served:
# As root sudo cipi app artisan blog migrate:status sudo cipi app artisan blog route:list # As the app's user sudo su - blog laravel queue:failed
laravel is a shell function for the app's user: it runs ~/current/bin/app from ~/current, where the .env is.
Queue worker and scheduler#
| What runs | Turn it on or off | |
|---|---|---|
| Queue worker | bin/app queue:work under Supervisor, in the live release | sudo cipi app edit blog --queue=on|off |
| Scheduler | bin/app schedule:run, every minute from the app's crontab | sudo cipi app edit blog --scheduler=on|off |
The worker is restarted on the new release after every deploy, once Nginx has moved, and is given two and a half minutes to finish the job it has. sudo cipi worker is for Laravel's PHP workers and Symfony's Messenger, and refuses a Laravel Go app.
Inertia server-side rendering#
With SSR on, a Node process beside the app renders the first page on the server. Cipi runs it for you, in the release that is serving.
sudo cipi app edit blog --ssr=on # or --ssr at create
sudo cipi deploy blog| What changes | |
|---|---|
The .env | INERTIA_SSR=true, and INERTIA_SSR_URL with the app's own port |
| The frontend build | npm run build:ssr, which also writes bootstrap/ssr/app.js. A build command of your own is left as it is: it has to write that file |
| A new program | node bootstrap/ssr/app.js under Supervisor, on the app's Node version, restarted on each new release |
Every app has a port of its own. The bundle Inertia builds listens on the same port for every app. Cipi starts it so that it listens on a port kept for this app, on localhost, and tells the app where it is: several Laravel Go apps of one server can have SSR, and none is reachable from outside.
If the SSR process is down, pages are rendered in the browser instead, with no error.
Reverb#
Laravel Go has a Reverb WebSocket server in its binary. Cipi can run it beside the app, with the same command a Laravel app uses:
sudo cipi app reverb enable blog sudo cipi deploy blog sudo cipi app reverb status blog sudo cipi app reverb disable blog
Every Laravel Go binary has the command: there is nothing to add to the build. Nginx sends /app and /apps of the app's domain to it, WebSocket upgrades included.
Status, restart, logs#
sudo cipi node status blog # the two slots, the worker, SSR, Reverb sudo cipi node restart blog # zero-downtime restart sudo cipi app logs blog --type=go # what the process printed, and storage/logs
A Laravel Go app shares the blue/green machinery of Node server apps, which is why these commands start with node.
The toolchain#
One Go for the server, in /opt/cipi/go: the latest stable release from go.dev, checked against the checksum go.dev publishes for it. Apps build with it as their own user; none can change it.
sudo cipi go status # the server's Go, and the Go each app was built with sudo cipi go update # the latest stable sudo cipi go clean blog # remove one app's module cache and build cache sudo cipi go remove # only when no app uses it
After an update the apps keep running the binary they have. Each is rebuilt by its next deploy.
A Go of the app's own#
A go.mod that asks for a newer Go than the server's, or names a toolchain, is followed. The go command downloads that toolchain itself, verified against Go's checksum database, into the cache of that app: no other app sees it, and nothing is installed for the server.
// go.mod
go 1.27
toolchain go1.27.2sudo cipi go status says which Go each app's binary was built with.
Limits#
| Reverb | The binary's own server: a single process, with connections kept in memory. Every deploy and every restart drops the open connections; Laravel Echo reconnects |
| Build elsewhere | Not with this type: the build is part of the deploy |
| Server sync | Laravel Go apps are moved like the others. On the new server Reverb is turned on again by hand, and the first deploy compiles from the start |
Common problems#
| Problem | Fix |
|---|---|
| The deploy ends at not a valid object name: main | The repository has no main: Laravel's skeleton has 0.x alone. sudo cipi app edit blog --branch=0.x, then deploy. An app created without --branch takes the repository's default by itself |
502 Bad Gateway right after creating the app | No release yet: the first successful deploy starts the app. After that, sudo cipi node status blog shows the two slots |
The deploy stops at go:driver | The app's database has no driver in the binary, and Cipi could not add it to the build: the message says why. Add the two lines it names to bootstrap/app.go, run go mod tidy, commit |
| missing go.sum entry | go.sum is not committed, or is behind go.mod: go mod tidy, commit both |
| The main package of this app is … and the repository has no such directory | --go-main names a directory the repository does not have: sudo cipi app edit blog --go-main=<directory> |
| go.mod not found in the repository root | Not a Go module: the repository of a Laravel Go app has its go.mod in the root |
Permission denied (publickey) while cloning | The repository does not have the app's deploy key: sudo cipi deploy blog --key shows it, to add as a read-only deploy key. A public repository needs none when given by its https:// address |
URLs start with http:// | m.Proxies = []string{"127.0.0.1"} is missing in bootstrap/app.go |
| Pages are not rendered on the server | SSR needs --ssr=on and a build that writes bootstrap/ssr/app.js: sudo cipi node status blog shows the ssr program |
| The deploy times out during the first build | sudo cipi app deploy-config blog --build-timeout=3600, and deploy again: what was compiled is kept |
Questions#
| Question | Answer |
|---|---|
| Do I need PHP for a Go app? | Not for the app. Cipi's deploy tool and the webhook receiver run on PHP, so the server keeps it. |
| Can it share a server with PHP apps? | Yes: it is one more isolated app, with its own Linux user and its own two ports on localhost. |
| Which Go builds it? | The server's, unless go.mod asks for a newer one: the toolchain. |
| Where are the static files served from? | By the app itself, from public/ of the release. Nginx proxies every request to it. |
| Laravel Rust or Laravel Go? | Both are deployed the same way: built at every deploy, switched blue/green. Laravel Rust apps. |