How to Install PHP 7.2-mcrypt Module on Ubuntu Linux

Computer screen with mobile devices
Computer screen with mobile devices

Have you noticed PHP-7.2 doesn’t support the mcrypt module anymore? Try installing it, and you’ll get an error that the package can’t be found or there is no installation candidate. For new users and students looking for help, the steps below should be a great place to start.

You may want to ask why the mcrypt module is no longer supported with PHP-7.2. Again, there may be a legitimate reason not to support it.

If you are running a PHP application that relies on the mcrypt module and wants to upgrade to PHP 7.2, then continue with the post below to learn how to install PHP 7.2 mcrypt module on Ubuntu 18.04 LTS servers and desktops.

To get started with installing the module, follow the steps below:

Install PHP-7.2

Before installing the mcrypt module, you must first install PHP-7.2 on Ubuntu. To do that, run the commands below:

sudo apt install php-7.2

After installing PHP above, continue below to install the required dependencies that will allow you to install the mcrypt module.

Install Required PHP Dependencies to Install Mcrypt

Now that PHP-7.2 is installed, run the commands below to install the required dependencies that will allow the mcrypt module to be installed on Ubuntu with PHP-7.2 support. To install the necessary packages, run the commands below.

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

After that, continue below to install mcrypt.

Now that PHP-7.2 and all its required dependencies to install mcrypt, run the commands below to install the PHP mcrypt module on Ubuntu using the pecl channel.

sudo pecl channel-update
sudo pecl install mcrypt-1.0.1

After running the commands above, you should see a message that reads PHP mcrypt module was successfully installed. And that you should include the mcrypt. So extension in the php.ini file.

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

Finally, run the commands below to open the PHP configuration file.

sudo nano /etc/php/7.2/cli/php.ini

Then add the line below into the file, just below [PHP], and save.

Save the file, and you’re done.

If you’re using an Apache2 HTTP server with PHP support, you may also want to add the extension to the php.ini file below:

sudo nano /etc/php/7.2/apache2/php.ini

For Nginx, use this:

sudo nano /etc/php/7.2/fpm/php.ini

Now the mcrypt module should be installed and ready to use.


You may also like the post below:

Posted by

I love computers; maybe way too much. What I learned I try to share at


  1. I follow your introduction, but in Step2, libmcrypt-dev can’t be installed successfully, Ubuntu18.04.1LTS responses:
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package libmcrypt-dev

    Any suggestion?

  2. Not a PHP expert, but I think you can simplify the instructions by enabling mcrypt as a module across all your various php.ini configs (cli, apache, fpm):

    sudo su -c “echo “” > /etc/php/7.2/mods-available/mcrypt.ini”
    sudo phpenmod mcrypt

  3. mcrypt version 1.0.2 is out!

  4. Another possibility would be to install

  5. This really helped a bunch. Thanks so much!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: