Install PHP mcrypt extension on Ubuntu 20.04 | 18.04

You can support us by downloading this article in PDF format via the link below.

Download the guide in PDF format

turn off


How can I solve”E: There is no candidate installation for the package “php-mcrypt”“On Ubuntu 20.04/18.04? Today’s guide will explain how to install the PHP mcrypt extension on Ubuntu 20.04/18.04. The PHP mcrypt extension is an interface to the mcrypt password library, which supports multiple block algorithms such as DES, TripleDES, Blowfish (default ), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and CBC, OFB, CFB and ECB GOST in password mode.

If you try to install mcrypt using apt, you will receive an error message:

$ sudo apt install php-mcrypt
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package php-mcrypt is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'php-mcrypt' has no installation candidate

The mcrypt extension has been moved to the PECL repository and has not been bundled with PHP since PHP 7.2.0. PECL is a repository of all known PHP extensions, where users can download and host developed PHP extensions.

Tell your operating system to extract the latest list of packages available in the installation repository:

sudo apt update

Install development tools on Ubuntu:

sudo apt update
sudo apt install -y build-essential

Confirm make and gcc:

$ gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

$ make --version
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

You need to install PHP, dev and pear extensions on Ubuntu 20.04 | 18.04 first.

sudo apt install php php-pear php-dev libmcrypt-dev

Confirm that the pecl command is available on your system.

$ which pecl 

PECL usage:

$ pecl help
build                  Build an Extension From C Source
bundle                 Unpacks a Pecl Package
channel-add            Add a Channel
channel-alias          Specify an alias to a channel name
channel-delete         Remove a Channel From the List
channel-discover       Initialize a Channel from its server
channel-info           Retrieve Information on a Channel
channel-login          Connects and authenticates to remote channel server
channel-logout         Logs out from the remote channel server
channel-update         Update an Existing Channel
clear-cache            Clear Web Services Cache
config-create          Create a Default configuration file
config-get             Show One Setting
config-help            Show Information About Setting
config-set             Change Setting
config-show            Show All Settings
convert                Convert a package.xml 1.0 to package.xml 2.0 format
cvsdiff                Run a "cvs diff" for all files in a package
cvstag                 Set CVS Release Tag
download               Download Package
download-all           Downloads each available package from the default channel
info                   Display information about a package
install                Install Package
list                   List Installed Packages In The Default Channel
list-all               List All Packages
list-channels          List Available Channels
list-files             List Files In Installed Package
list-upgrades          List Available Upgrades
login                  Connects and authenticates to remote server [Deprecated in favor of channel-login]
logout                 Logs out from the remote server [Deprecated in favor of channel-logout]
makerpm                Builds an RPM spec file from a PEAR package
package                Build Package
package-dependencies   Show package dependencies
package-validate       Validate Package Consistency
pickle                 Build PECL Package
remote-info            Information About Remote Packages
remote-list            List Remote Packages
run-scripts            Run Post-Install Scripts bundled with a package
run-tests              Run Regression Tests
search                 Search remote package database
shell-test             Shell Script Test
sign                   Sign a package distribution file
svntag                 Set SVN Release Tag
uninstall              Un-install Package
update-channels        Update the Channel List
upgrade                Upgrade Package
upgrade-all            Upgrade All Packages [Deprecated in favor of calling upgrade with no parameters]
Usage: pecl [options] command [command-options] 
Type "pecl help options" to list all options.
Type "pecl help shortcuts" to list all command shortcuts.
Type "pecl help version" or "pecl version" to list version information.
Type "pecl help " to get the help for the specified command.

Update channel:

$ sudo pecl channel-update
Updating channel ""
Update of Channel "" succeeded

$ sudo pecl update-channels
Updating channel ""
Update of Channel "" succeeded
Updating channel ""
Update of Channel "" succeeded
Updating channel ""
Channel "" is up to date

Let’s search for mcrypt extension.

$ sudo pecl search mcrypt
Matched packages, channel
Package       Stable/(Latest) Local
mcrypt        1.0.3 (stable)        Bindings for the libmcrypt library
mcrypt_filter 0.1.0 (beta)          Applies mcrypt symmetric encryption using stream filters

You can use the pecl command with installation options to install the mcrypt extension.

$ sudo pecl install mcrypt
downloading mcrypt-1.0.3.tgz ...
Starting to download mcrypt-1.0.3.tgz (33,590 bytes)
.........done: 33,590 bytes
6 source files, building
running: phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902

When you see the prompt

libmcrypt prefix? [autodetect] :

Press enter automatic detection.

After installing mcrypt extension on Ubuntu 20.04 Linux machine, you should get the following output.

Build process completed successfully
Installing '/usr/lib/php/20190902/'
install ok: channel://
configuration option "php_ini" is not set to php.ini location
You should add "" to php.ini

Enable the extension in the php.ini file.

Ubuntu 20.04:

$ sudo vim /etc/php/7.4/cli/php.ini

$ sudo vim /etc/php/7.4/apache2/php.ini

Ubuntu 18.04:

$ sudo vim /etc/php/7.2/cli/php.ini

$ sudo vim /etc/php/7.2/apache2/php.ini

You can use the following command to confirm that the module is installed and enabled:

$ php -m | grep mcrypt

If you use applications hosted by Apache or Nginx web server, please restart them.

--- Restart Apache web server ---
$ sudo systemctl restart apache2

--- Restart nginx web server ---
$ sudo systemctl restart nginx

This is how you can easily install the mcrypt PHP extension on Ubuntu 20.4 and Ubuntu 18.04 Linux systems.

PHP learning courses:

Complete Web Developer Course 2.0


$ 12.41

$ 225.71

In stock

Buy now

Install PHP mcrypt extension on Ubuntu 20.04 |


You can support us by downloading this article in PDF format via the link below.

Download the guide in PDF format

turn off