If you are starting development in Drupal then you can go with Ddev to configure a site on your local system. DDev is docker base tool which converts the docker's complex configurations into simple setup. Lets start
Requirements:
- Ubuntu/Mac/Windnow
- Docker is configured and working
- DDev is installed
Drupal Installation via Ddev:
Most of the below details copy from https://www.drupal.org/docs/official_docs/en/_local_development_guide.html and converted into steps
Step 1: export SITE_NAME=d9313
Step 2: mkdir $SITE_NAME
Step 3: cd $SITE_NAME
Step 4: ddev config --docroot web --project-name $SITE_NAME --project-type drupal9 --create-docroot
Step 5: ddev start
Note: Above command will download docker images on first run.
Step 6: ddev composer create "drupal/recommended-project"
Step 7: ddev composer require drush/drush
Step 8: ddev drush site:install --account-name=admin --account-pass=admin
Step 9: ddev launch
DDev some useful commands:
- ddev describe( List the available containers for the current ddev instance.)
- ddev ssh (Ssh to the web container.)
- ddev export-db -f ./db.sql.gz (Take the site backup as gz format)
- ddev import-db --src=./db.sql.gz (Import the database)
- ddev list (List the all running ddev instances)
- ddev restart(Restart current ddev instance)
- ddev poweroff(Power off the all ddev instances)
DDev drush some useful commands:
- ddev drush cr(Clear Drupal cache)
- ddev drush cim(Import the drush site configurations)
- ddev drush cex (Export the drush configurations)
- ddev drush uli (One time login url if don't the admin password and want to login on the site)
Setup the Site Configurations path:
Once Drupal site is configure and accessible then update the site configuration path into settings.php. Find the config_sync_directory keyword in the file. If the path is not configured yet then update the path to
$settings['config_sync_directory'] = '../config/syc'
Enable local development mode:
For local development it is recommend to enable the development mode. Please follow the below steps.
Step 1: Uncomment the below lines in settings.php
if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
include $app_root . '/' . $site_path . '/settings.local.php';
}
Step 2: Copy web/sites/example.settings.local.php to web/sites/default/settings.local.php
Step 3: Update the web/sites/development.services.yml
twig.config:
debug: true
auto_reload: true
cache: false
Enable/Display Error Reporting:
In your settings.php(sites/default/settings.php) or settings.local.php add the following code:
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
$config['system.logging']['error_level'] = 'verbose';
On your productions or dev you can enable verbose by using below command:
drush config:set system.logging error_level verbose -y