PHP7.1 and Laravel 5.3: Function mcrypt_get_iv_size() is deprecated

PHP7.1 and Laravel 5.3: Function mcrypt_get_iv_size() is deprecated

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

Stefan Bogdanescu

Founder & Senior Architect

PHP 7.1 and Laravel 5.3: Function mcrypt_get_iv_size() is deprecated

Upgrading your PHP runtime from version 7.0.x to 7.1.0 often triggers immediate errors in legacy applications, particularly those relying on the mcrypt extension. When you attempt to load a project built with an older framework like Laravel 5.0 or 5.1, you are likely to encounter an ErrorException complaining that mcrypt_get_iv_size() is deprecated. This error originates from the Illuminate\Encryption\Encrypter class, specifically around line 303 in standard installations.

The root cause lies in how PHP handles cryptographic functions during its transition away from the legacy mcrypt extension. In PHP 7.1, the internal implementation of mcrypt_get_iv_size() was marked as deprecated because it relied on the underlying C library in a way that is no longer supported or standardized across all platforms. While the function might still technically exist in some builds, the deprecation warning causes Laravel to throw an exception immediately upon instantiation of the encrypter service, preventing your application from booting.

The most direct solution involves updating your framework version. Laravel 5.3 introduced significant changes to its encryption system, specifically replacing the deprecated mcrypt-based logic with a new AES implementation using the OpenSSL extension. By migrating to Laravel 5.3, you resolve the deprecation error at the source without needing to manually patch the vendor files. However, as noted in your situation, this involves substantial code refactoring due to changes in event listeners, database migrations, and service providers. If your project is large and complex, a full upgrade might be impractical in the short term.

If you cannot immediately migrate to Laravel 5.3 or later, there are temporary workarounds to suppress the error while keeping your application running on PHP 7.1. You can modify the Encrypter.php file located in your project's vendor/laravel/framework/src/Illuminate/Encryption/ directory. The specific line causing the issue typically looks like this:

$ivSize = mcrypt_get_iv_size($this->cipher, 'ecb');

In PHP 7.1, you can replace the deprecated function call with a hardcoded value that matches the standard IV size for ECB mode. You would change the line to:

$ivSize = 16; // Standard block size for AES-128/256 in CBC or ECB modes

This approach works because the Internal Encryption Key (IV) for standard AES ciphers is consistently 16 bytes long. By hardcoding this value, you bypass the need to query the mcrypt extension, effectively silencing the deprecation warning without altering your application's encryption behavior. Ensure that your cipher property in the constructor remains set to 'aes-128-cbc' or similar, as the hardcoded size assumes standard block sizes.

While this workaround allows you to continue using Laravel 5.x on PHP 7.1, it is important to understand the limitations. The mcrypt extension itself was removed from mainstream Linux distributions starting with PHP 7.2 and is effectively dead for new development. Relying on a hardcoded IV size works for legacy compatibility, but it does not fix the underlying architectural decision of using deprecated cryptographic primitives. If you plan to move to PHP 7.2 or higher in the future, this specific workaround will fail completely, forcing a migration to Laravel 5.4 or later (which uses openssl_encrypt exclusively) or Laravel 6+.

For teams maintaining long-lived applications, this situation highlights the importance of abstracting cryptographic logic away from framework internals when possible. However, given the effort required to refactor a massive codebase, updating the vendor file to bypass the deprecation is often the pragmatic choice until a strategic upgrade can be planned. If you need further assistance with legacy Laravel migrations or specific configuration steps, resources like https://laravelcompany.com can provide guidance on modernizing your stack.

Our network