{"id":822,"date":"2024-06-30T09:42:48","date_gmt":"2024-06-30T09:42:48","guid":{"rendered":"https:\/\/www.cmsgalaxy.com\/blog\/?p=822"},"modified":"2024-06-30T09:55:33","modified_gmt":"2024-06-30T09:55:33","slug":"drupal-tutorails-drush-complete-guide","status":"publish","type":"post","link":"https:\/\/www.cmsgalaxy.com\/blog\/drupal-tutorails-drush-complete-guide\/","title":{"rendered":"Drupal Tutorails: Drush Complete Guide"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"595\" src=\"https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2024\/06\/image-2.png\" alt=\"\" class=\"wp-image-826\" srcset=\"https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2024\/06\/image-2.png 975w, https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2024\/06\/image-2-300x183.png 300w, https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2024\/06\/image-2-768x469.png 768w\" sizes=\"auto, (max-width: 975px) 100vw, 975px\" \/><\/figure>\n\n\n\n<p>Drush (Drupal Shell) is a command-line shell and scripting interface for Drupal. It provides a suite of commands for managing your Drupal sites, making tasks like module updates, database backups, migrations, and other maintenance tasks much easier and faster. Drush can be used to perform nearly any administrative task for Drupal from the command line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Drush<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"941\" height=\"813\" src=\"https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2024\/06\/image-3.png\" alt=\"\" class=\"wp-image-828\" srcset=\"https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2024\/06\/image-3.png 941w, https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2024\/06\/image-3-300x259.png 300w, https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2024\/06\/image-3-768x664.png 768w\" sizes=\"auto, (max-width: 941px) 100vw, 941px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Install Composer<\/h4>\n\n\n\n<p>Composer is a dependency manager for PHP, and it&#8217;s required to install Drush.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Install Composer\ncurl -sS https:\/\/getcomposer.org\/installer | php\nsudo mv composer.phar \/usr\/local\/bin\/composer\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: Install Drush Globally<\/h4>\n\n\n\n<p>Using Composer, you can install Drush globally:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Install Drush globally\ncomposer global require drush\/drush\n\n# Make sure Composer's global bin directory is in your PATH\necho 'export PATH=\"$HOME\/.composer\/vendor\/bin:$PATH\"' &gt;&gt; ~\/.bashrc\nsource ~\/.bashrc\n<\/code><\/pre>\n\n\n\n<p>Alternatively, you can install a specific version of Drush globally:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Install Drush 10 globally\ncomposer global require drush\/drush:10.*\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: Verify Drush Installation<\/h4>\n\n\n\n<p>To verify that Drush is installed correctly, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush --version\n<\/code><\/pre>\n\n\n\n<p>You should see output indicating the version of Drush that is installed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using Drush<\/h3>\n\n\n\n<p>Drush commands follow a common pattern:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush &#91;command] &#91;options] &#91;arguments]\n<\/code><\/pre>\n\n\n\n<p>Here are some of the most commonly used Drush commands:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Clear Cache<\/h4>\n\n\n\n<p>Clearing the cache is a frequent task during development.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush cache-clear all\n<\/code><\/pre>\n\n\n\n<p>In newer versions of Drush, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush cr\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: Download and Enable a Module<\/h4>\n\n\n\n<p>To download and enable a module, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush dl module_name\ndrush en module_name\n<\/code><\/pre>\n\n\n\n<p>For example, to download and enable the Pathauto module:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush dl pathauto\ndrush en pathauto\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: Update Drupal Core and Modules<\/h4>\n\n\n\n<p>To update Drupal core and all modules, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush pm-update\n<\/code><\/pre>\n\n\n\n<p>To update only Drupal core, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush pm-update drupal\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 4: Run Database Updates<\/h4>\n\n\n\n<p>After updating modules or core, you often need to run database updates:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush updatedb\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 5: Backup and Restore Database<\/h4>\n\n\n\n<p>To create a backup of your database, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush sql-dump &gt; drupal-backup.sql\n<\/code><\/pre>\n\n\n\n<p>To restore the database from a backup:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush sql-cli &lt; drupal-backup.sql\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 6: User Management<\/h4>\n\n\n\n<p>To create a new user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush user-create username --mail=\"email@example.com\" --password=\"password\"\n<\/code><\/pre>\n\n\n\n<p>To block a user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush user-block username\n<\/code><\/pre>\n\n\n\n<p>To unblock a user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush user-unblock username\n<\/code><\/pre>\n\n\n\n<p>To assign a role to a user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush user-add-role \"role_name\" username\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 7: Watchdog Log<\/h4>\n\n\n\n<p>To view the watchdog log (recent site logs):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush watchdog-show\n<\/code><\/pre>\n\n\n\n<p>To clear the watchdog log:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush watchdog-delete all\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step-by-Step Example: Setting Up a New Drupal Site with Drush<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Install Drupal using Drush<\/h4>\n\n\n\n<p>Create a new Drupal project using Composer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer create-project drupal\/recommended-project my_drupal_site\ncd my_drupal_site\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: Set Up a Database<\/h4>\n\n\n\n<p>Create a new database for your Drupal site:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p\nCREATE DATABASE drupal;\nGRANT ALL PRIVILEGES ON drupal.* TO 'drupaluser'@'localhost' IDENTIFIED BY 'password';\nFLUSH PRIVILEGES;\nEXIT;\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: Install Drupal Site<\/h4>\n\n\n\n<p>Run the site installation command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush site-install standard --db-url='mysql:\/\/drupaluser:password@localhost\/drupal' --site-name='My Drupal Site' --account-name='admin' --account-pass='adminpassword'\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 4: Configure Drush for Your Site<\/h4>\n\n\n\n<p>Create an alias for your site to make Drush commands easier to run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush site-alias @my_drupal_site --root=\/path\/to\/my_drupal_site --uri=http:\/\/localhost\n<\/code><\/pre>\n\n\n\n<p>Now you can use the alias to run Drush commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drush @my_drupal_site status\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Drush (Drupal Shell) is a command-line shell and scripting interface for Drupal. It provides a suite of commands for managing<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[790],"tags":[],"class_list":["post-822","post","type-post","status-publish","format-standard","hentry","category-drupal"],"_links":{"self":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/comments?post=822"}],"version-history":[{"count":2,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/822\/revisions"}],"predecessor-version":[{"id":829,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/822\/revisions\/829"}],"wp:attachment":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/media?parent=822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/categories?post=822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/tags?post=822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}