Introduction
The mcrypt PHP extension was once widely used for encryption and decryption in PHP applications. Although it has been deprecated in newer PHP versions, some legacy applications still depend on it to function correctly. In such cases, Install PHP mcrypt extension on Ubuntu becomes necessary to maintain compatibility.
In this blog, we’ll walk through the steps to install and activate the PHP mcrypt extension on an Ubuntu server, following standard and reliable practices.
Why mcrypt Is Needed
Some older PHP frameworks, CMS platforms, or custom applications rely on mcrypt for cryptographic operations. When migrating servers or upgrading PHP versions, these applications may throw errors like:
- Call to undefined function mcrypt_encrypt()
- mcrypt extension not loaded
Installing mcrypt resolves these compatibility issues.
Installing PHP mcrypt on Ubuntu
Step 1: Update the System
Before installing any packages, make sure your system repositories are up to date:
sudo apt update
Step 2: Install Required Dependencies
Install the necessary development libraries:
sudo apt install libmcrypt-dev php-dev
Step 3: Install mcrypt Using PECL
Since mcrypt is no longer bundled with PHP, it must be installed via PECL:
sudo pecl install mcrypt
During installation, press Enter to accept default values when prompted.
Enable the mcrypt Extension
Once installed, enable the extension by creating the configuration file:
echo "extension=mcrypt.so" | sudo tee /etc/php/8.1/mods-available/mcrypt.ini
Make sure to replace 8.1 with your actual PHP version.
Then enable it:
sudo phpenmod mcrypt
Restart Web Services
Restart your web server to apply changes:
sudo systemctl restart apache2
or, if using PHP-FPM:
sudo systemctl restart php8.1-fpm
Verify Installation
Confirm that mcrypt is enabled:
php -m | grep mcrypt
Or check via a phpinfo() page in your browser vc
Conclusion
Although mcrypt is deprecated, it remains essential for running certain legacy PHP applications. By installing it via PECL and enabling it correctly on Ubuntu, you can ensure backward compatibility without breaking existing functionality.
For new projects, it’s strongly recommended to migrate to modern encryption libraries like OpenSSL or Sodium, which are actively maintained and more secure.
If you still face issues or want expert help to Install PHP mcrypt extension on Ubuntu, Skynats’ professional server management services are here to assist. Our certified engineers handle PHP configuration, Linux troubleshooting, and performance optimization so you can focus on your business without server headaches. Contact Skynats today for reliable, 24/7 server support.