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
- Install Drupal locally
- Deploy Drupal to fortrabbit ← you are here
- Database syncing
- Files syncing
Code, database and files
A Drupal site has three parts, and each one travels its own way:
| Part | What | How |
|---|---|---|
| Code | Drupal, modules, themes, config/sync | Git push |
| Database | Content, users, active configuration | frbit db |
| Files | Uploads in web/sites/default/files | frbit 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:
- the root path
web composer install --no-devas the build commanddrush deployas the post-deploy commandweb/sites/default/filesas an exclude pattern, so uploads survive deployments- the
DB_*ENV vars from the MySQL component and a randomDRUPAL_HASH_SALT, read by the settings.php block
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}}
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
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
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
Logs
Drupal keeps its own log at /admin/reports/dblog. PHP errors show up in the logs of the dashboard.