TLDR Code Snippet

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
> cd $your_project_path
> ddev config --project-type="drupal" --php-version="8.2"

> ddev start
> ddev composer install 
> ddev composer require drush/drush
> ddev drush cr 
> ddev launch 

> ddev drush user-login
> ddev launch $(ddev drush uli)
> ddev import-db --file="$your_db_file_path"

DDEV with Drupal 8,9,10

(complete step-by-step breakdown screenshot can be found at: here)

Step-1: configuration initialisation and start environment

To begin with, you will need to get a copy of the project’s filebase to your local computer, navigate to the project’s folder, and initialize the ddev configuration file there using the ddev config --project-type drupal command:

1
2
> cd /Download 
> ddev config --project-type drupal

*Optionally, you may also enter argument, such as project’s name and php’s verison, at the time of writting this post, by default, the project’s name fill be the folder’s name, and php version will be php 8.3.0 (You may find a full list of the argument at: here):

1
> ddev config --project-type=drupal --project-name="my-website" --php-version=7.4

Once, the command finishes running, there’ll be a new \.ddev directory created on the root of your project folder, and you will be able to start the project via running ddev start, of which will start the docker container:

2025-01-06T133041

Step-2: install dependencies (inc. drush/drush)

Next we’ll use the ddev composer command to install the required dependencies for ddev:

1
2
3
4
5
6
7
> ddev composer install
> ddev composer require 'drush/drush'
> ddev composer require 'drupal/paragraphs'
> ddev composer require 'drupal/admin_toolbar'
> ddev composer require 'drupal/field_group'
> ddev composer require 'drupal/twig_tweak'
> ddev composer require 'drupal/bootstrap_barrio:^5.5'

And you can even enable them using the ddev drush command once drush gets installed:

1
2
3
4
5
6
7
8
> ddev drush en paragraphs 
> ddev drush en admin_toolbar
> ddev drush en admin_toolbar_search
> ddev drush en media
> ddev drush en media_library
> ddev drush en field_group
> ddev drush en twig_tweak
> ddev drush then bootstrap_barrio

Step-3: import database and login as admin

Lastly, to recover the project/website’s content, you also need to get a copy of the project’s database, and import it via the ddev import-db command:

1
2
> ddev import-db --file='/Users/xxx/Downloads/example-client-website-db.sql'
> ddev drush cr

2025-01-06T133758

And lastly launch the project running via ddev via your browser, and login using the root user:

1
2
3
> ddev launch
> ddev drush user-login
> ddev launch $(ddev drush uli)

1


DDEV with Drupal 6,7

If you are using ddev with drupal 6,7, you will need to modify the type of the ddev project, and the php_version to match with what drupal 6,7 needs.

You may either define it during initialization phase:

1
ddev config --project-type="drupal" --php-version="7.4"

Or alter it in the .ddev/config.yamlconfiguration file, and run ddev restart after the modification:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
name: XXYY-ZZ
docroot: ""
...
- type: drupal
+ type: drupal7
- php_version: "8.2"
+ php_version: "7.4"
...
database:
    type: mariadb
    version: "10.11"
use_dns_when_possible: true
...

You might also have to manually override the database configuration in settings.php with ddev’s configuration (you can find that via ddev describe, please make sure you comment-out/delete all the other lines of code relating to database configuration; More over you should also consider replacing the base_url with ddev’s hosted website’s url:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
- $base_url = 'https://original_url.ddev.site';  // NO trailing slash!
+ $base_url = 'https://ddev-xxyy-zz.ddev.site';  // NO trailing slash!

-   $databases['default']['default'] = array(
-     'driver' => 'pgsql',
-     'database' => 'databasename',
-     'username' => 'username',
-     'password' => 'password',
-     'host' => 'localhost',
-     'prefix' => '',
-   );
+ $databases['default']['default'] = array (
+ 	'driver' => 'mysql',
+ 	'database' => 'db',
+ 	'username' => 'db',
+ 	'password' => 'db',
+ 	'prefix' => '',
+ 	'host' => 'db',
+ 	'port' => '3306',
+ 	'namespace' => 'Drupal\Core\Database\Driver\mysql',
+ );

-   $databases['default']['default'] = array(
-     'driver' => 'sqlite',
-     'database' => '/path/to/databasefilename',
- );
+ $settings['trusted_host_patterns'] = array();

After editing the settings.php, consider running ddev restart to re-start all the containers, clearing cache; Then when everything is ready, run ddev launch /install.php and follow the link to open the page and install the database (or use ddev import-db --file="$your_db_file_path" to import it before opening).

More information can be found at: https://ddev.readthedocs.io/en/latest/users/quickstart/#drupal-drupal-67


Reference