- Published on
A minimal Drupal 9 local development environment (part 1)
- Christophe Jossart
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, ...
A follow-up of this article discuss how to go further with multiple PHP versions, a mail catcher, Solr, ... and reviews common pitfalls.
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 (make sure that sqlite3 is available).
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
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
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
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
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.
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.
Most of them are not specific to Drupal, but can have Drupal support.
- Using Composer to Install Drupal and Manage Dependencies
- Homebrew PHP (Shivam Mathur) to switch local PHP version on Mac OS
- Code Quality check tools for Drupal