Install Drupal using Drush on CentOS 8

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.

Drupal is a content management system (CMS) designed for building custom websites for personal and business use. Built for high performance and scalability, Drupal provides the necessary tools to create rich, interactive “community” websites with forums, user blogs, and private messaging. Drupal also has support for personal publishing projects and can power podcasts, blogs, and knowledge-based systems, all within a single, unified platform.

Drush is a command line tool for creating, administrating, and modifying Drupal websites. Command line tools, like Drush, add functionality through additional command packages. Once installed, Drush is as easy to use as any of the basic Linux commands.

Before You Begin

  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, 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 CentOS 8

  4. Install Composer and Drush on CentOS 8

  5. Install the wget and tar utilities. You will need this in a later section to install the Drupal 8 core.

    sudo yum install wget -y && sudo yum install tar -y
    
  6. In order to work with Drupal 8 and SELinux, you will need to install Python’s policy core utilities, which give you access to useful tools to manage SELinux settings.

     sudo yum install policycoreutils-python-utils -y
    

Download and Prepare Drupal 8

  1. Navigate to your site’s document root. If you installed and configured your Apache server using our LAMP stack on CentOS 8 guide, your document root should be located in the /var/www/html/example.com/public_html/ directory. Replace example.com with your own document root path’s name.

     cd /var/www/html/example.com
    
  2. Download the Drupal 8 tarball. As of writing this guide, Drupal 8.8.3 is the latest version. See Drupal’s download page for their latest core tarball. Replace 8.8.3 with the version number you wish to download.

     sudo wget http://ftp.drupal.org/files/projects/drupal-8.8.3.tar.gz
    
    Important
    Ensure that the version number matches the Drupal 8 version you wish to download.
  3. Extract the downloaded tarball’s contents into your site’s document root:

    sudo tar -zxvf drupal-8.*.tar.gz --strip-components=1 -C public_html
    
  4. Drupal depends on a PHP graphics library called GD. Install GD and other dependencies:

    sudo yum install -y php php-{cli,mysqlnd,json,opcache,xml,mbstring,gd,curl}
    
  5. Create your Drupal 8 installation’s settings.php file from the default settings file. This file will be configured when you run through Drupal’s automated web configuration. See the Install and Configure Drupal on CentOS 8 guide for more details.

     sudo cp /var/www/html/example.com/public_html/sites/default/default.settings.php /var/www/html/example.com/public_html/sites/default/settings.php
    
  6. Enforce trusted hostnames with those that users will access your site from. With the text editor of your choice, edit your settings.php file replacing the regular expression (RegEx) with a pattern that matches your own site’s URL(s).

    File: /var/www/html/example.com/public_html/sites/default/settings.php
    $settings['trusted_host_patterns'] = array(
      '^www\.example\.com$',
      '^example\.com$',
      );
    Note
    trusted_host_patterns also accepts IP addresses or localhost.

Configure Apache 2.4

  1. Enable Apache’s rewrite module. This module is necessary since Drupal 8 enables Clean URLs by default. To enable this module, edit your Apache configuration to include the LoadModule line displayed in the example file below.

    File: /etc/httpd/conf/httpd.conf
    1
    2
    
    LoadModule rewrite_module modules/mod_rewrite.so
        
  2. Specify the rewrite conditions for your Drupal site’s document root in Apache’s configuration file using the text editor of your choice. If you installed and configured your Apache server using LAMP stack on CentOS 8 guide, the configuration file for your site is located at /etc/httpd/conf.d/example.com.conf.

    File: /etc/httpd/sites-enabled/example.com.conf
    <Directory /var/www/html/example.com/public_html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
          RewriteEngine on
          RewriteBase /
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    </Directory>
  3. Set the SELinux context for your site’s directories in order to read and write to them. This includes your site’s root directory and subdirectories.

     sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/example.com/public_html(/.*)?"
     sudo chcon -Rt public_content_rw_t /var/www/html/example.com/public_html/sites/default/files
     sudo setsebool -P allow_httpd_anon_write=1
    
  4. Change the ownership of your site’s document root from root to apache. This allows you to install modules and themes, and to update Drupal, without being prompted for FTP credentials.

    sudo chown apache:apache -R /var/www/html/example.com/public_html
    
  5. Restart Apache so all your changes are applied.

    sudo systemctl restart httpd
    

Create a Drupal Website with Drush

In this section, you will use Drush to install a Drupal site with just a few commands.

  1. Change the working directory to the location of your new Drupal website. The previous guides created a /var/www/html/example.com/public_html directory, where public_html is the document root or the publicly viewable directory. Replace example.com with your own site’s name.

    cd  /var/www/html/example.com/public_html
    
  2. Your Linode is now ready for you to install a Drupal site. In the command below, replace mysql://username:password@localhost/databasename with your own site’s username, password, and database. For example, if you followed the How to Install a LAMP stack on CentOS 8 your username is webuser, password is password, and the database is webdata. Also, replace --site-name=example.com with your own website’s name.

    drush si standard --db-url=mysql://username:password@localhost/databasename --site-name=example.com
    
    Note
    Although MySQL accepts passwords with a special character, for example an exclamation point, the drush si standard command does not. If you have a special character in your MySQL password, you may need to change it.
    Note
    If you encounter errors related to writing to the sites/default directory, follow the steps in the Setting the Site’s Ownership and Permissions section to ensure the web server belongs to the current user’s group.

    After the installation is complete, Drush creates a user, named admin, and a random password. An example is pictured below. These credentials are used for the Drupal sign-in page.

  3. Optionally, if you’d like to change the admin’s password, it is best to do so with Drush, rather than sending the password over a non-secure HTTP connection. To update the admin password execute the following command and replace newpass with your new password:

    sudo drush user-password admin user-password=newpass
    

Setting the Site’s Ownership and Permissions

In server administration, there are many options for user and group permissions. The directions below create a site owner and a site owner’s group. The site owner will be added to the Apache web server’s group, named apache. Then, read, write, and execute permissions are granted to the apache user and group.

  1. To create a new user for the site owner position, see the Add a Limited User Account section of the Setting Up and Securing a Compute Instance guide.

  2. From the public_html directory, change ownership of the site to the apache user and group.

    sudo chown -R apache:apache sites/default
    
  3. Add the example_user to the apache group:

    sudo usermod -a -G apache example_user
    
  4. Make sure the permissions are set to allow access for the site owner and site owner’s group. Replace example.com with your own domain name.

    sudo chmod 774 -R /var/www/html/example.com/public_html
    

    Now, apache, example_user, and any user within the apache group has read, write, and execute permissions for the entire Drupal site directory tree.

  5. Restart Apache:

    sudo systemctl restart httpd
    
  6. Finally, check the status of the new site:

    drush status
    
    Note
    When installing new files, like a module or theme, make sure the Apache user has access rights. Use the command ls -al to list the file permissions within a directory to determine which permissions are assigned to it.

Navigate to your site’s domain (or IP address if you did not set up a domain name). Sign-in with the generated username and password to begin creating content for your Drupal site.

Additional Options

There are many ways to set up administration for a website. Below are sections explaining some additional options. It’s important to be aware of multi-site setups and additional security measures. The topics below touch on these subjects.

File Ownership, Permissions, and Security

The above setup is designed for ease of use. However, there are setups designed for tighter security and other considerations.

Multi-site Servers

At a high-level, the steps you will need to follow to begin configuring a Drupal multisite set up are:

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.