Setting Up a Drupal local development environment

When first setting up drupal, generally it will be for a local development environment. We can activate the "dev" environment quickly by setting up these features.

1. Copy  sites/example.settings.local.php to sites/default/settings.local.php.

cp web/sites/example.settings.local.php web/sites/default/settings.local.php

2. Edit settings.php to include the settings.local.php file. for this, remove the comments from the lines near the bottom of the file

# if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
#   include $app_root . '/' . $site_path . '/settings.local.php';
# }

to

if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
  include $app_root . '/' . $site_path . '/settings.local.php';
}

Since the database will be specific to our local machine, remove the database configuration and move it to the top of the new local settings file. This section:

$databases['default']['default'] = array (
  'database' => 'MY_DEV_DATABASE',
  'username' => 'MY_DB_USER',
  'password' => 'MY_DB_PASSWORD',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

The same goes for the config_sync_directory information. We can move this to our local settings file and update the path while we're at it. The line looks like this:

$settings['config_sync_directory'] = 'sites/default/files/config_TLrdardJJTr5aXpNMaERcyai9685LM_uyKBR7eTb7dJEP28S4UiPm9uj2LV5l7by870g_qQQmQ/sync';

Copy it, remove it from the settings.local.php file and place it at the top of the setting.local.php file after the opening <?php tag. The top of the file should look like this:

<?php
$databases['default']['default'] = array (
  'database' => 'MY_DEV_DATABASE',
  'username' => 'MY_DB_USER',
  'password' => 'MY_DB_PASSWORD',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

$settings['config_sync_directory'] = '../config/sync';

// @codingStandardsIgnoreFile

/**
 * @file
 * Drupal site-specific configuration file.
 *
 * IMPORTANT NOTE: etc… … …

Notice the path "config_sync_directory" path was updated to "../config/sync." This is the place, outside the web directory where the configuration files can be safely stored. Be sure to also create this folder, MY_SITE_ROOT/config/sync.

Add new comment

The content of this field is kept private and will not be shown publicly.
Enter a comment.