php-mcrypt package missing in Ubuntu Server 18.04 LTS

Is the php-mcrypt package missing in Ubuntu Server 18.04 LTS?

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

Solution 1:

Mcrypt has been deprecated in PHP 7.2, so it's not available by default.

You can still install the mcrypt extension using pecl. These instructions are for the apache web server.

# Install prerequisites
sudo apt-get install php-dev libmcrypt-dev gcc make autoconf libc-dev pkg-config

# Compile mcrypt extension
sudo pecl install mcrypt-1.0.1
# Just press enter when it asks about libmcrypt prefix

# Enable extension for apache
echo "extension=mcrypt.so" | sudo tee -a /etc/php/7.2/apache2/conf.d/mcrypt.ini

# Restart apache
sudo service apache2 restart

That should get you going.

In the long term you might want to replace mcrypt, it's deprecated for a reason.

Solution 2:

I did the following to get this working...

sudo add-apt-repository ppa:ondrej/php
sudo apt-get install php7.1-mcrypt

If you're running php5.6 or 7.0 then you can use the following

sudo apt-get install php5.6-mcrypt
sudo apt-get install php7.0-mcrypt