Mike Yang
Mike Yang

Reputation: 2924

The openssl extension is required for SSL/TLS protection

composer create-project flarum/flarum . --stability=beta

I try to run this command, but it gave me this error.

  [RuntimeException]                                                           
  The openssl extension is required for SSL/TLS protection but is not availab  
  le. If you can not enable the openssl extension, you can disable this error  
  , at your own risk, by setting the 'disable-tls' option to true.  

I tried to add "extension=php_openssl.dll" to "php.ini", but it still got this error

Upvotes: 142

Views: 514325

Answers (17)

Muzammil Hasnain
Muzammil Hasnain

Reputation: 149

i'm facing same issue what you need to do is go to php ini and remove colon on extension=openssl if its ;extension=openssl then check your php version and your xammpp version open cmd and check php -v if its not same go to windows enviroment varibales and set path of xampp php like this F:\xamp8.2\php in enviroment variables and restart your computer.

Upvotes: 0

TheJizel
TheJizel

Reputation: 1900

Just a heads up if you are using PhpStorm on Windows (not sure for other platforms):

Setting the configuration file for the CLI interpreter in the IDE settings alone does not work.

I kept trying to modify the existing php.ini-development that was provided with the PHP 8.3 install. Even when uncommenting the extension_dir = "ext" and extension=openssl lines, I kept getting the same error.

Once I renamed php.ini-development to php.ini, everything worked as expected.

I would guess that running composer commands via the GUI would work without renaming the ini, but it definitely did not work in a terminal inside the IDE itself (even though the php command did once I added it as a CLI interpreter and without adding it to my global PATH).

Hope this saves somebody the amount of time I wasted trying to figure this out.

Upvotes: 0

Jorn Rigter
Jorn Rigter

Reputation: 1195

What finally solved it for me was setting the correct php.ini file -- I had a php.ini-development and php.ini-production file in my PHP directory and was editing the production file, but turns out (thanks to @matty in this SO post) you need to choose one of the two.

So the steps to make this work in my case (on Windows) were:

  1. Change php.ini-production in the PHP directory to php.ini & follow the previously recommended steps by folks here, in my case:
  2. Uncomment ;extension=openssl
  3. Uncomment ;extension_dir = "ext"

Upvotes: 5

Dalan Dan
Dalan Dan

Reputation: 21

I got the same problem. I installed wamp then xampp. The solution is that I reinstalled composer because it is pathed to wamp files.

Upvotes: 0

Ax3
Ax3

Reputation: 21

lot of answers already, but this is what worked for me (in case someone still needs it)

Just upgraded from php 7.3.x to 7.4.33 in Windows 10, and this error occurred to me, so Just went back to the composer.exe installer, re-run the installation process once again pointing to the new php 7.4. folder, and it worked.

Upvotes: 0

Jacquelyn
Jacquelyn

Reputation: 23

I was just having this issue, but these solutions weren't working since I installed PHP and Apache independently without Xampp or Wamp.

The problem for me turned out to be that I was trying to run composer from Git for Windows instead of cmd or PowerShell—where it turned out to be working fine.

My solution was to add a symlink from my /c/php/php.ini (C:\php\php.ini) to my /bin/ directory (C:\Program Files\Git\bin).

Upvotes: 0

Vinícius Medeiros
Vinícius Medeiros

Reputation: 2989

The same error occurred to me. I fixed it by turning off TLS for Composer, it's not safe but I assumed the risk on my develop machine.

try this:

composer config -g -- disable-tls true

and re-run your Composer. It works to me!

But it's unsecure and not recommended for your Server. The official website says:

If set to true all HTTPS URLs will be tried with HTTP instead and no network-level encryption is performed. Enabling this is a security risk and is NOT recommended. The better way is to enable the php_openssl extension in php.ini.

If you don't want to enable unsecure layer in your machine/server, then setup your php to enable openssl and it also works. Make sure the PHP Openssl extension has been installed and enable it on php.ini file.


To enable OpenSSL, add or find and uncomment this line on your php.ini file:

Linux/OSx:

extension=php_openssl.so

Windows:

extension=php_openssl.dll

And reload your php-fpm / web-server if needed!

UPDATE:

As of PHP 7.4 the extension is named extension=openssl (known for Windows).

Upvotes: 267

Martin Zeitler
Martin Zeitler

Reputation: 76589

According to the composer reference there are two relevant options: disable-tls and secure-http, which one can use. Just edit the configuration with: nano ~/.composer/config.json:

{
    "config": {
        "disable-tls": true,
        "secure-http": false
    }
}

Then it will complain about:

You are running Composer with SSL/TLS protection disabled.
Warning: Accessing getcomposer.org over http which is an insecure protocol.

But it performs the composer selfupdate (or whatever command).

One cannot simply "enable SSL in the php.ini" on Linux; PHP needs to be compiled with openSSL configured as shared library - in order to be able to access it from the PHP CLI SAPI.

Upvotes: 31

Vrushal Raut
Vrushal Raut

Reputation: 1208

This issue occurs due to openssl and extension directory so uncomment below extensions in php.ini file

extension=php_openssl.dll

extension_dir = "ext"

Its works on my machine.

Upvotes: 57

Sebastian
Sebastian

Reputation: 442

I had this issue on IIS on my new home server when attempting to install Magento. To fix it i added the above: extension=php_openssl.dll in my php.ini and then restarted my IIS server on Windows 10 Pro.

Upvotes: 0

yassine dotma
yassine dotma

Reputation: 775

enter image description here You are running Composer with SSL/TLS protection disabled.

 composer config --global disable-tls true
 composer config --global disable-tls false

Upvotes: 2

Vasile Florin Vilsan
Vasile Florin Vilsan

Reputation: 315

After trying everything, I finally managed to get this sorted. None of the above suggested solutions worked for me. My system is A PC Windows 10. In order to get this sorted I had to change the config.json file located here C:\Users\[Your User]\AppData\Roaming\Composer\. In there, you will find:

{
    "config": {
        "disable-tls": true},
    "repositories": {
        "packagist": {
            "type": "composer",
            "url": "http://repo.packagist.org" // this needs to change to 'https'
        }
    }
}

where you need to update the packagist repo url to point to the 'https' url version.

I am aware that the above selected solution will work for 95% of the cases, but as I said, that did not work for me. Hope this helps someone.

Happy coding!

Upvotes: 8

Vincent PHILIPPE
Vincent PHILIPPE

Reputation: 1181

I just add this because it worked for me, i install composer with the developer option activate (just check the box in the installer)

https://getcomposer.org/Composer-Setup.exe

I think this problem may occurs when you add a new version of php to your wamp server. If you do this, you have to check if the extension_dir variable is configure to "env".

Then check if the php_openssl.dll exist in your phpx.x/ext folder. If there is not php_openssl.dll, you have to download it here : http://www.telecharger-dll.fr/dll-php_openssl.dll.html

If it still not working, check if your apache server use the good php.ini file by running the following cmd command :

php --ini

Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File:         C:\wamp64\bin\php\php7.4.7x64\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

If the loaded configuration file return (none), you have to check your appache/apache2.4.41/conf/httpd.conf file is configure with the proper phpIniDir and the correct module.

It must be something like this :

PHPIniDir "${APACHE_DIR}/bin"
LoadModule php7_module "${INSTALL_DIR}/bin/php/php7.4.7x64/php7apache2_4.dll"

Then restart apache and check the "apache/apache2.4.41/bin/php.ini" (wich is the one configure above by PHPIniDir) it must me like

enter image description here

Upvotes: 2

Qriz75
Qriz75

Reputation: 23

For me on Windows 10 none of those worked ... I had changed my local server from WAMP to Laragon and had to add the new path to the php.ini in the Environment Variables under:

Control Panel --> Advanced System Settings --> Environment Variables --> Path (double click) --> Browse... then navigate to the php.ini and click ok.

After that a reboot was needed and now composer works like a charm!

Upvotes: 0

Michael Neely
Michael Neely

Reputation: 399

I had the same problem. I tried everything listed on this page. When I re-installed Composer it worked like before. I had a PHP version mismatch that was corrected with a new install establishing the dependencies with the PHP path installed in my system environment variables.

I DO NOT RECOMMEND the composer config -g -- disable-tls true approach.

By the way the way to reverse this is composer config -g -- disable-tls false.

Upvotes: 8

Clairton Luz
Clairton Luz

Reputation: 2344

To enable openssl go into php.ini and enable this line:

extension=php_openssl.dll

if you don't want enable openssl you can set to composer not use openssl with this command:

composer config -g -- disable-tls true

however, this is a security problem.

Upvotes: 18

NiceDevelopmentq
NiceDevelopmentq

Reputation: 525

I had the exact same problem and couldn't find a solution, so after thinking and looking for a while I figured that my PHP.INI apparently didn't look in the correct directory for my PHP Extensions, so I went under:

"Directory in which the loadable extensions (modules) reside." And found the following:

; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
;extension_dir = "ext"

And simply removed the ; infront of "extension_dir = "ext", note this is only for Windows, remove the semicolon in front of the first extension_dir if you are running a different operating system.

I have no idea why mine wasn't already unmarked, but it's just something to look for if you are having problems.

Upvotes: 37

Related Questions