Skip to content
Related Articles

Related Articles

How to Install mcrypt extension on Ubuntu?

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 06 Apr, 2022

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

Verifying-PHP-mcrypt-installation

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

Installing-some-tools-to-build

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

Update-the-channel-for-PEAR-and-PECL

Step 3: To download and install php-mcrypt extension on Ubuntu system, we use the Pecl command:

sudo pecl install mcrypt

Download-and-install-php-mcrypt-extension

Press ENTER and proceed 

Press-Enter-to-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

Open-php.ini-file

Now edit the php.ini file and under Dynamic extension, type: extension=mcrypt.so beside other extensions, as shown in the screenshot.

Editing-the-php.ini-file

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

Open-php.ini-file

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 mcrpty 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.

Verifying-the-installation

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!