How to use Composer to install a Drupal 8 module with Dependency on an External library …
A general introduction to the topic ;

Drupal is an open-source content management system characterized by its flexibility , security, extensibility and most importantly its active community.
As above stated , extensibility is an important feature of Drupal which is possible solely due to the use of modules which might be installed and uninstalled as desired .
While the installation of most modules are pretty direct , there are some modules like PHPSecLib Encryption module(the one we will be working on in this tutorial ) with dependency on an External library .
On a quick and simplified note , a dependency is anything that you need for your code to work and in this particular case the PHP Secure Communications Library is needed !!!!
To install this module , composer is therefore required …
Composer — Background Knowledge …
- What is Composer ?
Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

- Context-wise ;
Drupal uses Composer to manage the various libraries that it depends on. Modules can also use Composer to include 3rd party libraries.
- To be able to use composer into any of your projects (Drupal or not ) ,it is essential for you to have
composer.json
file in your directory .This file basically describes the dependencies of your project coupled with metadata sometimes. In short ,composer.json
is the configuration for your project - Package name versus Package version constraints
While the package name is made up of the Vendor’s name and the project name , the Package version constraints indicates the development branch which is to be used.
Generally the naming convention for package name is ; vendorname/projectname
The installation process ‘ installing the PHPSecLib Encryption module on Drupal 8
Step 1 ‘ Installing composer on Ubuntu 18.04
As stated above ,composer is essential to install the PHPSecLib Encryption module. To get the latest version of composer , carry out the following steps in the listed order ;
- Update the packages index and install the necessary requirements:
1.sudo apt update
2.sudo apt install wget php-cli php-zip unzip

2. Once php-cli installed on our system , download the composer installer :
Note ; This will download the composer-setup.php
file in the current working directory.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

3. Before proceeding , it is important to verify the data integrity of the script by comparing the script SHA-384
hash with the latest installer hash found on the Signatures page .
The command will store in the downloaded signature in a variable called “HASH”
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
4. Check whether the document is not corrupted using
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
If everything works perfect , you will see the following display screen along with the output “ installer verified”.Otherwise , you will have to redownload the composer installation script and double check the value of the $HASH
variable with echo $HASH

5. Download installer using :
Note ; This command as you may see it will download composer into /usr/local/bin . You may change this directory by altering the command and inserting a new directory with respect to your needs and requirements …
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

6. Finally , check whether Composer is installed using :
$ composer
Step ;2 ; Installing the PHPSecLib Encryption module
Once composer installed on your system , you might proceed to installing the module .
In order to be able to view it on your localhost/drupal
, it is advisable that you install it in your Drupal root directory /var/www/html/drupal-in my case
To install this module or any other module using composer , run in terminal ;
Note ;Ensure the module you want to download is available on Drupal.org …Otherwise this command wont work
P.S ; You might need to put the sudo prefix in case of errors
composer require drupal/module_name
Consequently , to install PHPSecLib Encryption module , run ;
composer require drupal/encrypt_seclib

Step ; 3 : Installing the module on your localhost site
Ok guys , so we are nearly done … To finish the installation , proceed to your localhost drupal site ( localhost/drupal -in my case ) … Go to the option extend …
/admin/modules

Look for encryption and enable the PHPSecLib Encryption module as shown above … click on install module !!!
You will normally be prompted with a confirmation box. You should select continue …

Once installed , you can go configuration/system/encryptionprofiles/
and click on Add Encryption Profile
. Once there , select “ add encryption method “ and CONGRATULATE yourself upon seeing the option PHP Secure Communications Library (PHPSecLib)
… This ensures that the installation has successfully been completed…

That's it guys , you know how to install a Drupal 8 module with Dependency on an External library.
P.S ; This tutorial generally applies to all Drupal 8 module with Dependency on an External Library . PHPSecLib Encryption module is only one example …
Errors i faced and how i solved them ;
- I took some time to figure it out but curl for php 7.2( my php version) was missing from my system …This delayed the whole process since i was getting an error message while trying to download the above listed module as shown below

- How i solved this error ;
- Firstly ,i Installed PHP libraries for my Server
sudo add-apt-repository ppa:ondrej/php

2. I then updated the server
sudo apt update
3. Lastly , i installed curl for PHP 7.2
sudo apt install php7.2-fpm php7.2-gd php7.2-curl php7.2-mysql php7.2-dev php7.2-cli php7.2-common php7.2-mbstring php7.2-intl php7.2-zip php7.2-bcmath

Problem solved !!!!
To Sum Up ;
Well yeah , this installation introduced me to a number of new things such as Composer and other related things … even curl introduced itself !!!
I hope you guys enjoy this one … On this … Bye Bye … Have fun Drupalling
Sources
https://www.tecrobust.com/how-to-install-php-7-2-curl-on-ubuntu-18-04-18-04-2-19-04-edition/;
https://linuxize.com/post/how-to-install-and-use-composer-on-ubuntu-18-04/