125
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

marlo
  • 6,998
  • 5
  • 28
  • 34
Mike Yang
  • 2,581
  • 3
  • 24
  • 27
  • 3
    I try to add "extension=php_openssl.dll" to "php.ini", but it still got this error – Mike Yang Feb 07 '16 at 04:12
  • 1
    Possible duplicate of [Composer Warning: openssl extension is missing. How to enable in WAMP](http://stackoverflow.com/questions/14062055/composer-warning-openssl-extension-is-missing-how-to-enable-in-wamp) – Wouter J Feb 07 '16 at 14:12
  • Is your php installed manually or from package? – apex39 Nov 18 '16 at 16:38
  • I find Laragon to be the best local development environment. After changin php.ini be sure to Reload Apache. – s3c Jun 17 '21 at 08:31

14 Answers14

246

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).

mvandiepen
  • 67
  • 12
Vinícius Medeiros
  • 2,763
  • 1
  • 11
  • 12
  • 28
    You are not fixing it. You are just hiding the error. You need to enable the open_ssl module in your Wamp server's php.ini File. Wamp uses 2 php.ini file. One for Apache and the other one CLI. You need to enable open_ssl extension in the second php.ini file which you can locate at C:\wamp\bin\php\\php.ini – Narendran Parivallal Apr 22 '16 at 14:32
  • 2
    Yes, I know, but for some reasons my company not allow enable tls, and the user @thermos commented that turn on open_ssl module and not work. Then I give my solution for this question. – Vinícius Medeiros Apr 25 '16 at 19:15
  • 1
    Also, is this really unsafe if you're running it on a local development machine? How is that going to affect the security of your server? –  Jun 17 '16 at 04:43
  • @Hassan, disabling tls you are assuming all HTTPS will be HTTP, if you have public repositories, its no unsafe but not recommended, but in server has recommended you enable open_ssl module in your php. I improve my answer. – Vinícius Medeiros Jun 17 '16 at 12:30
  • 1
    I don't get this. If I do this on my develop machine will not that also be mirrored on the server? If not how can it work on the server? – Brainmaniac Jul 07 '17 at 08:38
  • @Olof I guess there are SSL-keys generated while installing via composer. These keys will be used to secure your web server later. – Martin Pfeffer Jul 11 '17 at 14:35
  • what with the space betwee -- and the disabled-tls option? – Jonathan DS Aug 14 '18 at 13:41
  • I encountered this problem when I installed MAMP and tried to use its php version. solutions provided did not work for me. This was the first time I installed MAMP, I uninstalled MAMP and installed WAMP (which I am used to) and problem is gone without any configuration (except PHP path) – Nuryagdy Mustapayev Oct 08 '20 at 11:25
  • Thank you @NarendranParivallal . This required copying `\mamp\conf\php\7.4.16\php.ini` to `\mamp\bin\php\7.4.16\php.ini` which then made the command line perform the same as within apache. Life saver! – kendavidson Nov 22 '21 at 19:03
42

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.

Vrushal Raut
  • 1,050
  • 2
  • 15
  • 20
34

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.

NiceDevelopmentq
  • 495
  • 1
  • 5
  • 11
30

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.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Had to use this approach because I could not set extension_dir = "ext" in php.ini (Laragon kept rewriting), openssl was already enabled in php.ini, and I could not set "disable-tls" via command line for some reason. Thanks! – Lys777 Oct 25 '19 at 01:10
18

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.

Clairton Luz
  • 2,116
  • 19
  • 15
  • 3
    To configure composer to trust a CA on Ubuntu you put certs into `/usr/local/share/ca-certificates/`, to do it on Windows you give up and find another job. – Lauri Elias Mar 21 '17 at 14:51
  • actually this helped me plus https://superuser.com/questions/1010080/the-openssl-extension-is-missing-on-windows-while-installing-composer – Mahdi Khalili Jun 19 '20 at 18:06
7

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!

6

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.

Michael Neely
  • 361
  • 4
  • 5
  • 1
    I think this should be the upvoted answer – ii iml0sto1 Apr 30 '22 at 18:12
  • This is not a solution, this is a way to bypass it – Timberman Mar 10 '23 at 12:16
  • Actually, Michael Neely solved my problem. My Composer was pointing to a wrong PHP version, so I was getting the error "The openssl extension is required for SSL/TLS protection..." None of the above solutions worked for me. After uninstalling Composer and reinstalling it, pointing it to the right PHP directory (which already had openssl enabled), the error went away. This is the best solution, because it solves the root problem (Composer using the wrong PHP version). This is another great example of an error message not telling you what the actual problem is. Thank you, Michael! – Steve Stilson Jul 05 '23 at 23:53
2

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

vincent PHILIPPE
  • 975
  • 11
  • 26
1

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
yassine dotma
  • 697
  • 8
  • 10
0

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!

Qriz75
  • 23
  • 3
0

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.

Sebastian
  • 402
  • 3
  • 12
0

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).

Jacquelyn
  • 23
  • 4
  • I'm adding this as a comment since it's not directly relevant to the question but will make the above step easier: running `ln -s ...` in Git for Windows required three additional steps to work properly: enable yourself to create symlinks in Local Security Policy in `Local Policies>User Rights Assignment`, and set the environment variable with `setx MSYS winsymlinks:nativestrict`. After this, I had to restart my computer. This is also helpful when developing from github cross-platform. – Jacquelyn Aug 29 '22 at 04:57
0

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.

Ax3
  • 21
  • 6
0

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

Dalan Dan
  • 11
  • 1