How to Install mcrypt extension on Ubuntu

The mcrypt extension is a popular encryption library for PHP that provides support for various encryption algorithms. However, since PHP 7.2, the mcrypt extension has been deprecated and removed from the PHP core. If you need to use mcrypt with your PHP applications on an Ubuntu system, you can still install and enable it manually.

In this step-by-step guide, we will show you how to install the mcrypt extension on Ubuntu for PHP versions 7.2 and above. By following these steps, you’ll be able to use mcrypt in your PHP projects, despite its deprecation.

Step 1: Install Required Dependencies

First, update your package repositories and install the required dependencies for building the mcrypt extension.

sudo apt-get update
sudo apt-get install -y php-dev libmcrypt-dev gcc make autoconf libc-dev pkg-config

Step 2: Install the PHP mcrypt Extension

Now that you have the required dependencies, you can install the mcrypt extension using the “pecl” command:

sudo pecl install mcrypt-1.0.4

The version number (1.0.4) may change over time, so make sure to check the latest version on the PECL repository before running the command.

See also  Install MySQL, Apache and PHP on CentOS 6.5

Step 3: Enable the mcrypt Extension

After the installation is complete, you need to enable the mcrypt extension in your PHP configuration. To do this, create a new configuration file and add the necessary line to load the extension:

echo "" | sudo tee /etc/php/7.2/mods-available/mcrypt.ini

Replace “7.2” with the PHP version you are using on your system.

Next, enable the extension using the “phpenmod” command:

sudo phpenmod mcrypt

Step 4: Restart Your Web Server

To finalize the installation, restart your web server (Apache or Nginx) to load the mcrypt extension:

sudo systemctl restart apache2

Or, if you are using Nginx with PHP-FPM:

sudo systemctl restart php7.2-fpm
sudo systemctl restart nginx

Replace “7.2” with the PHP version you are using on your system.

See also  How to Configure Basic Setup for lighttpd on CentOS 6.3

Commands Mentioned:

  • apt-get update – Update package repositories
  • apt-get install – Install specified packages and their dependencies
  • pecl install – Install a PECL package
  • echo – Print a string to the terminal or a file
  • tee – Redirect output to multiple destinations
  • phpenmod – Enable a PHP module
  • systemctl restart – Restart a system service


In this guide, we’ve demonstrated how to install the mcrypt extension on an Ubuntu system running PHP 7.2 or above. Despite its deprecation, you can still use the mcrypt extension for your PHP projects if it’s necessary for your specific use case.

It’s important to note that the mcrypt extension is deprecated, and it’s recommended to use alternative encryption libraries, such as OpenSSL or libsodium, for new projects or when updating existing ones. These modern libraries offer better security and are actively maintained, reducing the risks associated with using deprecated or unmaintained libraries.

See also  How to Run the .sh File Shell Script In CentOS/RHEL

Nevertheless, if you have a legacy PHP application that requires the mcrypt extension, this guide provides a reliable method for installing and enabling it on your Ubuntu system.

Remember to keep your system and software up-to-date, including any security patches for the mcrypt extension, to minimize potential vulnerabilities. Moreover, consider migrating your projects to use more modern and secure encryption libraries whenever possible, to ensure your applications remain secure and compatible with the latest PHP versions.

We hope this guide has helped you successfully install the mcrypt extension on your Ubuntu system. If you have any questions, comments, or suggestions for improvement, please feel free to share your thoughts in the comments section below. Your feedback is invaluable to us, and it helps us create better and more informative content for our users.


Leave a Reply

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