Drupal 9, 10, 11 Cloudways deployment

Having become a little disillusioned with Acquia’s high cost and debatable quality of service, I’ve been looking into alternatives for deploying Drupal sites that aren’t huge enough to warrant Acquia’s infrastructure and need a bit more flexibility in the services they use (more than just Solr with no admin interface).

So currently I’m trying out Cloudways and I thought I’d document it a little bit as I go because, although their documentation is okay, it hasn’t been plain sailing.

Teams

Firstly, if you’re setting up a team do not let the team members set up free trial accounts to play around. When you create a team, the team leader needs to set up an account and then add the team members’ emails to invite them. If they already have an account linked to that email address the Cloudways system will not allow the account and the suggestion in the interface to contact support just means that someone in support will tell you this. And you can’t destroy the team members accounts to get around this – believe me I’ve tried.

Github repo

Cloudways allows you to set up a Git repo for deployments – you can then click a button and it will deploy the code from the Git repo to your application. This is useful (nowhere near as comprehensive as Acquia’s deployment of course) but I kept getting an error message that said something like “Unfortunately, operation failed due to unexpected error.”

The ssh key worked as I’d used it on the command line to clone the repository on the server to get started with having a tinker. But this meant that the automation doesn’t work.

It turns out that when you add your repo URL as ‘git@github.com:<your account>/<your repo>.git‘ the system doesn’t cope with the ‘.git‘ at the end. Strip that off and it works. Remember that Github uses main instead of master now as the branch name.

Once this is sorted the instructions for setting up Drupal on Cloudways work fine.

Drush and PHP versions

There is an issue I’ve found with PHP versions where your site may be running on PHP 8.4 but the command line has PHP 8.2 installed. This means that when you run Drush you get output something like:

$ ddev drush @live cr
Composer detected issues in your platform:

Your Composer dependencies require a PHP version ">= 8.4.1". You are running 8.2.35.

PHP Fatal error:  Uncaught RuntimeException: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.4.1". You are running 8.2.35. in /home/1621587.cloudwaysapps.com/rumptytumpty/public_html/web/vendor/composer/platform_check.php:22

The way around this is somewhat hacky and I don’t like hacks because they become unexpected traps later. The way to do this is to create a symlink to the correct version of PHP in a local directory (for your user on the server) and get that in the path:

$ mkdir bin
$ cd bin
$ ln -s /usr/bin/php8.4 php

And then in your Drush alias file you can tweak the path environment variable so that it uses that version of PHP:

live:
  root: /home/1234567.cloudwaysapps.com/rumptytumpty/public_html/web
  uri: https://example.com
  host: 123.456.789.123
  user: master_jabberwocky
  env-vars:
    PATH: /home/master/bin:/usr/bin:/bin

Obviously the last two lines are the relevant ones here – the rest are what match your system.

Running Drush when you’re logged in is a bit more of a mess. I tend to set it up so that when you’re in the web directory of your Drupal install the command works by setting up an alias:

alias drush='env PATH=/home/master/bin:/usr/bin:/bin vendor/bin/drush'

And putting that in the .bash_aliases file (because .bashrc couldn’t be overwritten last time I tried).

These things are sent to test us it seems but things are running smoothly now.

0 Shares:
You May Also Like