Install Drupal 8 content management system

Table of contents


Drupal is a web site content management system serving web pages to the internet.


Install Apache2 web server if not already installed.

Enable Apache2 rewrite module:

$ sudo a2enmod rewrite

Configure Apache2:

$ sudo gedit /etc/apache2/apache2.conf

Specify, keeping "<" and ">":

<Directory /var/www/>
    Options Indexes FollowSymLinks
    # AllowOverride None # replaced with next line
    AllowOverride All
    Require all granted

Restart Apache2 service:

$ sudo systemctl restart apache2
$ sudo service apache2 restart

Install MySQL server + PHP5 + phpMyAdmin, and create a user with database both called "drupal8".

Co-exist with Drupal7

Change "web" below to "web2" to create another set of folders to co-exist with Drupal7 currently using "web", otherwise, just use "web".


Download Drupal 8.x.x (filename drupal-8.x.x.tar.gz) from, usually to own "Downloads" directory.

Use the file manager to extract the contents of the compressed file under the "Downloads" directory as "drupal-8.x.x".

Create a folder for Drupal but using a directory name of "web" instead of the default of "drupal":

$ sudo mkdir /var/www/web

Change to that directory:

$ cd /var/www/web

Move the contents under drupal-8.x.x:

$ sudo mv /home/<own account name>/Downloads/drupal-8.x.x/* .

See if there are hidden files beginning with ".", e.g. ".htaccess", ".gitignore":

$ sudo ls -la /home/<own account name>/Downloads/drupal-8.x.x

Move the hidden files also, individually:

$ sudo mv /home/<own account name>/Downloads/drupal-8.x.x/<hidden file name> .

or all, which may give an error message:

$ sudo mv /home/<own account name>/Downloads/drupal-8.x.x/.* .

Check again for successful move:

$ sudo ls -la
$ sudo ls -la /home/<own account name>/Downloads/drupal-8.x.x

Create a location for site files:

$ sudo mkdir sites/default/files

Change ownership:

$ sudo chown www-data:www-data sites/default/files

Create the initial configuration file for the default site:

$ sudo cp sites/default/default.settings.php sites/default/settings.php

Change ownership:

$ sudo chown www-data:www-data sites/default/settings.php

Restart Apache2 service:

$ sudo systemctl restart apache2
$ sudo service apache2 restart

Complete the Drupal Installation through a Browser by pointing to http://localhost/web/install.php, and follow the instructions there, using:

  • Choose language: English language
  • Choose profile: Standard
  • Setup database: MySQL
  • MySQL database name, user name and password as defined above
  • Site name:
  • Site e-mail address: <>
  • Site maintenance username: <name of the administrator>
  • Site maintenance user e-mail address: <>
  • Default country: Hong Kong S.A.R., China
  • Default time zone: Asia/Hong Kong
  • Check for updates automatically
  • Receive e-mail notifications

Change folder permissions:

$ sudo chmod 555 sites/default
$ sudo chmod 444 sites/default/settings.php

Permit uploading of files (similar change for modules and themes not required, they use ftp upload)

$ sudo chown www-data:www-data -R sites/default/files

Increase upload file size limit:

$ sudo gedit /etc/php/7.0/apache2/php.ini

Change existing to:

post_max_size = 200M
upload_max_filesize = 50M
max_file_uploads = 100

Restart Apache2 service:

$ sudo systemctl restart apache2
$ sudo service apache2 restart

Edit "settings.php" file:

$ sudo gedit /var/www/web/sites/default/settings.php

specify trusted hosts:

$settings['trusted_host_patterns'] = array(

Disable "update.php" file:

$ sudo mv /var/www/web/update.php /var/www/web/<some new name>

Migrate from Drupal 7 (as of 21 February 2018)

Log in as an administrator if not already in.

Choose "Manage" > "Extend" > "Book" module under Core > "Install" at the bottom, to allow users to create and organize related content in an outline.

Choose "Manage" > "Extend" > "Statistics" module under Core > "Install" at the bottom, to log content statistics.

Similarly, enable modules in Drupal8 that are enabled in Drupal7.

Click open the explanatory note of "Statistics". Select "Configure" > "Count content views" > "Save configuration" > "Continue".

Choose "Manage" > "Extend" > "Migrate", "Migrate Drupal" and "Migrate Drupal UI" modules under Core (Experimental) > "Install" at the bottom, to allow users to create and organize related content in an outline.

Click open the explanatory note of "Migrate Drupal UI". Select "Configure" > "Continue" > "maintenance mode" > "Put site into maintenance mode" > "Save configuration".

Move web page back to the Upgrade page. Choose "Continue".

Under SOURCE DATABASE, enter: 

  • Database host: localhost
  • Database name: drupal7
  • Database username: drupal7
  • Database password: <>

Under SOURCE FILES, assuming under "oldweb" enter:

  • /var/www/oldweb

Resolve the following problems found:

  • Some uploaded files have not been migrated. Execute "sudo cp /var/www/<oldweb>/sites/default/files/* /var/www/web/sites/default/files" to copy the files over (not the sub-directories).
  • The Main menu used in Drupal 7 has been migrated with a machine name called "main-menu" but the machine name used in Drupal 8 is called "main". This is incompatible. Although the menu structure is the same, the contents cannot be displayed. There is also an error message saying that the main-menu index has a problem. Add another menu under "Manage > Structure > Menus". Still at there, select "Edit menu" against the migrated Main menu to edit the individual menu items. Change the "Parent link" from the migrated Main menu to the newly added menu so as to empty the migrated Main menu. This may help remove the indexing problem. The contents can be displayed using the newly added menu. If things go fine and it is preferred to use the true Main menu, move the items back from the newly added menu to the Main menu, which should now use the correct machine name. The foregoing is based on memory. During the problem solving endeavour, mySQL has been accessed to delete references to "main-menu", but it is not sure whether this is really essential.
  • The Book menu has not been migrated and will need build-up from scratch.
  • The previously used theme has not been migrated. Download and install the desired theme under "Manage > Appearance". Set up with reference to the original setting.
  • Many modules have not been migrated. Download and install them from scratch under "Manage > Extend". Not all modules are available for Drupal 8.
  • Some modules (e.g. CKEditor Color Button) require the creation of a "libraries" folder under the Drupal root directory.
  • Some modules require the downloading of files at the server (i.e. not the web) and putting the unzipped files under the "libraries" and "vendor" folders. Some even require a sub-directory under "libraries", e.g. "CKEditor Find" module requires "... libraries/ckeditor/plugins".
  • Install the "libraries" module because some CKEditor modules require this to work.
  • CKEditor has the bigger problem. Instead of being a single installable module, it has now been included as part of Drupal 8 but with trimmed down features. To add back those features, individual modules and their corresponding CKEditor plugin files have to be installed. Not all previous features have Drupal 8 modules available. Not all Drupal 8 modules are successful. A lot of trial and error has to be done.

Re-direct http path to sub-directory "web"

Create a new ".htaccess" file under "/var/www":

$ sudo gedit /var/www/.htaccess


<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /
  RewriteRule ^(.*)$ web/$1 [R]

"^(.*)$" represents the full text from start to end after the domain name "".

"$1" represents the value represented by "(.*)". "web/" is to be inserted before this. "RewriteBase /" is to add "/" before "web". Without this, "/var/www/" will be added before "web/$1" and will cause unexpected results. This effect was discovered after many days of error discovery.

"[R]" is to redirect the path and will show "web/" as part of the redirected path. Using [F] may hide "web/" from the displayed path, but some of the web pages will show "web/" unavoidably. A mixed use with or without "web/" displayed will cause denial of access rights in some cases. Therefore, it is better to force to display "web/".

The following has the same effect:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /web
  RewriteRule ^(.*)$ $1 [R]

Remove "www" from url

This is not essential for using Drupal, but is adopted only to simplify.

Edit ".htaccess" file under /var/www/web:

$ sudo gedit /var/www/web/.htaccess


# To redirect all users to access the site WITHOUT the 'www.' prefix,
# ( will be redirected to
# uncomment the following:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

Permit redirection to external url

This section would not be required if the path redirection is properly defined.

Redirecting between a path with or without "web/" will be treated as a redirection to external url. Drupal 8 does not allow redirection to external url by default.

To allow:

$ sudo gedit /var/www/web/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php

change lines 7 and 74 from:

use Drupal\Core\Routing\LocalRedirectResponse;
$safe_response = LocalRedirectResponse::createFromRedirectResponse($response);


use Drupal\Core\Routing\TrustedRedirectResponse;
$safe_response = TrustedRedirectResponse::createFromRedirectResponse($response);

Page last modified: 20 March 2018