How to Install mcrypt extension on Ubuntu?
PHP mcrypt is an extension. It provides encryption facilities for web applications that require the functionality of modern algorithms such as AES. It works as interface to Mcrypt’s libmcrypt library which implements all the algorithms and modes available in it like GOST, RC2, RC6, MARS, etc. Here, .php extension means a plain text file that contains the source code written in the PHP language. Due to the lake of development in mcrypt the extension is vulnerable and can be decrypted so it removed from PHP package and move to the PHP Extension Community Library repository. So that if anybody required then they can easily install to the Linux machine using Pear.
Verify PHP mcrypt installation on Ubuntu
Open terminal on your Ubuntu system and type the following command to check whether mcrypt is installed or not.
php -m | grep mcrypt
If there is no result like shown in the above image, then follow the steps below to install php-mcrypt.
Installation of php-mcrypt
Step 1: For installing php-mcrypt on Ubuntu, we have to first install some tools that required to build packages from the source with some developer dependency packages. So to do this task we use the following command:
sudo apt install gcc make autoconf libc-dev pkg-config libmcrypt-dev php-pear php-dev -y
Step 2: Now update the channel for PEAR and PECL using the following commands:
sudo pecl channel-update pecl.php.net
sudo pecl update-channels
Step 3: To download and install php-mcrypt extension on Ubuntu system, we use the Pecl command:
sudo pecl install mcrypt
Press ENTER and proceed
Step 4: Enable “extension=mcrypt.so” via php.ini. So first type the following commands in the terminal to open php.ini file using nano editor.
sudo nano /etc/php/*/apache2/php.ini
Now edit the php.ini file and under Dynamic extension, type: extension=mcrypt.so beside other extensions, as shown in the screenshot.
Now save the file ctrl+X, type Y, and hit the Enter key. Again open the terminal and run the following command to edit the php.ini file stored at /etc/php/*/cli/php.ini
sudo vim /etc/php/*/cli/php.ini
Save the file ctrl+X, type Y, and hit the Enter key.
Step 5: Restart Apache server(Restart PC if necessary) to see the changes using the following command:
sudo systemctl restart apache2
Verifying the installation
To verify if the mcrypt extension is successfully installed or not using the following command:
php -m | grep mcrypt
If you get a message like in the below image then that means the extension is successfully installed in your system.
Contact Us