How to Install mcrypt PHP Module on Ubuntu 24.04
The mcrypt PHP module provides encryption and decryption tools for older website code running on Ubuntu 24.04. PHP removed mcrypt from its core software back in version 7.2, which means modern servers no longer include it by default.
Old websites and legacy apps still need this module to work properly and process secure data without breaking. You can add mcrypt to Ubuntu 24.04 by using a trusted software repository maintained by Ondřej Surý, which bridges the gap between modern PHP 8.x versions and outdated code.
Install the mcrypt PHP module on Ubuntu 24.04 by first installing necessary development packages with `sudo apt install gcc make autoconf libc-dev pkg-config libmcrypt-dev php-pear php-dev`. Then, run `sudo pecl install mcrypt` and enable the module by adding `extension=mcrypt.so` to your `php.ini` files.
Install PHP
Verification of an existing PHP installation comes first. Reviewing the guide ‘How to install PHP on Ubuntu’ helps handle that setup beforehand. Continuing with the following instructions happens once PHP runs successfully.
Proceed below after completing the PHP setup.
Install recommended packages
Compiling the extension requires development tools like gcc (GNU Compiler Collection) and make, alongside PEAR and PECL (PHP’s package repositories). Running the command `sudo apt install gcc make autoconf libc-dev pkg-config libmcrypt-dev php-pear php-dev` prepares the system.
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
Enabling the module remains necessary for web servers and PHP applications after installation. PHP configuration files require a specific line added to function properly. Web server setups dictate which file to modify: Apache deployments utilize paths like `/etc/php/8.3/apache2/`, whereas Nginx with PHP-FPM points toward `/etc/php/8.3/fpm/` instead.
For Apache, add the extension to the configuration file using `sudo nano /etc/php/8.3/apache2/php.ini`.
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 with PHP-FPM, open the corresponding file located at `sudo nano /etc/php/8.3/fpm/php.ini` instead.
sudo -s
echo extension=mcrypt.so > /etc/php/8.3/fpm/php.ini
echo extension=mcrypt.so > /etc/php/8.3/cli/php.ini
Web servers and PHP services require a restart following configuration updates.
Test PHP
Terminal commands verify whether the module operates correctly after installation and configuration. Typing `php -m | grep mcrypt` and pressing Enter checks the status. Active modules output `mcrypt` on the screen to confirm readiness.
php -m | grep mcrypt
Output should display mcrypt.
Browser testing offers an alternative verification method.

Configuration finishes here.
Conclusion:
Running legacy software often demands extra configuration steps. Key takeaways include:
- 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.
Completing these installation steps bridges older PHP applications with the mcrypt library, restoring required encryption functions.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!