A minimal Drupal 9 local development environment

colorfield

Christophe Jossart

Posted on February 28, 2021

A minimal Drupal 9 local development environment

Originally posted on colorfield.be

We will see how to get a minimal and fast Drupal 9 setup in 3 commands.

It just relies on a PHP built-in server, so no Docker here, the only requirements are Composer and PHP.

Then, we will do a recap of the available tools for developers.

The setup is not suitable for production, but is fine to evaluate a new version of Drupal locally, start a proof of concept, do some quick debugging on a vanilla setup, ...

Get Drupal and install it

This command will get the last stable version (9.1.x at the time of writing).

composer create-project drupal/recommended-project my-project-directory
Enter fullscreen mode Exit fullscreen mode

Install then the standard profile with the core install script, using SQLite.

cd my-project-directory
php web/core/scripts/drupal install standard
Enter fullscreen mode Exit fullscreen mode

Run it with the PHP built-in server.

cd web
php -S 127.0.0.1:8888
Enter fullscreen mode Exit fullscreen mode

And done :) your fresh Drupal site is now available: http://127.0.0.1:8888

Notes

To require a specific version, e.g. 8.9 or 9.2.x-dev

composer create-project drupal/recommended-project:^9.2.x-dev my-project-directory
Enter fullscreen mode Exit fullscreen mode

To update the Drupal core, it is slightly different than the Composer template for Drupal projects way to go, if you are used to it.

composer update drupal/core 'drupal/core-*' --with-all-dependencies
Enter fullscreen mode Exit fullscreen mode

Get common development tools

CLI utility

Install Drush as a development dependency.

composer require --dev drush/drush
Enter fullscreen mode Exit fullscreen mode

Check the site status and list Drush commands.

cd web
../vendor/bin/drush status
../vendor/bin/drush list
Enter fullscreen mode Exit fullscreen mode

With Drush installed, it can be used to (re-)install your site, e.g. from the configuration, instead of the core script installation.

../vendor/bin/drush si -y standard --sites-subdir default --account-name admin --account-pass admin --existing-config
Enter fullscreen mode Exit fullscreen mode

Or to serve it, as a replacement of php -S

../vendor/bin/drush serve
Enter fullscreen mode Exit fullscreen mode

Code scaffolding

For Drupal 9, you might be looking for Drupal Console, but there is no current support for it.

Console was taking care of several other helpers (like site:mode dev), but to scaffold code, you can find a replacement with the Module Builder project. Require then enable it (drush en module_builder) and visit http://127.0.0.1:8888/admin/config/development/module_builder

composer require --dev drupal/module_builder
Enter fullscreen mode Exit fullscreen mode

Developer module

Install Devel, it provides extra developer helpers like admin UI tools and Drush commands, var dumper, web profiler, content generation, ...

composer require --dev drupal/devel
Enter fullscreen mode Exit fullscreen mode

The var dumper can be a lightweight replacement of the xdebug one. Out of the box, the Symfony var dumper is available, but I like to use Kint in this case, which is more readable and now allows to search for expressions.

composer require --dev kint-php/kint
Enter fullscreen mode Exit fullscreen mode

Then configure Devel to use Kint, and use kint(), ksm() or dpm() in your code.

Devel Kint variables dumper configuration

Examples

For more than 10 years, the Examples for Developers module provides up-to-date and best practices code for most of the custom development tasks, and it is available for Drupal 9.

Update code from Drupal 8

Reports and fixes deprecated code.

Unit tests

Code quality

Most of them are not specific to Drupal, but can have Drupal support.

Resources

💖 💪 🙅 🚩
colorfield
Christophe Jossart

Posted on February 28, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related