35

While executing composer install/update I have got the following error from openssl:

The "https://packagist.org/packages.json" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed Failed to enable crypto failed to open stream: operation failed https://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date

I am using:

  1. PHP 5.6.3 (cli) (built: Nov 17 2014 15:16:53)
  2. XAMPP stack 5.6.3-0
  3. ubuntu 14.04

composer diag shows:

Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity: FAIL
[Composer\Downloader\TransportException] The "https://packagist.org/packages.json"  file  could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Failed to enable crypto
failed to open stream: operation failed
Checking disk free space: OK
Checking composer version: 

[Composer\Downloader\TransportException]
The "https://getcomposer.org/version" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Failed to enable crypto
failed to open stream: operation failed

php -r 'var_dump(openssl_get_cert_locations());' shows:

array(8) {
["default_cert_file"]=>
string(33) "/opt/lampp/share/openssl/cert.pem"
["default_cert_file_env"]=>
string(13) "SSL_CERT_FILE"
["default_cert_dir"]=>
string(30) "/opt/lampp/share/openssl/certs"
["default_cert_dir_env"]=>
string(12) "SSL_CERT_DIR"
["default_private_dir"]=>
string(32) "/opt/lampp/share/openssl/private"
["default_default_cert_area"]=>
string(24) "/opt/lampp/share/openssl"
["ini_cafile"]=>
string(0) ""
["ini_capath"]=>
string(0) ""
}

For php 5.5.19 everything is Ok.

yuklia
  • 6,733
  • 5
  • 20
  • 26

12 Answers12

32

I found a solution to this

I'm running:
FreeBSD 10.1
Apache2.4
PHP 5.6.3

To find the CA file I ran this command

> locate cacert.pem

Result was:
/usr/local/lib/perl5/site_perl/5.16/Mozilla/CA/cacert.pem

Then open the php.ini file and
change this:

;openssl.cafile=

To this:

openssl.cafile=/usr/local/lib/perl5/site_perl/5.16/Mozilla/CA/cacert.pem

Note: This directive is only available on php 5.6.x

Then restart Apache

Manuel Ochoa
  • 321
  • 2
  • 4
12

I solved the problem with the SSL error by adding the SSL certificate to the XAMPP certificates folder.

// navigate to a directory to save the certificate
cd /Downloads

// download a certificate
wget http://curl.haxx.se/ca/cacert.pem

// rename and move the file to the Xampp certificates folder
mv cacert.pem /Applications/XAMPP/xamppfiles/share/openssl/cert.pem

Don't forget to restart your apache!

teynon
  • 7,540
  • 10
  • 63
  • 106
kipzes
  • 694
  • 2
  • 10
  • 27
  • 2
    Thank you! For information, on Linux the path is: sudo mv cacert.pem /opt/lampp/share/openssl/cert.pem – Ronald Araújo Oct 03 '15 at 14:22
  • To find the location the following can be used: `php -r "print_r(openssl_get_cert_locations());"` (look for the value of `default_cert_file`.). – Potherca Feb 28 '18 at 09:23
12

I am using Mac OS Sierra and when I was trying to update the composer using the command /usr/local/bin/composer self-update I kept getting the error:

[Composer\Downloader\TransportException]                                                          
  The "https://getcomposer.org/version" file could not be downloaded: SSL operation failed with co  
  de 1. OpenSSL Error messages:                                                                     
  error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed                 
  Failed to enable crypto                                                                           
  failed to open stream: operation failed  

I fixed it following these steps:

1) Create the local database using the command:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

2) Locate the cert file:

locate cacert.pem 

3) Check the location of the php.ini file:

php --ini

4) If the 'Loaded Configuration File' for php.ini file is showing as (none), copy the file /etc/php.ini.default to /etc/php.ini:

sudo cp /etc/php.ini.default /etc/php.ini

5) Open the php.ini file and edit the ;openssl.cafile= line by uncommenting it and appending the link to the cert file location:

openssl.cafile=/Users/me/.composer/cacert.pem

Thats it. Now, when you run the composer update, it will work fine.

Neel
  • 9,352
  • 23
  • 87
  • 128
7

I ran into the same exact issue on Windows even after adding valid latest certificate downloaded. I'm running composer behind proxy, So i've to add environment variables http_proxy and https_proxy.

My environment: PHP 5.6.33 Windows 7 64 bit Composer version 1.6.3 2018-01-31 16:28:17

I downloaded latest certificates CA Bundle and updated following paths in my php.ini still didn't work.

curl.cainfo = C:\Certificates\ca-bundle.crt
openssl.cafile= C:\Certificates\ca-bundle.crt
openssl.capath=C:\Certificates

Then did following steps

1) Open chrome browser and navigate https://packagist.org/

2) Click on the little Secure Lock icon

3) Click on Certificates Valid

enter image description here

4)Open Certificate Path tab and you will see the following path levels

enter image description here

5) Need to export the certificate for both 1&2 marked in the image

6) To export certificate, click on view Certificate, Got to Details Tab and click on Copy to file

enter image description here

7)choose BASE 64 encoding

enter image description here

8) click on Next and save that file to a location, Do this for No. (2) shown in setp 4

enter image description here

9) Open the .cer file and copy the content to the end of .crt file which you used to configure in php.ini

Then try running comport install - It's worked for me

Process should be same if you see composer throwing ssl error when accessing sites over proxy.

Praveen Govind
  • 2,619
  • 2
  • 32
  • 45
6

Adding openssl.cafile to php.ini worked for me too. Instead of looking for the cert file, I downloaded it directly:

curl http://curl.haxx.se/ca/cacert.pem > cacert.pem

and then just pointed openssl.cafile setting to it.

phoenix
  • 1,629
  • 20
  • 11
  • It is a security issue to download from an insecure source (http) to root certificates. Only amateurs do that and then they get hacked. – Daniel W. Oct 24 '16 at 16:26
  • 1
    @Kwadz use the https link instead, put the file onto your server via SSH/SFTP/SCP. – Daniel W. Jun 13 '18 at 15:49
5

1.

php -r "print_r(openssl_get_cert_locations());"
array(8) {
  ["default_cert_file"]=>
  string(31) "/usr/local/etc/openssl/cert.pem"
  ...
}

2.vim php.ini

[openssl]
openssl.cafile=/usr/local/etc/openssl/cert.pem
shengji yin
  • 51
  • 1
  • 1
2
composer clearcache

This worked for me when I get error :

https://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date

Syscall
  • 19,327
  • 10
  • 37
  • 52
sim
  • 21
  • 1
  • Now I get the following error: `curl error 60 while downloading https://repo.packagist.org/packages.json: SSL certificate problem: unable to get local issuer certificate`, how do I solve it? – Pathros Feb 08 '23 at 16:50
1

On the mac with XAMPP:

cd /Applications/XAMPP/xamppfiles/share/openssl

sudo curl -O -k http://curl.haxx.se/ca/cacert.pem

sudo mv cacert.pem cert.pem

Stop and Restart Apache

jww
  • 97,681
  • 90
  • 411
  • 885
1

First: Check certificate file location which will be in default_cert_file key, you will found it in openssl_get_cert_locations() its a php openssl function. You can run it as follows:

$ php -r "print_r(openssl_get_cert_locations());"

Output in my system

    Array
    (
        [default_cert_file] => /opt/lampp/share/openssl/cert.pem
        [default_cert_file_env] => SSL_CERT_FILE
        [default_cert_dir] => /opt/lampp/share/openssl/certs
        [default_cert_dir_env] => SSL_CERT_DIR
        [default_private_dir] => /opt/lampp/share/openssl/private
        [default_default_cert_area] => /opt/lampp/share/openssl
        [ini_cafile] => 
        [ini_capath] => 
    )

Second: Download http://curl.haxx.se/ca/cacert.pem:

$ wget http://curl.haxx.se/ca/cacert.pem

Third: Copy certificate.pem file into default_cert_file location:

$ sudo mv cacert.pem /opt/lampp/share/openssl/cert.pem

** FROM https://github.com/composer/composer/issues/3346 **

Amanuel Nega
  • 1,899
  • 1
  • 24
  • 42
1

I would like to add a simple answer.

Your problem: The composer is unable to download dependency files due to an incorrect certificate, either it is corrupt, incorrect, or not in place at all.

Your potential easiest solution: Download a new certificate and tell Composer to use the new one.

Step 1: Get CA Certificate from https://curl.se/docs/caextract.html

Step 2: Use the following command to use new certificate composer config --global cafile "<file_path_including_cacert.pem"

halfer
  • 19,824
  • 17
  • 99
  • 186
Akash Varde
  • 83
  • 1
  • 11
0

For us, this issue only seemed to affect one of our private repositories. It may have had something to do with certs or a corporate firewall, but it seemed intermittent so we weren't able to confirm before we found a different fix.

Inside composer.json, we changed the repository URL from the https to the ssh variant and added the "no-api": trueoption:

"repositories": [
    {
      "type": "vcs",
      "url": "git@github.com:our-user/our-repo.git",
      "no-api": true
    }
]

With that edit, composer update/install operations were able to complete successfully.

Everett
  • 8,746
  • 5
  • 35
  • 49
0

Simply add this configuration to your composer.json file.

"config": {
"secure-http": false
}

Here is an full example of a working composer.json file

  "repositories": [{
    "type": "composer",
    "url": "http://packagist.org"
  }],
  "require": {
    "phpmailer/phpmailer": "^6.0"
  },
  "config": {
    "secure-http": false
  }
}
```
Leon
  • 485
  • 4
  • 11
  • you never want to go the insecure route. You want to always fix the security errors, not brush them aside and ignore them. There is a reason for the error! – Danny F Oct 28 '21 at 13:25