Magento 2 – Causes of ‘Failed to Enable Crypto’ Error

composermagento2ssl

I'm trying to install Magento 2.1 via the composer meta-package with the following command

composer create-project --repository=https://repo.magento.com/ magento/project-community-edition

However, composer fails to update the packages.json from repo.magento.com, and reports

The "https://repo.magento.com/packages.json" file could not be downloaded: Failed to enable crypto

Does anyone know what triggers this "Failed to enable crypto" error is and how someone could fix it?

Best Answer

It sounds like Magento's severely tightened up their HTTPS on the repo.magento.com server.

These settings are tight enough that applications that support HTTPS but use an older version of OpenSSL may have their connections rejected.

Meaning, if the version of PHP you're using to run composer.phar is linked against and older version of PHP, you'll get the Failed to enable crypto error. You can test your version of PHP with the following code snippet.

error_reporting(E_ALL);
$context = stream_context_create();
$contents = file_get_contents('https://repo.magento.com/packages.json', false, $context);

The reason I got this error was/is the packaged version of PHP I've been using (depending on how you count) for almost 13 years was linking against an older version of SSL. The package maintainers have released a new build that seems to address these problems.

If you're using a different packaged version of PHP, you'll need to pressure the package maintainers to release a new build that fixes this, or pressure Magento to do the same.

If you're building a version of PHP yourself (by hand, via brew, etc) then make sure you're using as modern a version of OpenSSL with modern TLS support (I may have used those words wrong, not an HTTPS/SSL expert by any stretch)

Related Topic