🚀 Setting Up Your Drupal Module Development Environment: Best Practices + VSCode Setup
Are you starting Drupal module development and want to follow the community’s best practices from Day 1? You're in the right place! 🎯
In this guide, we’ll walk through setting up your Drupal development environment with Composer, Drush, PHPUnit, code linting, and VSCode — so you can develop like a pro. 👨💻
🧱 1. Install Drupal Using Composer
Start by creating a new Drupal project with the recommended structure:
composer create-project drupal/recommended-project my_site_name_dir
cd my_site_name_dir
This gives you:
- Clean project structure
web/
as web root- Composer-managed core and contrib modules
🛠️ 2. Fix Core Dependencies
If you're getting errors like “missing or incorrect dependency in your project”, run:
composer require drupal/core --with-all-dependencies
🧩 3. Install Developer Tools & Drush
Drush is your CLI superpower ⚡. Add it and other useful dev tools:
composer require drush/drush --dev
composer require phpunit/phpunit --dev
composer require squizlabs/php_codesniffer --dev
composer require dealerdirect/phpcodesniffer-composer-installer --dev
composer require drupal/coder --dev
✅ Now you can run:
vendor/bin/drush status
vendor/bin/phpcs --version
🧪 4. Enable Must-Have Dev Modules
Add these modules to supercharge development:
composer require \
drupal/devel \
drupal/webprofiler \
drupal/stage_file_proxy \
drupal/admin_toolbar
Module | Purpose |
---|---|
devel |
Debugging and helper tools 🐞 |
webprofiler |
Symfony-style profiler bar ⚙️ |
stage_file_proxy |
Auto-fetch files from prod 🌐 |
admin_toolbar |
Better admin UX 🧭 |
✅ 5. Setup PHP Code Standards (Linting)
Drupal uses strict coding standards. Here's how to enable automatic linting:
Configure PHP CodeSniffer:
vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer
vendor/bin/phpcs --config-set default_standard Drupal
Create .phpcs.xml
in your root:
<?xml version="1.0"?>
<ruleset name="Drupal">
<description>Drupal Coding Standards</description>
<rule ref="Drupal"/>
<rule ref="DrupalPractice"/>
<file>web/modules/custom</file>
</ruleset>
Run linting:
vendor/bin/phpcs web/modules/custom
🧪 6. Configure PHPUnit for Automated Tests
Add this phpunit.xml
to your project root:
<phpunit bootstrap="web/core/tests/bootstrap.php"
colors="true"
verbose="true">
<testsuites>
<testsuite name="Custom Module Tests">
<directory>web/modules/custom/YOUR_MODULE/tests/src</directory>
</testsuite>
</testsuites>
</phpunit>
Run tests with:
./vendor/bin/phpunit
💻 7. VSCode Configuration for Drupal
Use VSCode with these extensions for a silky-smooth Drupal experience:
🧩 Recommended Extensions:
- PHP Intelephense
- Drupal Snippets
- PHPUnit
- Twig Language 2
- EditorConfig for VSCode
⚙️ .vscode/settings.json
:
{
"php.validate.executablePath": "/usr/bin/php",
"intelephense.environment.phpVersion": "8.1",
"intelephense.files.exclude": ["**/vendor/**"],
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/vendor": true
},
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
}
}
🎁 Bonus Tips
- Use DDEV or Lando for container-based local dev.
- Use
.editorconfig
for consistent formatting across teams. - Use
composer patches
for clean contrib module customizations.
🏁 Final Thoughts
With this setup, you’re now ready to: ✅ Write clean modules ✅ Follow coding standards ✅ Run automated tests ✅ Develop with confidence 🚀
Got questions or want to automate even more? Let’s connect! 💬
♥️ Built with love for the Drupal community