How to install and enable Mcrypt extension for PHP + Nginx

Sometimes while installing WordPress plugins, you might come across a message to install / enable Mcrypt extension for PHP.
Mcrypt is an interface which supports a wide range of block algorithims. It support Algorithims like DES, TripleDES, GOST, OFB etc.

Note : The Mcrypt extension relies on the ‘libmcrypt’ extension, which is not maintained since 2007. So some people consider installing the extension useless. None the less some WordPress plugins do require this extension to be installed and enabled.

Step 1 : Download and isntall the mcrypt extension

apt-get install php5-mcrypt


Step 2 : Create a symlink for Mcrypt to mods-available

ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini

If you are running PHP-FPM your path might be like

ln -s /etc/php5/fpm/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini

If you get an error message like:

ln: failed to create symbolic link ‘/etc/php5/mods-available/mcrypt.ini’: File exists

This means that the extension is already installed on your server and you just need to enable it by skipping to the next step.

Step 3 : Enable Mcrypt extension

php5enmod mcrypt

Step 4 Restart PHP and Nginx

service php5-fpm restart
service nginx restart