Cheatsheet for Composer with a focus on Drupal Web Development
Install Theme
1
| composer require 'drupal/bootstrap5:^4.0'
|
Install Drush module
The below use of composer is also using ddev
. If not using Ddev exclude the ddev
from the command.
1
| ddev composer require --dev drush/drush
|
Update Drupal Core
Update to 10.3
1
| composer require drupal/core-recommended:10.3 drupal/core-composer-scaffold:10.3 drupal/core-project-message:10.3 --update-with-all-dependencies
|
Update to 10.2
1
| composer require drupal/core-recommended:10.2 drupal/core-composer-scaffold:10.2 drupal/core-project-message:10.2 --update-with-all-dependencies
|
Install a sub theme
In this example we install the radix theme as a sub theme in Drupal using composer
1
| composer require drupal/radix
|
Install components module
1
| composer require 'drupal/components:^3.0@beta'
|
Enable components
Now create a sub theme
1
| drush --include="themes/contrib/radix" radix:create radix_blocks
|
Enable the Sub theme
- Go to appearance and themes
- Install and set as default the radix subtheme
Update Drupal core with composer
Check Status report under Reports in the Administrative GUI. Fix all errors and warnings before proceeding. Before updating, make a back up with Backup and Migrate or Drush, so you can roll back if anything goes wrong. If you use Drush, update to minimum Drush 12.4.3 to be Drupal 10.2 compatible:
1
| composer update drush/drush
|
Update Drupal core with this command:
1
| composer update "drupal/core-*" --with-all-dependencies
|
Use Drush to run required database updates and rebuild caches:
1
2
| drush updatedb
drush cache:rebuild
|
Check Status report under Reports. Fix all errors and warnings.
If using ddev
1
2
| ddev ssh
composer update "drupal/core-*" --with-all-dependencies
|
Troubleshooting
Below are fixes to some errors i have needed to fix at times.
Fix the Satisfy Requirement Error
For example:
1
| phpunit/phpunit 5.7.16 requires php ^5.6 || ^7.0 -> your php version (8.1.29) does not satisfy that requirement
|
- open
composer.json
- update
"phpunit/phpunit": "5.7.16|6.*"
to a Satifiable version "phpunit/phpunit": "^9.5"
Uninstall Drupal Module
1
| drush pm:uninstall module_name
|
Remove the Module:
1
| composer remove drupal/module_name
|
with ddev
Uninstall the Module:
1
| ddev drush pm:uninstall module_name
|
Remove the Module:
1
| ddev composer remove drupal/module_name
|