Install PHP 7.2-mcrypt Module on Ubuntu 18.04 LTS

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 are no installation candidate. For new users and students looking for help, the steps below should be a great place to start.

The question you may want to ask is why the mcrypt module is no longer supported with PHP-7.2? Again, there may be a legitimate reason not to support it. some have mentioned that it is for security reasons the module was dropped.. however, some PHP application still depend on this module to fucntion.

If you are running a PHP application that relies on the mcrypt module and you want 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:

Step 1: 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 required dependencies that will allow you to install the mcrypt module.

Step 2: Install Required PHP Dependencies to Install Mcrypt

Now that PHP-7.2 is installed, run the commands below to install required dependencies that will allow the mcrypt module to be installed on Ubuntu with PHP-7.2 support. To install the required 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 are installed, run the commands below to install PHP mcrypt module on Ubuntu using 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 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 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 going to be using Apache2 HTTP server with PHP support, you may also want to add the exetension 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: