Post

Drush Cheatsheet

Get version of Drupal and PHP you are running.

1
drush status

Update sync database

The updatedb command is used to update the locate database on Unix-like systems. This database is used by the locate command to quickly find files on the filesystem.

What Does update DB Do?

  • Scans the Filesystem: It scans directories in the filesystem to create an index of file names and their locations.
  • Updates the Database: The collected information is stored in a database file, usually located at /var/lib/mlocate/mlocate.db or a similar path.
  • Optimizes Search Performance: By maintaining an indexed list of files, it allows the locate command to retrieve results much faster than using find.

When Should You Run updatedb?

You should run drush updatedb:

  • After Adding or Deleting Many Files: If you’ve recently made significant changes to your filesystem (e.g., installed new software, moved directories, or deleted files), you may want to update the database to reflect these changes.
  • If locate Results Are Outdated: If the locate command isn’t finding files that exist or is showing files that have been deleted, running updatedb will refresh the index.
1
drush updatedb

List installed modules

1
drush pm:list --status=enabled

Remove flag to get all installed modules, regardless of status

Enable Module

1
ddev drush en paragraphs

Its best practice to enable modules with drush —

** Why? **

When you enable a module, Drupal:

  • Writes to the database
  • Changes active configuration
  • Sometimes installs config provided by the module

If you enable via the UI on production, you are:

Changing production directly without version control.

** What is config drift? **

Dev and Prod stop matching.

That creates something called config drift.

** Example: **

  • You enable module on Prod via UI.
  • It’s NOT enabled on Dev.
  • Your git repo does NOT know about this.
  • Later you deploy config from Dev.
  • Suddenly Prod disables it or breaks.
  • Now you’re debugging a ghost problem.

Drush + config export prevents that.

Disable module

1
 drush pm:disable module_name

List Themes

1
drush pm-list --type=theme

Enable Theme

1
ddev drush theme-enable bootstrap5

Set theme as default

1
2
ddev drush cset system.theme default bootstrap5 --yes
ddev drush cr
1
cd /your/drupal/site/
1
drush uli --uri example.com

Trouble Shooting

The Drush launcher could not find a local Drush in your Drupal site.

1
vendor/bin/drush uli --uri http://your-site-url

Find Drush version

1
drush --version

Update Drush

You might need to add the ^ to the beginning of the version number ie ^12.0.2 in the composer.json file.

1
composer update drush/drush

Uninstall Drupal Module

1
drush pm:uninstall module_name

Remove the Module:

1
composer remove drupal/module_name

** same command but with ddev **

Uninstall the Module:

1
ddev drush pm:uninstall module_name

Remove the Module:

1
ddev composer remove drupal/module_name
This post is licensed under CC BY 4.0 by the author.