Install Drupal Themes and Modules Using Drush on Ubuntu 18.04

Select distribution:
Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

Drush is a command line tool, which can be used for various Drupal projects. This tutorial uses Drush to install themes, modules, and covering some basic administration tasks such as backup and migrate for Drupal websites.

Linode has another guide for installing Drush and creating a Drupal website, Install Drupal using Drush on Ubuntu 18.04. Depending on your experience level with Drush, you may want to start with that guide.

Before You Begin

Before installing themes, modules, and a backup system with Drush, make sure that the following prerequisites have been met:

  1. Familiarize yourself with our Getting Started guide and complete the steps for setting your Linode’s hostname and timezone.

  2. Follow our Securing Your Server guide to create a standard user account, harden SSH access, remove unnecessary network services and create firewall rules for your web server; you may need to make additional firewall exceptions for your specific application.

    Note

    This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, visit our Users and Groups guide.

    All configuration files should be edited with elevated privileges. Remember to include sudo before running your text editor.

  3. Install and configure a LAMP stack on Ubuntu 18.04

  4. Install Composer and Drush on Ubuntu 18.04

  5. Make sure that your system is up to date, using:

    sudo apt-get update && sudo apt-get upgrade
    
Note
The Drush commands to download or enable themes and modules vary depending on the version of Drush that you have installed. This guide uses Drush 10.

Installing Themes with Drush

In this section you will download, enable, and set a Drupal theme using Drush.

  1. Navigate to Drupal’s Download and Extend page to find the theme you want to download. The Drush download name is usually appended to the end of the Drupal theme page’s URL; for example, drupal.org/project/project/my_theme.

  2. Move into your Drupal site’s document root, /var/www/html/example.com/public_html/. Replace example.com with your own domain’s name.

     cd /var/www/html/example.com/public_html
    
  3. Download your desired theme using Composer. For example to download the bootstrap theme use:

     composer require drupal/bootstrap
    
    Note

    If you receive an error related to not being able to write to the composer.json file, see the Setting the Site’s Ownership and Permissions section of the Install Drupal using Drush on Ubuntu 18.04 guide.

    Ensure that your /var/www/html/example.com/public_html directory has user and group read, write, and execute permissions.

    sudo chmod 774 -R /var/www/html/example.com/public_html
    
  4. Enable the theme that you downloaded in the previous step. For example, to enable the bootstrap theme run the following command. Replace bootstrap with the name of your theme.

    drush theme:enable bootstrap
    
  5. As an example, set the Omega theme as the default and active theme:

    drush config-set system.theme default omega
    

    Check the homepage of your site and the new theme should appear.

Installing Modules with Drush

Downloading and enabling a module is similar to working with a theme. However, modules can be used for almost any purpose. From enhancing public-facing functionality to providing a better administrative UI; there are thousands of Drupal modules. It is helpful to use modules with clear documentation, since once a module is installed, its interface can be challenging to use if it is not well documented and designed by the contributor.

  1. Move into your Drupal site’s document root, /var/www/html/example.com/public_html/. Replace example.com with your own domain’s name.

     cd /var/www/html/example.com/public_html
    
  2. Download the Backup and Migrate module. This module enables you to perform the backup, restore, and migrate tasks

     composer require drupal/backup_migrate
    
  3. Enable the backup_migrate module:

    drush en backup_migrate -y
    
  4. Sign in to your Drupal site’s browser interface and navigate to the Extend menu item (or Administration > Extend). Under the OTHER section, the Backup and Migrate module will be listed and selected.

You have successfully installed and enabled a new module. The module is now running and ready to be used.

Backup a Drupal Site

It’s always important to keep regular backups of a website. Backups protect you from losing data due to configuration changes, vulnerabilities, or system failures. Backups should be stored on a separate system whenever possible. The Backup and Migrate module helps you to create backups of your site.

  1. To configure backup and migrate, navigate to Administration > Configuration > Development > Backup and Migrate

  2. For a quick backup, select the type of Backup Source and select the Backup Destination, and click Backup now

Note
Always download a backup prior to updating or installing modules.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.