← ServerPilot Docs

How to Install the PHP mcrypt Extension

In the examples shown, replace "X.Y" with your app's PHP version (for example, "7.2").

The mcrypt extension is an interface to the mcrypt cryptography library. This extension is useful for allowing PHP code using mcrypt to run on PHP 7.2+.

The mcrypt extension is included in PHP 5.4 through PHP 7.1. It was removed from PHP 7.2 and moved to an unofficial PECL extension because the mcrypt library is no longer maintained.

For PHP 7.2+, PHP instead uses libsodium as a cryptography library. ServerPilot builds PHP 7.2+ with the official libsodium extension. New PHP code should be written to use libsodium rather than mcrypt.

Installing mcrypt on PHP 5, PHP 7.0, and PHP 7.1

You do not need to install the mcrypt extension on PHP 5, 7.0, or 7.1. ServerPilot builds these PHP versions with the mcrypt extension so it is always available.

Installing mcrypt on PHP 7.2, 7.3, or 7.4

To install this extension on PHP 7.2 through 7.4, run the following commands as your server's root user:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install libmcrypt-dev
sudo pecl7.2-sp install --nodeps mcrypt-snapshot

When you are shown the prompt

libmcrypt prefix? [autodetect] :

Press Enter to autodetect.

Once installed, create a configuration file for the extension and restart PHP by running the following commands as root:

sudo bash -c "echo extension=mcrypt.so > /etc/php7.2-sp/conf.d/mcrypt.ini"
sudo service php7.2-fpm-sp restart

Verifying mcrypt Is Installed

You can check that the extension was installed with this command:

php7.2-sp -i | grep mcrypt

The output will look like this:

$ php7.2-sp -i | grep mcrypt
/etc/php7.2-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.*
mcrypt
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value

Uninstalling the Mcrypt Extension

To uninstall this extension, as root run the commands:

sudo rm /etc/phpX.Y-sp/conf.d/mcrypt.ini
sudo peclX.Y-sp uninstall mcrypt

Next, restart PHP-FPM with the command:

sudo service phpX.Y-fpm-sp restart
Last updated: October 8, 2018

Launch your first site in 5 minutes