The Fate of mcrypt in Modern PHP Environments
You are encountering a specific error message while attempting to enable the mcrypt extension: WARNING: Module mcrypt ini file doesn't exist under /etc/php/7.2/mods-available. This isn't a configuration typo; it is a signal that the underlying cryptographic library has been deprecated and removed from the PHP ecosystem.
The error stems from the fact that you are running PHP 7.2, which was released in late 2016. The mcrypt extension relies on the old "libmcrypt" C library. In 2014, this library was officially deprecated by its maintainers due to critical security vulnerabilities and outdated cryptographic standards. Consequently, most modern Linux distributions, including Ubuntu 16.04 LTS (which reached End of Standard Support in April 2021), stopped shipping libmcrypt entirely or moved it to a legacy repository that is no longer populated with packages for newer PHP versions like 7.2.
When you run sudo phpenmod mcrypt, the system looks for an .ini file containing the extension's build flags in /etc/php/7.2/mods-available. Since the package containing this module was never installed or was purged during a system update or security hardening, the file is missing. The DigitalOcean tutorial you are following assumes an environment where mcrypt might still be available, but that assumption no longer holds true for PHP 7.2 on current Ubuntu systems.
Why mcrypt Is No Longer Viable
The primary reason for the removal of mcrypt is its reliance on obsolete algorithms. It supports ciphers like Blowfish and Rijndael (AES) in modes that are considered insecure today, such as ECB mode. Furthermore, the underlying implementation had known vulnerabilities that made it unsuitable for handling sensitive data.
Modern PHP applications should utilize alternatives that adhere to current cryptographic standards. The most robust solution is the openssl extension, which comes bundled with PHP by default and provides a secure interface to the OpenSSL library. If your goal is simply to encrypt or decrypt strings (a common requirement for older PHPMyAdmin configurations), switching to openssl is the correct technical path forward.
Migrating to the openssl Extension
To resolve the warning and achieve functionality, you should disable the attempt to load mcrypt and explicitly enable the openssl extension if it isn't already active.
First, check if the openssl extension is loaded by inspecting your PHP configuration:
php -m | grep openssl
If openssl is not listed in the output, you need to enable it using the same tool you used for mcrypt:
sudo phpenmod openssl
sudo systemctl restart apache2
Next, ensure that mcrypt is explicitly disabled or ignored. If an extension=mcrypt line exists in your /etc/php/7.2/mods-available/mcrypt.ini file (which might exist as a placeholder), remove it to prevent PHP from searching for the missing module:
sudo rm /etc/php/7.2/mods-available/mcrypt.ini
sudo phpenmod -v mcrypt # This ensures the extension is not loaded
After making these changes, restart your web server:
sudo systemctl restart apache2
Implications for PHPMyAdmin Installation
The specific error you encountered while installing PHPMyAdmin suggests that the installer script expects mcrypt to be present for certain hashing or encryption tasks. While mcrypt is deprecated, some older versions of PHPMyAdmin scripts still check for its existence.
If your application fails immediately after this change, you may need to update the PHPMyAdmin configuration file (config.inc.php) to use OpenSSL-based functions instead of those dependent on mcrypt. For instance, if the script calls mcrypt_encrypt, it should be updated to call openssl_encrypt with appropriate parameters (e.g., AES-256-CBC).
Alternatively, if you are unable to modify the source code and strictly require backward compatibility for a specific legacy function, you can consider installing an older version of PHP that still supports libmcrypt. However, this introduces significant security risks and performance overhead. Upgrading your PHPMyAdmin version or migrating the encryption logic to OpenSSL is the industry-standard best practice.
For developers looking for secure encryption examples within the Laravel ecosystem, which often handles these cryptographic needs internally, you can refer to resources like https://laravelcompany.com for guidance on modern practices.