Skip to content

Instantly share code, notes, and snippets.

@kerasai
Last active May 3, 2024 15:59
Show Gist options
  • Save kerasai/ec133fbc03b8318ad7d37fd9ce4155bc to your computer and use it in GitHub Desktop.
Save kerasai/ec133fbc03b8318ad7d37fd9ce4155bc to your computer and use it in GitHub Desktop.
Drupal Project Setup

Drupal Project Setup

Drupal poject setup steps, for use in Lando environment.

Lando setup

  1. lando init
  2. Copy, adjust pertinent sections from provided .lando.yml
  3. lando start

Drupal/Composer

lando composer create-project drupal/recommended-project my_site
cp -r my_site/. .
rm -rf my_site

Add a few things we know we'll want.

lando composer config --no-plugins allow-plugins.cweagans/composer-patches true

lando composer require -n cweagans/composer-patches \
  drupal/admin_toolbar \
  drupal/config_split \
  drupal/devel \
  drupal/devel_php \
  drupal/environment_indicator \
  drupal/module_filter \
  drush/drush \
  wikimedia/composer-merge-plugin

Configure Composer merge plugin in composer.json.

{
    "extra": {
        "merge-plugin": {
            "include": [
                "web/modules/custom/*/composer.json",
                "web/modules/custom/*/modules/*/composer.json",
                "web/themes/custom/*/composer.json"
            ]
        }
    }
}

Add the .gitignore file to the root of the project.

Environment detection

  1. lando composer require kerasai/lamp-env:^1@alpha
  2. Add PSR-4 loading to composer.json
  3. Add env detection class to project
  1. Setup Drupal settings files
  • settings.php
    • From kerasai/lamp-env
  • settings.default.php
  • settings.dev.php
    • And develop.services.yml
  • settings.lando.php

Add to the settings files as needed when you build-out the site.

Locally you can override as needed using settings.local.php. It's a good idea to throw in an settings.local.php file as well, with example code that can be copy/paste-d to the local settings file.

Initial Drupal installation

Install the site, enable some dev utilities, remove some extra "cruft" we can do without.

lando drush si -y standard
lando drush en -y admin_toolbar admin_toolbar_tools config_split devel devel_php environment_indicator module_filter
lando drush edel shortcut
lando drush pm:uninstall announcements_feed contact search shortcut tour

Set up the dev split:

  1. mkdir -p web/config/split/dev
  2. Set up the split in the UI
  • Machine name: dev
  • Folder ../config/split/dev
  • Active: No (will be overridden by settings files)
  • Complete split of devel and devel_php

Export config with lando drush cex -y. You should see the config/sync directory filled with the site's config (minus the dev modules), and config/split/dev will contain the dev modules' config.

Edit config/sync/core.extension.yml, replace standard with minimal. This is necessary because the standard install profile does some setup in its hook_install and it cannot install from config.

From here you will be able to install/reinstall the site as needed using lando drush si -y --existing-config.

# Ignore directories generated by Composer
/drush/contrib/
/vendor/
/web/core/
/web/modules/contrib/
/web/themes/contrib/
/web/profiles/contrib/
/web/libraries/
# Ignore sensitive information
/web/sites/*/settings.local.php
# Ignore Drupal's file directory
/web/sites/*/files/
# Ignore SimpleTest multi-site environment.
/web/sites/simpletest
# Ignore files generated by PhpStorm
/.idea/
# Ignore .env files as they are personal
/.env
.lando.env
.lando.local.yml
# Packages
*.7z
*.dmg
*.gz
*.bz2
*.iso
*.jar
*.rar
*.tar
*.zip
*.tgz
# Logs and databases
*.log
*.sql
# OS generated files
.DS_Store*
ehthumbs.db
Thumbs.db
._*
name: __mysite__
recipe: drupal10
config:
webroot: web
env_file:
- .lando.env
services:
appserver:
overrides:
environment:
DRUSH_OPTIONS_URI: "https://__mysite__.lndo.site"
mailhog:
type: mailhog
portforward: true
hogfrom:
- appserver
pma:
type: phpmyadmin
hosts:
- database
proxy:
pma:
- db.__mysite__.lndo.site
mailhog:
- mail.__mysite__.lndo.site
parameters:
http.response.debug_cacheability_headers: true
twig.config:
debug: true
auto_reload: true
services:
cache.backend.null:
class: Drupal\Core\Cache\NullBackendFactory
<?php
// Default configuration and settings.
$databases = [];
$config_directories = [];
$settings['hash_salt'] = '__set_random_salt__';
$settings['config_sync_directory'] = '../config/sync';
$settings['update_free_access'] = FALSE;
$settings['file_scan_ignore_directories'] = [
'node_modules',
'bower_components',
];
$settings['entity_update_batch_size'] = 50;
$settings['entity_update_backup'] = TRUE;
$settings['migrate_node_migrate_type_classic'] = FALSE;
$config['system.performance']['css']['preprocess'] = TRUE;
$config['system.performance']['js']['preprocess'] = TRUE;
$settings['file_public_path'] = 'sites/default/files';
$settings['file_private_path'] = 'sites/default/files/private';
$config['config_split.config_split.dev']['status'] = FALSE;
$config['environment_indicator.indicator']['bg_color'] = '#CC0000';
$config['environment_indicator.indicator']['fg_color'] = '#FFFFFF';
$config['environment_indicator.indicator']['name'] = 'Unknown';
<?php
// Development configuration and settings.
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/default/develop.services.yml';
$config['system.logging']['error_level'] = 'verbose';
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['discovery_migration'] = 'cache.backend.memory';
$settings['cache']['bins']['page'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
$settings['skip_permissions_hardening'] = TRUE;
$config['config_split.config_split.dev']['status'] = TRUE;
<?php
$databases['default']['default'] = [
'database' => 'drupal10',
'username' => 'drupal10',
'password' => 'drupal10',
'prefix' => '',
'host' => 'database',
'port' => '3306',
'isolation_level' => 'READ COMMITTED',
'namespace' => 'Drupal\\mysql\\Driver\\Database\\mysql',
'driver' => 'mysql',
'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/',
];
$config['environment_indicator.indicator']['name'] = 'Lando';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment