Drupal

Drupal is a free, web-based Open Source Content Management System (CMS) and Framework written in PHP and distributed under the GPL 2.0 (or later) licence.

According to W3Techs (2011-07-15), at least 2.3% of all websites worldwide are running with Drupal.

Drupal 8 is based on Symfony, a popular high performance PHP framework for web development.

Drupal was released for the first time in 2000 by Dries Buytaert. Since then it has been continuously developed and it is actively maintained by various contributors.


Note

This guide is about installing Drupal 8 via Drupal Composer Template.

Note

You should be familiar with the basic concepts of

Prerequisites

PHP 7.2

We are using PHP in the stable version 7.2:

[isabell@stardust ~]$ uberspace tools version use php 7.2
Selected PHP version 7.2
The new configuration is adapted immediately. Patch updates will be applied automatically.
[isabell@stardust ~]$ uberspace tools version show php
Using 'PHP' version: '7.2'
[isabell@stardust ~]$

Database credentials

You’ll need your MySQL credentials. Get them with my_print_defaults:

[isabell@stardust ~]$ my_print_defaults client
--default-character-set=utf8mb4
--user=isabell
--password=MySuperSecretPassword
[isabell@stardust ~]$

Domain

Your website domain needs to be set up:

[isabell@stardust ~]$ uberspace web domain list
isabell.example
isabell.uber.space
[isabell@stardust ~]$

Database

Create an additional database, for example: isabell_drupal.

Composer

Note

The given Composer command uses the Drupal Composer Template and installs the latest stable release.

You might replace target parameter drupal with something more suitable.

cd into the directory above your document root /var/www/virtual/$USER/ to run to composer command:

[isabell@stardust ~]$ cd /var/www/virtual/$USER/
[isabell@stardust isabell]$ composer create-project drupal-composer/drupal-project:8.x-dev drupal --no-interaction
  - Installing drupal-composer/drupal-project (8.x-dev bdaa8fd): Cloning bdaa8fd53b from cache
Created project in drupal
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
[...]
> DrupalProject\composer\ScriptHandler::createRequiredFiles
Created a sites/default/settings.php file with chmod 0666
Created a sites/default/files directory with chmod 0777
[isabell@stardust isabell]$

RewriteBase

Edit /var/www/virtual/$USER/drupal/web/.htaccess, search for # RewriteBase / and remove the leading # to activate this statement.

RewriteBase /

SCM

It is a very good time to initialise a repository within the drupal directory. This step is optional but highly recommended ;-D

drush

In order to make use of Drupal Composer Template’s drush, you will add the path of your Drupal Composer Template’s bin directory, which contains drush´s executable to the PATH environment variable. It will detect DRUPAL_ROOT.

Place the following statement to the startup file of your shell, e.g. ~/.bashrc or ~/.zshrc:

export PATH=$PATH:/var/www/virtual/$USER/drupal/vendor/bin

Create a configuration file for drush.

[isabell@stardust isabell]$ mkdir ~/.drush
[isabell@stardust isabell]$ cp /var/www/virtual/$USER/drupal/vendor/drush/drush/examples/example.drush.yml ~/.drush/drush.yml

Add uri option to your drush configuration.

This is useful for some commands which generate urls, like drush uli. Edit ~/.drush/drush.yml, search for uri: and place the following statement below the matching line.

uri: 'https://isabell.example'

If you use more than one codebase, you will need install drush_launcher.

Installation

There are at least two different ways to install Drupal:

Interactive Installer

Open a browser and visit the URL of your domain. It is self-explanatory, for specific steps and screenshots checkout Running the Interactive Installer.

drush site:install

Do it via Drush at the command line, see drush site:install for details.

Configuration

Trusted Host setting

For Drupals protection against HTTP HOST Header attacks, you need to configure Trusted host security setting in settings.php, which was introduced in Drupal 8.

Insert this configuration for the domains given above:

$settings['trusted_host_patterns'] = [
  '^isabell\.example$',
  '^isabell\.uber\.space$',
];

Cronjob

For executing periodical tasks like e.g. updatíng the search index, purging old logs or checking for updates, you will need to create a cronjob.

Get your cron url for your site at Administration > Configuration > System > Cron (/admin/config/system/cron). We create a cronjob with above url which runs once a day:

[isabell@stardust isabell]$ crontab -e
4 0 * * * wget -O - -q -t 1 https://isabell.example/cron/CsUKMfKtaFI8P3CaFpWy6iMIJPjjAwnm-Svs6wXb_LSrxqLnlbv85qy5us0YSnK3iQpthKoIrQ

Updates

Note

For Drupal core and contrib updates, configure Reports > Available updates > Settings (/admin/reports/updates/settings) within your site and subscribe Security advisories and public service announcements too!

Core Updates

In case of Core updates see the Updating Drupal Core section of Drupal Composer Template.

Contrib Updates

Updates of contributed modules work like this, e.g. for the geofield contrib:

[isabell@stardust drupal]$ composer update drupal/geofield --with-dependencies

Tested with Drupal 8.7.9 and Uberspace 7.3.7.0

Written by: Florian Latzel <https://netzaffe.de>