Drupal 8 Tip: How To Patch A Module Via Composer

In my case I was using the Entity Auto Term module, which issued a patch fixing a known issue. The patch i’m trying to apply is https://www.drupal.org/files/issues/2018-09-28/no-duplicate-terms-2945343-5.patch and part of it looks like this:

To apply it, you have to edit your composer.json located at your website root, pictured here via Filezilla FTP:

I right click view/edit to edit it in Notepad++ here:

I will need to add the red part below. You will most likely have the green part already present, so just edit the red “patches” section to fit your needs.

"extra": {

"installer-paths": {


"web/core": ["type:drupal-core"],


"web/libraries/{$name}": ["type:drupal-library"],


"web/modules/contrib/{$name}": ["type:drupal-module"],


"web/profiles/contrib/{$name}": ["type:drupal-profile"],


"web/themes/contrib/{$name}": ["type:drupal-theme"],


"drush/contrib/{$name}": ["type:drupal-drush"]


},

"patches": {

"drupal/eat": {


"Drupal EAT fix duplicate terms": "https://www.drupal.org/files/issues/2018-09-28/no-duplicate-terms-2945343-5.patch"


}


}


}

Next run Composer Update, and the output should look like this:

That’s it you should be all set.

Drupal 8 Installation On a VPS

This was done on an Ubuntu 14.04 laptop (named groundcontrol). For all intents and purposes it is similar to a VPS. Just like a VPS it has MySQL, Php and Apache running a virtual host, all current versions as of this time.

This tutorial assumes you have set up your VPS appropriately, with the proper directories prepared, hosts file and DNS ready, etc.

I. Download and un-compress.

Go to Drupal.org, click ‘Download & Extend’

1

Click Drupal 8, right click the latest Drupal core 8.x and select ‘copy link address’.

2

Via SSH, login your VPS and go to the directory you set up for the installation. Here I used ‘/srv/www/d8’.

  • Enter ‘sudo wget’ then right-click your mouse to paste the address on the command line, ie.
sudo wget https://ftp.drupal.org/files/projects/drupal-8.1.1.tar.gz

The latest compressed drupal 8 files will download.

  • Uncompress the file
ghm33@groundcontrol /srv/www/d8 $ sudo tar xvzf drupal-8.1.1.tar.gz

The files will decompress into a folder called drupal-8.1.1.

  • Move all the compressed files in the new drupal-8.1.1 directory into public_html.
ghm33@groundcontrol /srv/www/d8 $ sudo cp -rv drupal-8.1.1/* public_html/

Enter the command ‘ls public_html/’ and you will now see all the drupal 8 directories and files properly laid out.

4

II. Prepare database.

Still in the terminal, login mysql.

sudo mysql -u root -p
  • Enter password to login mysql shell.
  • Create a database:
    create database d8;
  • Create a user and grant privileges to that user on d8:
    grant all on d8.* to 'd8user' identified by 'password';
  • flush priviliges;
  • quit

8

You now have an empty database (d8) and a database user (d8user). List this down.

III. Set up Drupal 8.

Open your browser and enter the url where you placed the drupal 8 files. This should appear:

9

After choosing a language, click ‘standard installation’ in ‘choose profile’.

10

A few errors appear.

  • Fix the clean URLs issue (the .htaccess file was not included when we copied it over).
 sudo cp -rv /srv/www/d8/drupal-8.1.1/.htaccess /srv/www/d8/public_html/
  • Fix the File System issue:
sudo mkdir -p /srv/www/d8/public_html/sites/default/files
  • Fix the Settings file issue:
sudo cp -rv /srv/www/d8/public_html/sites/default/default.settings.php /srv/www/d8/public_html/sites/default/settings.php

Refresh the page. You will probably see these messages:

11

  • Fix the file system issue:
 sudo chmod -R 777 /srv/www/d8/public_html/sites/default/files/
  • Fix the settings file issue:
sudo chmod 777 /srv/www/d8/public_html/sites/default/settings.php
  • Refresh your browser and proceed. Enter the database details prepared earlier.

12

Wait.

13

This message will appear:

14

Enter the ff. commands to fix these:

sudo chmod 444 /srv/www/d8/public_html/sites/default/settings.php

sudo chmod -R 755 /srv/www/d8/public_html/sites/default/files/

You should now have a working Drupal 8 installation.

15

Visit the ‘admin/reports/status’ page first and deal with any issues you find there. We will cover file and directory permissions in another post.