The PHP-Mcrypt Installation Gap on CentOS 6
Encountering the No package php-mcrypt available error on CentOS 6 is a classic frustration for developers maintaining legacy infrastructure. You verify that EPEL is installed, you toggle centosplus repositories with and without the flag, and you confirm that the underlying C library (mcrypt) is functional. Yet, the package manager remains stubbornly silent. The root cause isn't a broken repository; it is a deliberate architectural shift in the CentOS project that often catches developers off guard.
In modern Linux distributions, the community generally moved away from php-mcrypt. However, on CentOS 6, the situation is nuanced. While the base repositories and even EPEL might not list php-mcrypt directly as an installable unit in some contexts or specific mirror configurations, the package actually exists within the centosplus repository, but it requires a specific version of PHP to function correctly.
The command you are running, yum install php-mcrypt --enablerepo=centosplus, is technically correct, yet it frequently fails if the underlying system state does not match the package requirements. The most common pitfall on CentOS 6.4 64-bit is a version mismatch between the PHP interpreter and the PECL extension. If your system has php version 5.4.x or earlier, the corresponding php-mcrypt might be absent or flagged as unsatisfiable dependencies because the PECL build for that specific PHP release was deprecated in favor of internal implementations or stripped out entirely to encourage migration to OpenSSL-based cryptography.
Before proceeding with any manual compilation, you must verify which version of PHP is actually running. Run the following command:
php -v
If you are on a version prior to 5.4.8, you may not find php-mcrypt in the package index because CentOS 6 updates often dropped support for extensions that relied heavily on deprecated algorithms like MCRYPT_RIJNDAEL_128. If your PHP version is compatible but the package still refuses to install, the issue lies with the centosplus repository metadata. Sometimes, the mirror caches are stale or the repository definition in /etc/yum.repos.d/CentOS-Plus.repo is misconfigured for your specific hostname's DNS resolution.
If standard installation fails, you have two primary paths forward. The first is to manually compile the extension. This approach is superior if you require a specific version of MCrypt that matches your PHP build exactly. You would need to install php-devel, mcrypt, and gcc before extracting the PECL source tarball. This ensures binary compatibility, though it adds maintenance overhead.
The second path involves migrating to the OpenSSL extension. In many production scenarios involving Laravel or modern PHP stacks, relying on legacy MCRYPT is no longer recommended due to security vulnerabilities in the underlying algorithms (such as DES and Blowfish). The php-openssl package is available in EPEL and provides robust cryptographic capabilities without the bloat of the deprecated MCRYPT library.
If you are maintaining a legacy application that strictly requires php-mcrypt, ensure that your system is updated to the latest point releases for CentOS 6, specifically looking for patches that reintroduced the PECL package into the standard repo or fixed the dependency hell between PHP and the extension. However, if your goal is simply to enable encryption features in a new project, compiling from source or switching to OpenSSL is the technically sound decision.
For those running Laravel on older CentOS instances, note that newer versions of the framework have dropped support for MCRYPT entirely. If you are migrating a legacy app, it is often more efficient to rewrite the encryption logic using openssl_encrypt and openssl_decrypt. This aligns your stack with current security standards and avoids the headache of maintaining obsolete packages.
Ultimately, the error message is not a bug; it is a signal that your environment has outpaced the package availability in its current state. Whether you choose to compile from source or pivot to OpenSSL depends on whether you are patching legacy code or building something new.
