How to Install PHP 7.2-mcrypt Module on Ubuntu Linux

|

|

PHP-7.2 no longer supports the mcrypt module. However, there are steps to install PHP 7.2 mcrypt module on Ubuntu 18.04 LTS servers and desktops. Initially, install PHP-7.2 on Ubuntu and its required dependencies including php-dev, libmcrypt-dev, and php-pear. Then, using the pecl channel, install the PHP mcrypt module, and subsequently make necessary configurations in the…

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 pecl.php.net
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/mcrypt.so'
install ok: channel://pecl.php.net/mcrypt-1.0.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=mcrypt.so" 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.

extension=mcrypt.so

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 mcrypt.so 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.

Enjoy!

You may also like the post below:

Like this:



5 responses to “How to Install PHP 7.2-mcrypt Module on Ubuntu Linux”

  1. Woo Hsutung Avatar
    Woo Hsutung

    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. benjaoming Avatar
    benjaoming

    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 “extension=mcrypt.so” > /etc/php/7.2/mods-available/mcrypt.ini”
    sudo phpenmod mcrypt

  3. theyosh Avatar
    theyosh

    mcrypt version 1.0.2 is out!

  4. tokencrumb Avatar
    tokencrumb

    Another possibility would be to install https://github.com/phpseclib/mcrypt_compat

  5. Al U Avatar
    Al U

    This really helped a bunch. Thanks so much!

Leave a Reply to theyosh Cancel reply

Your email address will not be published. Required fields are marked *

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