WordPress apps
WordPress from Git with zero-downtime releases: classic or Bedrock, shared uploads, WP-CLI.
A WordPress app deploys a WordPress kept in Git the way a Laravel app deploys: a new release beside the live one, one switch, rollback. The uploads and the configuration live outside the releases, so a deploy never touches them.
$ sudo cipi app create --wordpress --user=blog --domain=blog.example.com --repository=git@github.com:acme/blog.git
WordPress app or custom app?#
WordPress app (--wordpress) | Custom app (--custom) | |
|---|---|---|
| The code | In Git: core, themes and plugins, committed or required with Composer | Uploaded over SFTP, or pulled into ~/htdocs |
| Deploy | Zero-downtime releases with rollback | In place |
| Plugins and updates | In Git, then a deploy. wp-admin does not install or update | From wp-admin, as usual |
Database, salts, wp-config.php | Created and written for you | A database on request; the configuration is yours |
| For | Sites built by developers, with a repository and reviews | A WordPress run from its dashboard |
Both are fine. A site whose plugins are installed from wp-admin is a custom app: a release is replaced whole at the next deploy, and what the dashboard added would be gone with it.
Create one#
# WordPress at the root of the repository sudo cipi app create --wordpress --user=blog --domain=blog.example.com \ --repository=git@github.com:you/blog.git # Bedrock (roots.io): served from web/, WordPress in web/wp sudo cipi app create --wordpress --user=shop --domain=shop.example.com \ --repository=git@github.com:you/shop.git --docroot=web # A theme built with Vite, on PHP 8.4 sudo cipi app create --wordpress --user=mag --domain=mag.example.com \ --repository=git@github.com:you/mag.git --php=8.4 \ --node-build='npm ci && npm run build'
| Flag | Meaning | Default |
|---|---|---|
--wordpress | The app type. Also --framework=wordpress, or WordPress in the wizard | |
--repository | Git URL over SSH. Required | asked |
--docroot=web | A Bedrock project | the repository's root |
--db=NAME | The database's name. --no-db makes none | the app's name |
--node-build | Asset build run in every deploy | none |
--php, --branch, --env | As for every app |
The database is on MySQL or MariaDB, the engines WordPress runs on: --engine=pgsql is refused.
What the repository holds#
| Layout | In Git | Not in Git |
|---|---|---|
| Classic | WordPress itself (index.php, wp-settings.php, wp-admin/, wp-includes/), wp-content/themes, wp-content/plugins | wp-config.php, wp-content/uploads |
| Bedrock | composer.json and composer.lock, config/, web/app/themes, your own plugins | .env, web/wp and the plugins Composer installs, web/app/uploads |
A wp-config.php committed to a classic repository is harmless: Cipi's own takes its place in every release. A composer.json at the root is installed on every deploy, so plugins from wpackagist work in a classic layout too.
Before a release goes live, the deploy checks that it has a WordPress to serve (index.php and wp-settings.php). A repository that holds only a theme stops there, with the site as it was.
Where things live#
/home/blog/ ├── current -> releases/12 # what Nginx serves ├── releases/11/ 12/ # one folder per deploy └── shared/ ├── .env # database, salts, WP_HOME… ├── wp-config.php # reads that .env (classic layout) └── wp-content/uploads/ # the media library
Each release gets links to the three shared entries. Bedrock shares .env and web/app/uploads and reads the .env itself.
Configuration#
Everything WordPress is told lives in ~/shared/.env. Cipi writes it when the app is created, so the first deploy shows WordPress's own installer with nothing left to configure. Change it with sudo cipi app env blog or from the panel's editor; it applies to the next request.
| Variable | Value |
|---|---|
DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, DB_PREFIX | The database made with the app |
AUTH_KEY … NONCE_SALT | The eight keys and salts, generated |
WP_HOME, WP_SITEURL | https:// and the app's domain (/wp added for Bedrock). They follow sudo cipi app edit blog --domain=… |
WP_ENVIRONMENT_TYPE | From --env: production, staging, development or local |
DISALLOW_FILE_MODS, AUTOMATIC_UPDATER_DISABLED | true: the code comes from Git |
DISABLE_WP_CRON | true: cron runs from the crontab |
WP_DEBUG, WP_DEBUG_LOG, WP_DEBUG_DISPLAY | false: errors are neither shown to visitors nor written to debug.log. To look into a problem set the first two to true and leave WP_DEBUG_DISPLAY off |
CIPI_APP_USER, CIPI_ENV, CIPI_PHP_VERSION, CIPI_DEPLOY_BRANCH | What Cipi knows about the app, for your own code |
WP_MEMORY_LIMIT, FORCE_SSL_ADMIN, WP_CACHE | Yours to set |
Constants that are not in the list go between the two comments at the end of ~/shared/wp-config.php (Add any custom values…).
With DISALLOW_FILE_MODS=true, wp-admin hides the plugin and theme installers and the update buttons. That is the point: add a plugin to the repository (or to composer.json) and deploy.
Deploy#
sudo cipi deploy blog sudo cipi deploy blog --rollback
The commit of the branch, in a folder of its own. The live release is not touched.
wp-config.php (or Bedrock's .env) and the uploads folder are linked in.
composer install --no-dev. Nothing for a WordPress committed whole.
The build command of the app, if it has one.
A release without a WordPress to serve stops here.
One step. A request is answered by the old release or by the new one, never by half of each.
Pushes deploy by themselves: the webhook is Cipi's own, with nothing to install in WordPress (auto-deploy). Keep releases, the build's time limit and the database snapshot before a deploy are in sudo cipi app deploy-config blog.
A rollback moves the code back. The database is not part of a release: for a deploy that changes it, turn on the snapshot before deploy.
WP-CLI#
sudo cipi package install wp-cli sudo su - blog wp plugin list wp search-replace 'http://old.example.com' 'https://blog.example.com' --dry-run
$ sudo cipi package install wp-cli $ sudo su - blog $ wp option get siteurl $ wp --info | grep 'PHP binary' $ wp cache flush
As the app's user, wp works on the live release from any folder, on the PHP version the app runs on. After a deploy it is on the new release.
Cron#
WordPress's scheduled events run every minute from the app's crontab (wp-cron.php, on the app's PHP), not when a visitor happens to load a page. Scheduled posts go out on time on a site with no traffic.
Caching#
| Layer | Command |
|---|---|
| Pages, for anonymous visitors | sudo cipi cache blog on |
| Objects, in a Valkey of the app's own | sudo cipi cache blog object on writes the WP_REDIS_* lines into ~/shared/wp-config.php (classic layout). On Bedrock, add them to config/application.php |
Step by step: caching WordPress with Cipi.
What Nginx does#
| Permalinks | Every path that is not a file goes to index.php |
| Uploads | No PHP runs from the uploads folder, classic or Bedrock |
robots.txt | WordPress's own answer when the repository has no file |
| During a deploy | The path of the release is resolved per request ($realpath_root), so OPcache never mixes two releases |
Common problems#
| Problem | Fix |
|---|---|
| The deploy stops at wp-settings.php not found | The repository has no WordPress core. Commit it, or require it with Composer (Bedrock does) |
| Error establishing a database connection | Check DB_* in sudo cipi app env blog. A new password: sudo cipi db password blog, then put it in the .env |
| A plugin installed from wp-admin is missing | It was added to a release that is gone. Add it to the repository and deploy |
| Images are missing after moving the site | Copy the old wp-content/uploads into ~/shared/wp-content/uploads (as the app's user) |
| Redirect loop behind Cloudflare | Use Full (strict) on Cloudflare and install a certificate on the app: the guide |
Questions#
| Question | Answer |
|---|---|
| Can I update WordPress from the dashboard? | Not in this app type: updates come from Git. For a WordPress run from its dashboard, create a custom app. |
| Does it work with WooCommerce? | Yes. Orders are in the database and uploads in shared/: neither is touched by a deploy. See WooCommerce on a VPS. |
| Multisite? | Yes: add the MULTISITE constants to ~/shared/wp-config.php, and for subdomains a wildcard alias. |
| How do I move an existing site in? | Put its code in a repository, create the app, import the database (wp db import) and copy the uploads into shared/. The guide walks through it. |
| Is it backed up? | shared/ (uploads, .env) and the database are in backups. The code comes back from Git. |
| Can a custom app become a WordPress app? | Not by a switch. Create the new app next to it and move the database and the uploads; the guide above has the steps. |