Issue in installing php7.2-mcrypt

Issue in installing php7.2-mcrypt

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Issue in installing php7.2-mcrypt

Attempting to install the mcrypt extension on PHP 7.2 often leads developers down a rabbit hole of deprecated binaries and broken command-line tools. The specific error you are encountering, sudo: pecl7.2-sp: command not found, is a direct symptom of trying to use an obsolete build tool that was never meant for production environments or has been removed from the system entirely.

The root of this problem lies in how the mcrypt extension evolved alongside PHP versions. The mcrypt extension was deprecated in PHP 7.1 and officially removed in PHP 7.2. Consequently, the community scripts and documentation found on older sites often suggest using a custom PECL channel like pecl7.2-sp. As you discovered via your terminal logs, this command does not exist on standard Ubuntu or Debian installations (specifically Xenial based on your package sources). The script referenced in older tutorials likely relied on a manual setup that is no longer available or functional, leading to the "command not found" error when executed.

Before attempting complex workarounds or downgrading your entire stack, it is crucial to understand the architectural implications of mcrypt. This extension relies on legacy cryptographic algorithms (like MCRYPT_RIJNDAEL_128) that are considered insecure by modern standards. Even if you successfully compile the extension using a custom PECL snapshot, you will inherit security vulnerabilities inherent to the algorithm itself. For new applications, switching to the openssl extension is the standard and secure practice.

However, legacy projects often require specific cryptographic functions provided only by mcrypt. If you are maintaining an older codebase that strictly depends on these functions and cannot migrate to OpenSSL immediately, you face a choice: compile the extension from source or downgrade the PHP version.

Compiling from Source (Advanced)

If your server environment permits it and you require PHP 7.2 specifically for other dependencies, compiling mcrypt manually is technically possible but fraught with caveats. The standard approach involves fetching the source code from a snapshot repository compatible with PHP 7.2, applying necessary patches to fix compilation errors on modern toolchains, and then running the PECL install command locally.

The process generally looks like this:

# Clone the specific mcrypt snapshot branch
git clone https://github.com/jamesgagel/mcrypt.git
cd mcrypt
git checkout php7.2-snapshot

# Compile with PHP 7.2 configuration
phpize
./configure --with-php-config=$(which php)

# Make and install
make clean
make
sudo make install

After installation, you must manually edit the php.ini file (located in /etc/php/7.2/mods-available/) to uncomment the line:

extension=mcrypt.so

Then restart your web server or PHP-FPM service. This method bypasses the need for the non-existent pecl7.2-sp command. However, be aware that this requires root access and a development environment with gcc, make, and autoconf installed, which you have confirmed are present in your logs.

The Downgrade Alternative

If compiling from source yields compilation errors due to library mismatches or if the security risk of using deprecated algorithms is too high for your compliance requirements, downgrading to PHP 7.1.x is a viable strategy for legacy applications running on Debian-based systems. As noted in community discussions regarding this specific issue, PHP 7.1.x still supports mcrypt by default without requiring manual compilation or external PECL channels.

This approach involves reinstalling PHP via the package manager:

sudo apt-get install php7.1 php7.1-mcrypt

You would then need to configure your web server (Apache/Nginx) and application bootstrapper (like Laravel) to route specific legacy projects to the PHP 7.1 FPM pool while keeping other projects on PHP 7.2 or 8.x. This allows you to isolate the dependency without affecting the rest of your infrastructure.

Final Considerations

While solving the immediate error is important, relying on mcrypt in a new codebase is not recommended. If you are working within the Laravel ecosystem, for instance, ensure that any third-party packages requiring mcrypt are updated to versions compatible with OpenSSL or AES-CTR via the native crypto functions. For existing legacy integrations, downgrading the PHP version for specific projects is often the most stable solution compared to maintaining a manually compiled extension on a deprecated platform.

Our network