Deploy Drupal to fortrabbit

Published

Reviewed

Create a Drupal app on fortrabbit and deploy it with Git. The Drupal software template sets the root path, the build command, the ENV vars and drush deploy.

Install and deploy run down

  1. Install Drupal locally
  2. Deploy Drupal to fortrabbit ← you are here
  3. Database syncing
  4. Files syncing

Code, database and files

A Drupal site has three parts, and each one travels its own way:

PartWhatHow
CodeDrupal, modules, themes, config/syncGit push
DatabaseContent, users, active configurationfrbit db
FilesUploads in web/sites/default/filesfrbit files

Code goes up with every push. Database and files go up once to bring the site live, then mostly down, to work locally with live content.

Create the app

Create an app with Drupal as the software and connect the GitHub repository. The software template then sets:

With General PHP or another software, these ENV vars are missing and Drupal finds no database.

First deployment

Connecting the repository deploys the code. The site does not run yet: the database is empty. Push the local database and files up, as in database up and files up:

ddev export-db --file=local.sql.gz
frbit db push local.sql.gz {{app-env-id}}
frbit files push web/sites/default/files -e {{app-env-id}}
shell

Or install a fresh site over SSH with frbit ssh {{app-env-id}} -- vendor/bin/drush site:install.

Drush deploy

Every deployment runs drush deploy as its post-deploy command. It applies pending database updates of core and modules, imports the configuration from config/sync, rebuilds the caches and runs deploy hooks. The template skips it while Drush is missing or no site is installed yet, so the first deployment of a fresh environment passes:

if vendor/bin/drush status --field=bootstrap 2>/dev/null | grep -q Successful; then vendor/bin/drush deploy; else echo 'No drush or no installed Drupal site, skipping drush deploy'; fi
shell

Drush has to be in require of composer.json: the build skips require-dev. Drupal CMS ships Drush as a dev dependency, composer require drush/drush moves it.

A configuration change follows the Drupal way: change it locally, export, commit, push. The next deployment imports it.

ddev drush config:export -y
git add config/sync
git commit -m "Update config"
git push
shell

drush deploy refuses an empty sync folder, and the deployment fails. Export and commit the configuration before the first deployment that runs it.

Drush over SSH

Run Drush on the environment with frbit ssh, or over plain SSH:

frbit ssh {{app-env-id}} -- vendor/bin/drush status
shell

Logs

Drupal keeps its own log at /admin/reports/dblog. PHP errors show up in the logs of the dashboard.

Written by AI, lectured by a human.

AI use & editorial processEdit on GitHub ↗