Call to undefined function openssl_decrypt

Call to undefined function openssl_decrypt

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

Stefan Bogdanescu

Founder & Senior Architect

Call to undefined function openssl_decrypt

Encountering a Fatal error: Call to undefined function openssl_decrypt() is one of those frustrating PHP errors that immediately points in two directions: either the OpenSSL extension isn't loaded, or your code is running on a version of PHP where that specific function name doesn't exist yet. Since you've already confirmed the OpenSSL extension is installed via your server support team, we can rule out the most obvious cause. The real culprit here is almost certainly a version mismatch between your PHP runtime and the API surface of the openssl library.

The function openssl_decrypt() was introduced in PHP 7.0. If you are running PHP 5.x, or if you have somehow managed to invoke this function before upgrading from PHP 5 to 7, the interpreter will throw exactly the error you are seeing. It is not a bug; it is a feature of the language evolution that broke backward compatibility for certain cryptographic wrappers.

To resolve this immediately without upgrading your entire stack (which might be necessary but requires downtime), you need to check your actual PHP version using php -v in your terminal or by creating a test file with <?php echo phpversion(); ?>. If the output is anything less than 7.0, you have two options: upgrade PHP immediately or migrate your decryption logic to the older API available in PHP 5.

If upgrading isn't an option right now, the migration path involves using the underlying stream context methods that existed prior to the wrapper functions. In PHP 5.6 and earlier, you would use openssl_decrypt via a different mechanism or simply stick to the raw OpenSSL calls, though the wrapper was cleaner. However, the most pragmatic short-term fix for legacy code running on older runtimes is often to check if a compatibility layer exists in your environment, such as a polyfill, or to explicitly call the underlying stream context functions.

Wait, there is another common pitfall even on PHP 7+. It is possible that the extension is installed globally on the server but not loaded for your specific virtual host or application pool. Sometimes, checking phpinfo() shows the module, but the specific function remains undefined if the configuration file php.ini does not include extension=openssl. Ensure that extension=openssl (or extension=openssl.so depending on your OS) is uncommented in the correct php.ini file for your web server context.

Furthermore, verify that you aren't running into a namespace issue or an autoloading problem if this code resides within a specific framework like Laravel. While openssl_decrypt is a global function and not namespaced, confusion often arises when developers assume it behaves like other modern PHP functions that are part of the core stream wrappers.

If you find yourself stuck on an older PHP version with production data encrypted using AES-256-CBC, consider contacting the team that implemented the encryption. If they used openssl_encrypt in a newer PHP version to generate the ciphertext, the key format might differ slightly from what was expected in older versions, or they might have relied on features not available in your current runtime.

For modern applications, upgrading PHP is the only sustainable solution. PHP 5 reached end-of-life years ago, and relying on it introduces security risks beyond just missing functions. The jump to PHP 7 or later provides access to openssl_decrypt, improved performance, and better cryptographic standards. If you are using Laravel, ensure your project's composer.json allows for the required PHP version in production environments.

If you need a quick reference for checking the extension status programmatically within your application logic before attempting decryption, you can use the following check:

if (!extension_loaded('openssl')) {
    die('OpenSSL extension is not loaded.');
}

if (!function_exists('openssl_decrypt')) {
    die('Function openssl_decrypt is not available. Check PHP version (must be >= 7.0).');
}

This defensive coding approach prevents the fatal error from crashing your application and allows you to handle the situation gracefully, perhaps by logging an alert or redirecting to a maintenance page.

Finally, if you are maintaining legacy systems that cannot be upgraded immediately, look into using polyfills or rewriting the encryption logic to use the stream context API available in older PHP versions, though this adds significant complexity. For new projects, always target a supported PHP version and ensure your dependencies respect the minimum requirements of the cryptographic functions you intend to use.

Our network