A minimal Drupal 9 local development environment

Submitted by christophe on Tue, 02/02/2021 - 00:54
Drupal 9 lightweight development environment


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 

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

cd my-project-directory 
php web/core/scripts/drupal install standard 

Run it with the PHP built-in server.

cd web 
php -S 127.0.0.1:8888 

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 

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 

Get common development tools

CLI utility

Install Drush as a development dependency.

composer require --dev drush/drush 

Check the site status and list Drush commands.

cd web 
../vendor/bin/drush status 
../vendor/bin/drush list 

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 

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

../vendor/bin/drush serve 

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 

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 

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

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

Tags

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.