Install the PHP mcrypt extension
The mcrypt extension provides PHP functions for using the mcrypt cryptography library.
For PHP 5.6 through PHP 7.1, the mcrypt extension is installed by default. You do not need to install the mcrypt extension for these PHP versions.
Starting with PHP 7.2, the mcrypt extension was removed from PHP and must be installed as a third-party extension using the instructions below.
Install the mcrypt extension
Installing the extension involves the following steps:
- Install build dependencies (packages that are required to build the extension).
- Build the extension’s library file.
- Enable the extension in the PHP configuration.
Install build dependencies
Set environment variables for the package manager.
export DEBIAN_FRONTEND=noninteractiveInstall a compiler and other packages that are required for building PHP extensions.
sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-configInstall additional packages that are required to build the mcrypt extension.
sudo apt-get -y install libmcrypt-devBuild the extension
The PECL install command compiles the extension’s .so library file.
sudo yes '' | pecl8.5-sp install --nodeps mcrypt-snapshotsudo yes '' | pecl8.4-sp install --nodeps mcrypt-snapshotsudo yes '' | pecl8.3-sp install --nodeps mcrypt-snapshotsudo yes '' | pecl8.2-sp install --nodeps mcrypt-snapshotsudo yes '' | pecl8.1-sp install --nodeps mcrypt-snapshotsudo yes '' | pecl8.0-sp install --nodeps mcrypt-snapshotsudo yes '' | pecl7.4-sp install --nodeps mcrypt-snapshotsudo yes '' | pecl7.3-sp install --nodeps mcrypt-snapshotsudo yes '' | pecl7.2-sp install --nodeps mcrypt-snapshotEnable the extension
Configure PHP to load the extension.
sudo bash -c "echo extension=mcrypt.so > /etc/php8.5-sp/conf.d/mcrypt.ini"sudo bash -c "echo extension=mcrypt.so > /etc/php8.4-sp/conf.d/mcrypt.ini"sudo bash -c "echo extension=mcrypt.so > /etc/php8.3-sp/conf.d/mcrypt.ini"sudo bash -c "echo extension=mcrypt.so > /etc/php8.2-sp/conf.d/mcrypt.ini"sudo bash -c "echo extension=mcrypt.so > /etc/php8.1-sp/conf.d/mcrypt.ini"sudo bash -c "echo extension=mcrypt.so > /etc/php8.0-sp/conf.d/mcrypt.ini"sudo bash -c "echo extension=mcrypt.so > /etc/php7.4-sp/conf.d/mcrypt.ini"sudo bash -c "echo extension=mcrypt.so > /etc/php7.3-sp/conf.d/mcrypt.ini"sudo bash -c "echo extension=mcrypt.so > /etc/php7.2-sp/conf.d/mcrypt.ini"Restart PHP-FPM.
sudo service php8.5-fpm-sp restartsudo service php8.4-fpm-sp restartsudo service php8.3-fpm-sp restartsudo service php8.2-fpm-sp restartsudo service php8.1-fpm-sp restartsudo service php8.0-fpm-sp restartsudo service php7.4-fpm-sp restartsudo service php7.3-fpm-sp restartsudo service php7.2-fpm-sp restartVerify the extension is enabled in PHP.
php8.5-sp -i | grep mcryptphp8.4-sp -i | grep mcryptphp8.3-sp -i | grep mcryptphp8.2-sp -i | grep mcryptphp8.1-sp -i | grep mcryptphp8.0-sp -i | grep mcryptphp7.4-sp -i | grep mcryptphp7.3-sp -i | grep mcryptphp7.2-sp -i | grep mcryptIf the extension is enabled, you will see output like the following.
/etc/phpX.Y-sp/conf.d/mcrypt.ini,Registered Stream Filters => zlib.*, convert.iconv.*, bzip2.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, mcrypt.*, mdecrypt.*mcryptmcrypt support => enabledmcrypt_filter support => enabledmcrypt.algorithms_dir => no value => no valuemcrypt.modes_dir => no value => no valueUninstall the mcrypt extension
Uninstalling the extension involves the following steps:
- Disable the extension in the PHP configuration.
- Remove the extension’s library file.
Disable the extension
Remove the extension’s configuration from PHP.
sudo rm /etc/php8.5-sp/conf.d/mcrypt.inisudo rm /etc/php8.4-sp/conf.d/mcrypt.inisudo rm /etc/php8.3-sp/conf.d/mcrypt.inisudo rm /etc/php8.2-sp/conf.d/mcrypt.inisudo rm /etc/php8.1-sp/conf.d/mcrypt.inisudo rm /etc/php8.0-sp/conf.d/mcrypt.inisudo rm /etc/php7.4-sp/conf.d/mcrypt.inisudo rm /etc/php7.3-sp/conf.d/mcrypt.inisudo rm /etc/php7.2-sp/conf.d/mcrypt.iniRestart PHP-FPM.
sudo service php8.5-fpm-sp restartsudo service php8.4-fpm-sp restartsudo service php8.3-fpm-sp restartsudo service php8.2-fpm-sp restartsudo service php8.1-fpm-sp restartsudo service php8.0-fpm-sp restartsudo service php7.4-fpm-sp restartsudo service php7.3-fpm-sp restartsudo service php7.2-fpm-sp restartRemove the extension
The PECL uninstall command removes the extension’s .so library file.
sudo pecl8.5-sp uninstall mcryptsudo pecl8.4-sp uninstall mcryptsudo pecl8.3-sp uninstall mcryptsudo pecl8.2-sp uninstall mcryptsudo pecl8.1-sp uninstall mcryptsudo pecl8.0-sp uninstall mcryptsudo pecl7.4-sp uninstall mcryptsudo pecl7.3-sp uninstall mcryptsudo pecl7.2-sp uninstall mcrypt