Skip to content

Deploy WordPress from Git with Managed MySQL (Step-by-Step)

Run WordPress like a modern app: Git deploys, managed MySQL, automatic HTTPS, persistent uploads and a step-by-step migration of an existing WordPress site.

Published
Reading time
3 min
On this page

Key takeaways

  • WordPress runs like any PHP app: tuned PHP-FPM with opcache, managed MySQL or MariaDB, and automatic HTTPS.
  • Read database credentials from the environment in wp-config.php, and keep the code in Git so staging and rollbacks just work.
  • Uploads must live on persistent storage (Hobby and up) or in object storage: a redeploy replaces the container's files.

Classic WordPress hosting means FTP, a cPanel, and hoping nobody changed a plugin on the live site. You can run WordPress like a modern app instead: code in Git, a managed database, HTTPS by default and repeatable deploys.

How WordPress runs on DockHosting

  • Detection: a wp-config.php (or composer.json) marks the project as PHP.
  • Runtime: production PHP-FPM with opcache and tuned FPM workers. Common extensions (gd, curl, mbstring, pdo, redis) are preinstalled.
  • Database: managed MySQL or MariaDB on a private network.
  • HTTPS: automatic on your .dockhosting.cloud subdomain and on custom domains.
  • Pricing: flat, with no visitor or bandwidth metering.

1. Put the site in Git

Commit WordPress core (or install it with Composer), your theme and your plugins. Don't commit wp-content/uploads or secrets:

text
# .gitignore
wp-content/uploads/
.env

2. Read credentials from the environment

Attach a managed MySQL database to the project. Its connection details are injected into the environment, so wp-config.php reads them instead of hard-coding them:

php
// wp-config.php
$db = parse_url(getenv('DATABASE_URL'));
 
define('DB_NAME', ltrim($db['path'], '/'));
define('DB_USER', $db['user']);
define('DB_PASSWORD', $db['pass']);
define('DB_HOST', $db['host'] . (isset($db['port']) ? ':' . $db['port'] : ''));
 
// Generate these once at https://api.wordpress.org/secret-key/1.1/salt/ and store them as variables.
define('AUTH_KEY', getenv('AUTH_KEY'));
// … SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY and the four salts the same way
 
// Behind the platform's HTTPS proxy:
if (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https') {
    $_SERVER['HTTPS'] = 'on';
}

3. Deploy

bash
curl -fsSL https://cli.dockhosting.dev/install.sh | sh   # Windows: irm https://cli.dockhosting.dev/install.ps1 | iex
dock login
dock deploy

Open https://<project>.dockhosting.cloud and run the WordPress installer, or import your existing database first (step 5).

4. Uploads need persistent storage

Each deploy starts a fresh container, so files written to its disk don't survive a redeploy. Media uploads need somewhere permanent:

  • Persistent storage on paid plans (1 GB on Hobby, 5 GB on Pro, 20 GB on Team) for wp-content/uploads, or
  • Object storage through an offload plugin, for large media libraries.

The Free plan is great for trying things out, but use Hobby or above for a site where people upload images.

5. Migrate an existing site

  1. Export the database: mysqldump -u USER -p DBNAME > site.sql (or use a backup plugin).
  2. Import it into the managed database. Public database access for desktop tools is available on Hobby and up.
  3. Copy uploads into persistent storage.
  4. Deploy the Git repository.
  5. Fix URLs if the domain changed: wp search-replace 'https://old.com' 'https://new.com' with WP-CLI.
  6. Add your custom domain and switch DNS when everything checks out. The certificate is issued automatically.

Performance basics

  • opcache is already on, so PHP code is compiled once.
  • Add Redis as an object cache (the redis extension is preinstalled). Attach managed Redis and point your cache plugin at REDIS_URL.
  • Keep plugins lean. Each one runs on every request.

Daily database backups are included on paid plans (kept 3, 7 or 30 days). Running Laravel next to WordPress? See Laravel with queues and Redis.

Frequently asked questions

Can I host WordPress for free?

Yes, for trying it out. DockHosting's Free plan runs a real WordPress site with a managed MySQL database on a free .dockhosting.cloud subdomain. It sleeps when idle, and media uploads aren't persistent, so for a live site use Hobby ($4/month): always on, your own domain, 1 GB persistent storage and daily database backups.

Does it work with plugins and themes?

Yes. It's standard WordPress on PHP 8.1 to 8.3. Commit themes and plugins to the repository so every deploy is identical, rather than installing them from the admin screen.

How do I move an existing WordPress site?

Export the database (mysqldump or a plugin), import it into the managed MySQL database, commit wp-content to Git, deploy, then update the site URL if the domain changed. Cut DNS over when it works.

  • WordPress
  • PHP
  • MySQL
  • Hosting
  • Tutorial

Written by Doughmi ILYAS

Doughmi builds DockHosting, the developer-first platform behind dock deploy: the build system, the managed databases and the dashboard. On this blog: guides to shipping apps without running servers, written with the commands the platform actually ships.

Summarize with

Share

All posts

Create an account, run dock deploy, and get a live HTTPS URL in minutes.