Drupal guide
Published
Updated
Run Drupal 11 on fortrabbit with Composer and Git deployment. The Drupal software template sets the root path web, the database ENV vars and a hash salt, keeps uploaded files across deployments, and runs drush deploy.
Get ready
Create an app with Drupal as the software, so the software template applies. The template covers Drupal 11; Drupal 10 gets the platform defaults and needs the settings below by hand. Install Drupal in a local development environment first, see the Drupal installation guide:
# Create a new Drupal project with Composer
composer create-project drupal/recommended-project my-drupal-site
# Navigate to the project directory
cd my-drupal-site
DDEV has a Drupal quickstart.
Root path
The template sets the root path to web.
Deployment
Drupal deploys with Composer and Git through the GitHub App. The build commands run composer install.
Git ignores
drupal/recommended-project ships no .gitignore. Create one in the project root that keeps out at least vendor, web/core, web/modules/contrib and web/sites/*/files:
- drupal.org/project/drupal_cms/issues/3500134 - Issue
- github.com/github/gitignore/blob/main/Drupal.gitignore - Example
First deployment
- Commit the local project and push it to GitHub.
- Connect the repository to the app; the push deploys.
- Install Drupal over SSH with
vendor/bin/drush site:install, or import an existing database. - Export the configuration and commit it, see Drush.
Drush
Drush is the Drupal command line tool. Require it with Composer, so it ships with every deployment:
composer require drush/drush
Call it directly via SSH, not through the PHP interpreter: vendor/bin/drush is a shell script.
ssh {{app-env-id}}@ssh.{{region}}.frbit.app
vendor/bin/drush status
Drush deploy
drush deploy runs database updates, imports the configuration and rebuilds caches. The Drupal software template sets it as a post deploy command. It is skipped while Drush is missing or the site is not installed yet, so the first deployment of a fresh environment does not fail:
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 deploy imports the configuration from the sync directory. It refuses an empty sync directory, and the deployment fails. Export the configuration locally and commit it:
vendor/bin/drush config:export
git add config/sync
Files and uploads
Drupal stores uploads in web/sites/default/files. The template excludes that folder from deployments, so uploads persist.
Using rsync for file management
Sync the files with rsync:
# Download files from fortrabbit to local
rsync -av {{app-env-id}}@ssh.{{region}}.frbit.app:web/sites/default/files/ ./web/sites/default/files/
# Upload files from local to fortrabbit
rsync -av ./web/sites/default/files/ {{app-env-id}}@ssh.{{region}}.frbit.app:web/sites/default/files/
Logs
Drupal keeps its own log at /admin/reports/dblog. PHP errors show up in the logs of the dashboard.
Database and ENV vars
The template sets the DB_* variables from the MySQL component and a random DRUPAL_HASH_SALT. Drupal reads its database connection from web/sites/default/settings.php, so read the variables there:
if (getenv('DB_HOST')) {
$databases['default']['default'] = [
'driver' => 'mysql',
'database' => getenv('DB_DATABASE'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'host' => getenv('DB_HOST'),
'port' => getenv('DB_PORT') ?: '3306',
'prefix' => '',
'collation' => 'utf8mb4_general_ci',
];
$settings['hash_salt'] = getenv('DRUPAL_HASH_SALT');
$settings['config_sync_directory'] = '../config/sync';
}
Keep the local credentials in a settings.local.php.