How to Install and Configure Drupal 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 8 is the latest version of the popular Drupal content management system. This guide demonstrates how to install Drupal 8 on your Linode running CentOS 8.

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

  4. 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
    
  5. 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
    

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.2 is the latest version. See Drupal’s download page for their latest core tarball.

     sudo wget http://ftp.drupal.org/files/projects/drupal-8.8.2.tar.gz
    
    Caution
    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 web configuration in the Drupal First Start section.

     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 the directories Drupal 8 and Apache 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 semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/example.com/public_html/sites/default/settings.php'
     sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/example.com/public_html/sites/default/files'
     sudo restorecon -Rv /var/www/html/example.com/public_html
     sudo restorecon -v /var/www/html/example.com/public_html/sites/default/settings.php
    
  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
    

Drupal First Start

  1. Go to your Linode’s domain or IP address in a web browser. This will show you the first step of Drupal 8’s web configuration. Choose your language and proceed to the next page.

  2. Choose whether you want a Standard or Minimal installation profile.

  3. Complete the database configuration using the DB name, username and password you created when setting up your LAMP stack with a MySQL or MariaDB database.

    Note
    If you forgot the name of your database, log back in to MySQL or MariaDB with: mysql -u root -p and enter: show databases;.
  4. After Drupal 8 installs your site, you’ll be shown a site configuration page where you must create the admin user for your website. Do not use the same password that you used for your database.

    Next, you’ll be taken to the administrative dashboard which will say that Drupal 8 was installed successfully.

  5. Now that Drupal 8 is finished writing to settings.php and services.yaml, you can restore their default permissions:

    sudo chmod 644 /var/www/html/example.com/public_html/sites/default/{settings.php,services.yml}
    

Where to Go From Here

Drupal has a significant amount of documentation for security best practices to consider when hardening any Drupal server. There is also extensive community documentation and there are multiple ways of participating in the Drupal community.

This page was originally published on


Your Feedback Is Important

Let us know if this guide made it easy to get the answer you needed.


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.