This article explains how to install the mcrypt PHP module on Ubuntu 24.04.
PHP mcrypt is a library that equips developers with various PHP encryption and decryption functions. It supports various encryption algorithms and modes, enabling developers to store and transmit sensitive data securely.
Although mcrypt was widely used for cryptographic operations before PHP 7.1, it has now been deprecated in favor of modern libraries such as OpenSSL and libsodium.
Installing it on Ubuntu might still be essential for older PHP applications that significantly depend on mcrypt for cryptography.
If you install mcrypt on Ubuntu, you can enable the required package using third-party package managers.
Install PHP
If you use the mcrypt module, you must have PHP installed.
If you haven’t already done so, the post below shows you how to install PHP.
After installing PHP, continue below.
Install recommended packages
After installing PHP, execute the command below to install recommended packages that will assist you in building and installing the mcrypt module.
sudo apt install gcc make autoconf libc-dev pkg-config libmcrypt-dev php-pear php-dev
Next, add and update the channel for PEAR and PECL using the command below.
sudo pecl channel-update pecl.php.net
sudo pecl update-channels
After that, run the command below to build and install mcrypt.
sudo pecl install mcrypt
Enable the mcrypt module
After installing the mcrypt module, you can enable it by including it with PHP. To do that, run the command below.
For Apache:Run:
sudo -s
echo extension=mcrypt.so > /etc/php/8.3/apache2/php.ini
echo extension=mcrypt.so > /etc/php/8.3/cli/php.ini
For Nginx:Run:
sudo -s
echo extension=mcrypt.so > /etc/php/8.3/fpm/php.ini
echo extension=mcrypt.so > /etc/php/8.3/cli/php.ini
After adding the module to the PHP configuration file, restart the web server and PHP.
Test PHP
To test and validate whether the mcrypt module is enabled, run the command below.
php -m | grep mcrypt
It should output mcrypt.
Or use the web.

That should do it!
Conclusion:
In summary, installing the mcrypt PHP module on Ubuntu is a straightforward process that can be crucial for supporting legacy applications. Here are the key takeaways:
- Understanding mcrypt: mcrypt provides essential encryption and decryption functions for PHP developers but is deprecated in newer PHP versions.
- Installation Prerequisites: Ensure PHP is installed before installing the mcrypt module.
- Recommended Packages: Install necessary packages such as gcc, make, and libmcrypt-dev to successfully build the mcrypt module.
- Enabling mcrypt: After installation, update the PHP configuration files for Apache and Nginx to enable the mcrypt extension.
- Testing the Installation: Verify that mcrypt is active using the command line or checking through a web interface.
By following these steps, you can ensure seamless integration of the mcrypt library into your older PHP applications.
Leave a Reply