How to install mcrypt PHP module on Ubuntu 18.04 Linux


The objective is to install mcrypt PHP module on Ubuntu 18.04 Linux

Operating System and Software Versions

  • Operating System: – Ubuntu 18.04 Linux
  • Software: – PHP 7.2 or higher


Privileged access to your Ubuntu System as root or via sudo command is required.




  • # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ – given linux commands to be executed as a regular non-privileged user


PHP installation

Most likely you PHP is already installed but any attempt to install the mcrypt PHP module fails with an error message:

E: Package 'php-mcrypt' has no installation candidate

If this is so, simply skip this step. Alternatively, perform a basic PHP installation:

$ sudo apt install php

Next, check whether the mcrypt PHP module is present:

$ php -m | grep mcrypt

Install Prerequisites

To install the mcrypt PHP module we first need to satisfy the following prerequisites:

$ sudo apt install php-dev libmcrypt-dev php-pear

Install mcrypt PHP module

Now we are ready to install mcrypt PHP module on our Ubuntu 18.04 system:

$ sudo pecl channel-update
$ sudo pecl install mcrypt-1.0.1
Build process completed successfully
Installing '/usr/lib/php/20170718/'
install ok: channel://
configuration option "php_ini" is not set to php.ini location
You should add "" to php.ini

Lastly, as suggested by the compilation output we need to enable the mcrypt PHP module within appropriate php.ini file. Your configuration may be different, the below serves only as a solution to the default PHP CLI configuration. Open the /etc/php/7.2/cli/php.ini file and insert:

Please note that if you are using Apache or Nginx web-server or another PHP version the location of the loaded php.ini file may be different.

All done. When successful, checking for the presence of the mcrypt PHP module should produce the following output:

$ php -m | grep mcrypt

Comments and Discussions
Linux Forum