Skip to content
WordPress

Deploy a WordPress website

Deploy WordPress on Clever Cloud with a managed MySQL database and persistent media storage.

WordPress runs on Clever Cloud’s PHP runtime. This guide uses Git deployment so the WordPress core, themes and plugins are versioned with the application while a MySQL add-on stores content and an FS Bucket stores uploads.

This guide was tested with WordPress 7.1 and PHP 8.4. It also applies to newer compatible WordPress releases.

Prepare WordPress

Install Clever Tools, log in, download WordPress and initialize the repository:

npm i -g clever-tools
clever login

curl -LO https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
cd wordpress
git init

Copy the example configuration:

cp wp-config-sample.php wp-config.php

In wp-config.php, replace the database definitions with the variables injected by the linked MySQL add-on:

wp-config.php
define('DB_NAME', getenv('MYSQL_ADDON_DB'));
define('DB_USER', getenv('MYSQL_ADDON_USER'));
define('DB_PASSWORD', getenv('MYSQL_ADDON_PASSWORD'));
define('DB_HOST', getenv('MYSQL_ADDON_HOST') . ':' . getenv('MYSQL_ADDON_PORT'));
define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', '');

Replace the eight authentication key and salt definitions with environment-backed values:

wp-config.php
define('AUTH_KEY',         getenv('WORDPRESS_AUTH_KEY'));
define('SECURE_AUTH_KEY',  getenv('WORDPRESS_SECURE_AUTH_KEY'));
define('LOGGED_IN_KEY',    getenv('WORDPRESS_LOGGED_IN_KEY'));
define('NONCE_KEY',        getenv('WORDPRESS_NONCE_KEY'));
define('AUTH_SALT',        getenv('WORDPRESS_AUTH_SALT'));
define('SECURE_AUTH_SALT', getenv('WORDPRESS_SECURE_AUTH_SALT'));
define('LOGGED_IN_SALT',   getenv('WORDPRESS_LOGGED_IN_SALT'));
define('NONCE_SALT',       getenv('WORDPRESS_NONCE_SALT'));

Add the following before require_once ABSPATH . 'wp-settings.php'; so WordPress detects HTTPS through Clever Cloud’s reverse proxy:

wp-config.php
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && str_contains($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https')) {
    $_SERVER['HTTPS'] = 'on';
}

define('DISALLOW_FILE_MODS', true);

DISALLOW_FILE_MODS prevents changes from the administration interface that would disappear on the next deployment. Add or update WordPress core, themes and plugins in Git instead.

Create the application and services

Create a PHP application with an alias, then create and link MySQL:

clever create -t php -a myWordPress
clever addon create mysql-addon myWordPressDatabase -p xs_sml --link myWordPress

Clever Tools targets your personal organisation by default. To use another organisation, add --org ORGANISATION or -o ORGANISATION when you create or link a resource.

You can display your application’s URL or add a custom domain. A custom domain also requires DNS configuration:

clever domain
clever domain add your.website.tld

Select PHP 8.4 and generate independent authentication secrets:

clever env set CC_PHP_VERSION 8.4

for key in AUTH_KEY SECURE_AUTH_KEY LOGGED_IN_KEY NONCE_KEY AUTH_SALT SECURE_AUTH_SALT LOGGED_IN_SALT NONCE_SALT; do
  clever env set "WORDPRESS_${key}" "$(openssl rand -base64 48)"
done

Do not change these values after users have signed in, because doing so invalidates every active WordPress session.

Create and link an FS Bucket for media uploads, then mount it into the absent wp-content/uploads directory:

clever addon create fs-bucket myWordPressFiles --link myWordPress

FS_BUCKET_HOST="$(clever env -F json | jq -er 'first(.fromAddons[] | select(.addonName == "myWordPressFiles") | .env[] | select(.name == "BUCKET_HOST") | .value)')"
clever env set CC_FS_BUCKET "/wp-content/uploads:${FS_BUCKET_HOST}"
unset FS_BUCKET_HOST

The name lookup expects the add-on name to be unique. If several add-ons use that name, retrieve the host with clever addon env ADDON_ID -F json and the ID returned when the add-on was created. The mount target must not exist in the repository, so do not commit wp-content/uploads.

You can also create and link these resources from the Clever Cloud Console.

Deploy WordPress

Commit and deploy the application:

git add .
git commit -m "Deploy WordPress"

clever deploy
clever open

The first request opens the WordPress installation form. Choose the site title and administrator credentials to initialize the database. Once installation completes, uploaded media is stored in the FS Bucket and remains available across deployments.

Update WordPress and plugins

Apply updates locally, review them, commit the changed files and deploy again. Keeping code in Git makes deployments reproducible and prevents changes made on a replaced application instance from being lost.

If you use Composer to manage WordPress and plugins as immutable dependencies, see the Clever WordPress example.

Improve performance

Varnish is available on PHP applications for HTTP caching. Start from the WordPress VCL example and make cache exclusions match your site and plugins.

For object caching, link a Redis add-on and use a maintained WordPress Redis plugin configured with the injected REDIS_HOST, REDIS_PORT and REDIS_PASSWORD variables. Use a unique cache-key salt when several WordPress sites share the same Redis database.

Learn more

Last updated on