Skip to main content
Blog

Deploying Drupal to Cloudways with Git and GitHub Actions

A complete, copy-and-paste GitHub Actions workflow that deploys a Composer-based Drupal site to Cloudways on every push: build, upload, database backup and drush deploy.

By Jakub Mlynarczyk ·

Cloudways is a popular, reasonably priced way to host Drupal. It runs your site on a managed server from DigitalOcean, Vultr, AWS or Google Cloud, without you having to look after the server. What it doesn't give you is a proper Drupal deployment pipeline.

Its built-in Deployment via Git feature does a git pull into your application folder, and that's all it does. A modern Drupal site also needs composer install, database updates, a config import and a cache rebuild after the code changes. Run those by hand over SSH and, sooner or later, someone forgets one.

This guide sets up a workflow where a push to main deploys the site with no manual steps:

  1. GitHub Actions checks out the code and runs composer install.
  2. It takes a database backup on the server.
  3. It uploads the built code to Cloudways with rsync.
  4. It runs drush deploy.

The full deploy.yml is further down.

Why build in GitHub Actions instead of on the server?

The common alternative is to SSH in, git pull, then run composer install on the server. That works, but building in CI has some real advantages:

  • The server never needs access to your Git repository. You don't need deploy keys on the server, and nothing breaks when a token expires.
  • Composer runs in CI, not on a small server with a PHP memory limit, which is where composer install likes to fail.
  • If the build fails, nothing reaches production. A broken dependency stops the workflow before any files are copied.

What you need

  • A Composer-based Drupal site (the standard drupal/recommended-project layout, with the web root in web/), with drush/drush in composer.json.
  • Config exported to Git, for example in config/sync.
  • A Cloudways server with a PHP application, set to the PHP version your site needs: 8.3 or newer for Drupal 11.
  • SSH access to the Cloudways server.

Step 1: Point the Cloudways web root at web/

Cloudways serves each application from public_html. A Composer-based Drupal site keeps vendor/, config/ and composer.json above the public web root, and that is exactly where they should stay.

In the Cloudways dashboard, go to Application Settings → General and set the Webroot to public_html/web. After that, the whole project lives in public_html, but only public_html/web is reachable from the internet.

Step 2: Keep secrets out of Git

Database credentials and the hash salt must never be committed. The pattern I use: commit settings.php with everything that's the same on every environment, and have it include a server-only file:

// web/sites/default/settings.php (committed)
$settings['config_sync_directory'] = '../config/sync';

if (file_exists($app_root . '/' . $site_path . '/settings.cloudways.php')) {
  include $app_root . '/' . $site_path . '/settings.cloudways.php';
}

Then create web/sites/default/settings.cloudways.php on the server only, using the database details from Application Management → Access Details:

<?php
$databases['default']['default'] = [
  'database' => 'your_db_name',
  'username' => 'your_db_user',
  'password' => 'your_db_password',
  'host' => 'localhost',
  'port' => '3306',
  'driver' => 'mysql',
  'prefix' => '',
];
$settings['hash_salt'] = 'a-long-random-string';
$settings['trusted_host_patterns'] = ['^www\.example\.co\.uk$', '^example\.co\.uk$'];

Add both the server-only file and the uploaded files directory to .gitignore:

/web/sites/*/settings.cloudways.php
/web/sites/*/files/

Step 3: Create an SSH key for GitHub Actions

Generate a key pair just for deployments, with no passphrase:

ssh-keygen -t ed25519 -C "github-actions-deploy" -f cloudways_deploy -N ""

In Cloudways, open Server Management → Master Credentials → SSH Public Keys and add the contents of cloudways_deploy.pub.

Next, record the server's host key, so GitHub Actions can verify that it's really talking to your server:

ssh-keyscan -H YOUR_SERVER_IP

Don't skip this and use StrictHostKeyChecking=no instead. That turns off the check that protects your deploy key from a man-in-the-middle attack.

Step 4: Add GitHub secrets

In your repository, go to Settings → Environments, create an environment called production, and add these secrets:

SecretValue
CLOUDWAYS_HOSTYour server's public IP
CLOUDWAYS_USERThe master SSH username
CLOUDWAYS_PATH/home/master/applications/APP_FOLDER/public_html
CLOUDWAYS_SSH_KEYThe contents of the private key file cloudways_deploy
CLOUDWAYS_KNOWN_HOSTSThe output of ssh-keyscan

APP_FOLDER is a random-looking name that Cloudways gives each application, not your domain. You'll find it in the application's details in the dashboard, or by running ls /home/master/applications/ over SSH.

Using an environment, rather than plain repository secrets, also lets you add protection rules, such as requiring an approval before production deploys.

Step 5: Add the workflow

Save this as .github/workflows/deploy.yml:

name: Deploy to Cloudways

on:
  push:
    branches: [main]
  workflow_dispatch: # allows a manual "Run workflow" button

# Never run two deployments at the same time
concurrency:
  group: deploy-production
  cancel-in-progress: false

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    env:
      HOST: ${{ secrets.CLOUDWAYS_HOST }}
      USER: ${{ secrets.CLOUDWAYS_USER }}
      APP_PATH: ${{ secrets.CLOUDWAYS_PATH }}

    steps:
      - name: Check out code
        uses: actions/checkout@v4

      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3' # match your Cloudways server
          tools: composer:v2

      - name: Install Composer dependencies
        run: composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader

      - name: Set up SSH
        run: |
          mkdir -p ~/.ssh
          printf '%s\n' "${{ secrets.CLOUDWAYS_SSH_KEY }}" > ~/.ssh/id_ed25519
          printf '%s\n' "${{ secrets.CLOUDWAYS_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
          chmod 600 ~/.ssh/id_ed25519 ~/.ssh/known_hosts

      - name: Back up the database
        run: |
          STAMP=$(date -u +%Y%m%d-%H%M%S)
          # Skipped on the very first deploy, before Drush exists on the server
          ssh "$USER@$HOST" "cd $APP_PATH && if [ -x vendor/bin/drush ]; then \
            mkdir -p ../private_html/backups && \
            vendor/bin/drush sql:dump --gzip \
              --result-file=$APP_PATH/../private_html/backups/pre-deploy-$STAMP.sql; fi"

      - name: Upload code
        run: |
          rsync -az --delete \
            --exclude='.git/' \
            --exclude='.github/' \
            --exclude='.ddev/' \
            --exclude='web/sites/*/files/' \
            --exclude='web/sites/*/settings.cloudways.php' \
            ./ "$USER@$HOST:$APP_PATH/"

      - name: Run drush deploy
        run: ssh "$USER@$HOST" "cd $APP_PATH && vendor/bin/drush deploy -y"

What each step does

  • concurrency stops two pushes in quick succession from deploying on top of each other. The second one waits.
  • composer install --no-dev leaves development tools out of production, and --optimize-autoloader makes the class loader a little faster.
  • The backup step runs before any code changes, using the Drush already on the server. The dumps go into private_html, which Cloudways keeps outside the web root, so they can't be downloaded. On the very first deploy there's no Drush on the server yet, so the step skips itself.
  • rsync --delete makes the server match the repository exactly, so files you deleted in Git are deleted on the server too. The --exclude rules also protect paths from deletion, which is why the uploaded files directory and your server-only settings file survive every deploy.
  • drush deploy runs, in the right order: database updates (updatedb), a cache rebuild, the config import (config:import) and any hook_deploy_NAME() functions. That's the standard Drupal deployment sequence in one command.

Step 6: Test it

Before you point it at a live site:

  1. Back up the application in the Cloudways dashboard.
  2. Make sure public_html contains only what you expect. On the first run, rsync --delete removes anything that isn't in your repository or excluded.
  3. Run the workflow manually from the Actions tab, using the workflow_dispatch button, and watch the logs.
  4. Visit the site, log in, and check Reports → Recent log messages.

Common problems on Cloudways

Permission errors after deploying. Files uploaded by the master user can end up owned differently from files the application writes itself. If Drupal can't write to sites/default/files, use Application Settings → Reset Permission in the dashboard.

Changes not showing for logged-out visitors. Cloudways puts Varnish in front of your site. drush deploy clears Drupal's caches but not Varnish, so purge it from the dashboard after a deploy that changes the front end. You can also add the Purge module with a Varnish purger to do it automatically.

drush: command not found. Always call vendor/bin/drush from the project root, as the workflow does. Don't rely on a global Drush on the server.

Composer platform mismatch. If CI runs a newer PHP than the server, Composer can install packages the server can't run. Pin the server's version in composer.json:

"config": {
  "platform": { "php": "8.3" }
}

Where to go from here

The same workflow works for a staging site. Copy the job, trigger it on a develop branch, and point it at a second Cloudways application with its own staging environment secrets.

You can also add a test job before deploy, running PHPUnit or end-to-end tests with Playwright, and make deploy depend on it with needs: test. Then a push that breaks your contact form never reaches production.

Need a hand setting up deployments for your Drupal site, or for your agency's clients? Get in touch. It's the kind of work I do for agencies regularly.

Ready for a website that pays its way?

Tell me about your business and where you want it to go. You’ll get honest, practical advice within one working day, with no obligation.

Book a free consultation