FreeBSD Tutorial - Manage Drupal CMS with Drush CLI

Drush, aka The Drupal Shell, is a Unix command line shell and scripting interface for Drupal installations. It allows access to common Drupal features and tasks via the command line. With Drush commands, you can easily update Drupal core files, update modules and execute sql queries.


Drush is a must-have utility for managing one or many Drupal installations. This utility can help speed up common tasks for Drupal site builders, developers, and DevOps teams. Among other things, it makes it easier to integrate Drupal into CI/CD workflows.


The guide in this article will only discuss a few of the many commands. The entire contents of this article run on the FreeBSD 13.2 server, but can also be implemented on Linux or MaxOS systems.


1. About Drush

Drush is made with the PHP programming language that can run in a shell terminal. Drush is used to support Drupal projects, because you can easily interact with one or more Drupal projects. The Drush core ships with commands to perform a variety of common tasks such as managing configurations, performing database updates and clearing the cache. Drush also provides utilities for executing SQL queries and migrations, and for generating scaffolding code for frequently used Drupal core APIs.

Drush can automate many Drupal tasks, usually users perform various steps in the Drupal UI which can take a lot of time, with Drush everything can be executed easily with just CLI commands.

For example, a website may need an update for several reasons, such as security issues and updated modules. Opting to update modules via conventional methods proves to be a time-consuming task. Because you have to do a lot of clicking and other settings. But Drush makes you convenient and saves time by allowing you to update your website with just one command line.

In Drush, you can work on Drupal quickly with the command line. However, you should back up your site and database first.


2. Install Drush

Drush cannot be run without Drupal, but Drupal can be run without Drush. If you want to use Drush, install Drupal first. The following is how to install Drupal on FreeBSD.
root@ns3:~ # cd /usr/ports/www/drupal10
root@ns3:/usr/ports/www/drupal10 # make install clean
You can read a complete guide on how to install Drupal in our previous article.


Before we install Drush, there is a dependency that must be installed, namely "php82-phar".
root@ns3:~ # pkg install php82-phar
We recommend that you use system ports to install Drush, follow the commands below.
root@ns3:~ # cd /usr/ports/www/drush
root@ns3:/usr/ports/www/drush # make install clean
Let's start by looking at Drush's status, using the status command.
root@ns3:~ # drush status
 PHP configuration      :  /usr/local/etc/php.ini
 PHP OS                 :  FreeBSD
 Drush script           :  /usr/local/bin/drush.phar
 Drush version          :  8.4.12
 Drush temp directory   :  /tmp
 Drush configuration    :
 Drush alias files      :


3. How to Use Drush

You can find all the basic drush commands in core drush, but there are many more special Rules commands provided by the Rules module and the Rules Essentials module. The following are some common examples of using Drush commands.

a. Update Commands

Check available updates.
root@ns3:~ # drush pm-updatestatus

b. Update Drupal core and contrib projects
root@ns3:~ # drush pm-updatecode

c. Update Drupal database tables
root@ns3:~ # drush updatedb

d. Update Drupal core and contrib projects, and apply
root@ns3:~ # drush pm-update

e. Cache, List, and Help Commands

Clear cache files.
root@ns3:~ # drush cache-clear
Enter a number to choose which cache to clear.
 [0]  :  Cancel
 [1]  :  drush
1
'drush' cache was cleared.
Clear all cache files.
root@ns3:~ # drush cache-clear all
List all available modules and themes.
root@ns3:~ # drush pm-list
root@ns3:~ # drush pm-info
You can see other Drush commands in the "help" command.
root@ns3:~ # drush help

f. Install, Enable and Uninstall Plugin

To install the selected plugin, you must download the plugin before activating it.
root@ns3:~ # drush dl addtoany
Project addtoany (7.x-4.19) downloaded to /root/addtoany.
To activate the module installed in the above example, you need to run the command below.
root@ns3:~ # drush en addtoany
Remove plugins.
root@ns3:~ # drush pm-uninstall addtoany

If your website or blog uses Drupal, using Drush is unavoidable, because it can simplify the process of updating modules, databases and backups. So Drus and Drupal are one package that cannot be separated.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post