Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to install packages on Windows and PHP7.3.1 #104

Closed
Hlsgs opened this issue Feb 14, 2019 · 13 comments
Closed

Unable to install packages on Windows and PHP7.3.1 #104

Hlsgs opened this issue Feb 14, 2019 · 13 comments

Comments

@Hlsgs
Copy link

Hlsgs commented Feb 14, 2019

Here is my WP CLI info:

OS:     Windows NT 10.0 build 17763 (Windows 10) i586
Shell:  C:\Windows\system32\cmd.exe
PHP binary:     D:\dev\xampp\php\php.exe
PHP version:    7.3.1
php.ini used:   D:\dev\xampp\php\php.ini
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       D:\dev
WP-CLI packages dir:    C:\Users\EDIT/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.1.0

And here is the response when trying to install a package:

PS D:\dev> wp package install iandunn/wp-cli-rename-db-prefix
Installing package iandunn/wp-cli-rename-db-prefix (dev-master)
Updating C:\Users\EDIT\.wp-cli\packages\composer.json to require the package...
Error: Failed to get composer instance: The configured cafile was not valid or could not be read.
Reverted composer.json.

Everything else works, WP CLI is in D:\dev\wp-cli\ and PHP in D:\dev\xampp\php\ and both are set in PATH.

This is the content of D:\dev\wp-cli\wp.bat:

@ECHO OFF
php.exe "D:\dev\wp-cli\wp-cli.phar" %*

Thank you!

@Hlsgs
Copy link
Author

Hlsgs commented Mar 6, 2019

Running wp package list results in:

PHP Warning:  file_get_contents(phar://D:/dev/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/../res/cacert.pem): failed to open stream: phar error: "vendor/composer/ca-bundle/res/cacert.pem" is not a file in phar "D:/dev/wp-cli/wp-cli.phar" in phar://D:/dev/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/CaBundle.php on line 140

Warning: file_get_contents(phar://D:/dev/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/../res/cacert.pem): failed to open stream: phar error: "vendor/composer/ca-bundle/res/cacert.pem" is not a file in phar "D:/dev/wp-cli/wp-cli.phar" in phar://D:/dev/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/CaBundle.php on line 140
Error: Failed to get composer instance: The configured cafile was not valid or could not be read.

So this seems related to #4703, #72 and it's resolution #73.

Has #73 not been merged into the latest WP-CLI 2.1.0?

@schlessera
Copy link
Member

The fix in #73 has been merged into WP-CLI and is part of v2.1.0.

My first guess would be that the SSL_CERT_FILE environment variable that the fix wants to set is either not correctly set or that Composer does ignore it in this case.

@Hlsgs
Copy link
Author

Hlsgs commented Mar 9, 2019

The SSL_CERT_FILE env variable is not set. However, if I do set it to phar://wp-cli.phar/vendor/rmccue/requests/library/Requests/Transport/cacert.pem as per wp-cli/wp-cli#4703 (comment), everything works fine. This is regardless of whether I run everything as admin or not.

@schlessera
Copy link
Member

Okay, so the fix we did has a few conditionals, and maybe one if them is failing:

https://github.com/wp-cli/package-command/pull/73/files#diff-ca5ded108d7e84b923c359071e50f993R1070

Can you check whether one of these environment variables might be set for you?

@schlessera
Copy link
Member

Okay, to be more precise, check whether any of the following exist:

  • environment variable SSL_CERT_FILE (you already checked that one)
  • environment variable SSL_CERT_DIR
  • PHP ini value openssl.cafile
  • PHP ini value openssl.capath

Also, maybe the check to see whether you're in a Phar is failing for you. Please verify the result of the following command:

wp eval "var_dump( WP_CLI\Utils\inside_phar() );"

@Hlsgs
Copy link
Author

Hlsgs commented Mar 9, 2019

Only openssl.cafile is set: openssl.cafile = "\dev\xampp\apache\bin\curl-ca-bundle.crt" and the result of that command is bool(true). This is a XAMPP portable stack, so this will be pretty common.

@schlessera
Copy link
Member

Okay, so I assume that:

  1. Can you try to temporarily unset openssl.cafile to see whether that fixes the issue?
  2. Can you try to diagnose why one of the conditions in here fails: https://github.com/composer/ca-bundle/blob/1.1.0/src/CaBundle.php#L85

@Hlsgs
Copy link
Author

Hlsgs commented Mar 9, 2019

  1. Unsetting openssl.cafile = "\dev\xampp\apache\bin\curl-ca-bundle.crt" solves the issue. Also, setting the full path including the drive letter like so openssl.cafile = "d:\dev\xampp\apache\bin\curl-ca-bundle.crt" also solves the issue. The former is the way XAMPP portable configures itself, and it makes sense so that the stack is fully portable, as in working from a USB stick.
  2. I don't know how to test that, but I presume it's to do with the above mentioned path.

@schlessera
Copy link
Member

Okay, so this is in fact an upstream issue with Composer on Windows then.

Composer fails to properly validate the provided CA file here: https://github.com/composer/ca-bundle/blob/1.1.0/src/CaBundle.php#L85

This means that there's not much to change at the WP-CLI side of things, but it might make sense to introduce a bug report to the Composer repository instead.

@Hlsgs
Copy link
Author

Hlsgs commented Mar 14, 2019

@schlessera Doing that is unfortunately beyond my knowledge level, so, if you could be bothered to do it instead, it would be great. Regardless, thank you for your time!

@schlessera
Copy link
Member

I've created an upstream ticket. I'm not sure this is something that can be solved by Composer, so you shouldn't hold your breath and just remove/adapt the openssl.cafile setting for now.

I'm closing the ticket as there's currently no next action for WP-CLI, but we can reopen if needed.

@Hlsgs
Copy link
Author

Hlsgs commented Mar 17, 2019

I will set the SSL_CERT_FILE env variable to phar://wp-cli.phar/vendor/rmccue/requests/library/Requests/Transport/cacert.pem as a mitigation for now. Thank you!

@maheshwaghmare
Copy link

maheshwaghmare commented Apr 26, 2019

I was facing the same issue on my windows setup.

Quick SOLUTION is:

  1. In my php.ini there is a code openssl.cafile which have set the file curl-ca-bundle.crt E.g.
openssl.cafile="C:\xampp\apache\bin\curl-ca-bundle.crt"

I notice that the file curl-ca-bundle.crt NOT EXIST in location C:\xampp\apache\bin\

  1. On other computers localhost, I found that the path for openssl.cafile in php.ini file was not set.

For both the above cases, I have followed the below steps:

  • Step 1: Download the cacert.pem file from https://curl.haxx.se/docs/caextract.html
  • Step 2: Paste into C:\xampp\apache\bin\
  • Step 3: Make sure the curl.exe and the cacert.pem file in the same directory.
  • Step 4: Rename the cacert.pem file to curl-ca-bundle.crt
  • Step 5: Re-run curl.exe !

More Details

My old version of WP CLI was 2.1.0.

C:\xampp\htdocs\dev.test\wp-content
λ wp cli info
OS:     Windows NT 6.3 build 9600 (Windows 8.1 Professional Edition) AMD64
Shell:  C:\Windows\system32\cmd.exe
PHP binary:     C:\xampp\php\php.exe
PHP version:    7.3.2
php.ini used:   C:\xampp\php\php.ini
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       C:\xampp\htdocs\dev.test\wp-content
WP-CLI packages dir:    C:\Users\MaheshW/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.1.0

I have update my WP CLI version:

C:\xampp\htdocs\dev.test\wp-content
λ wp cli update
You have version 2.1.0. Would you like to update to 2.2.0? [y/n] y
Downloading from https://github.com/wp-cli/wp-cli/releases/download/v2.2.0/wp-cli-2.2.0.phar...
md5 hash verified: ffdc73bf30a4fa74079b9472993b0645
New version works. Proceeding to replace.
Success: Updated WP-CLI to 2.2.0.

But, After update still getting the same error.

C:\xampp\htdocs\dev.test\wp-content
λ wp package list
PHP Warning:  file_get_contents(phar://C:/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/../res/cacert.pem): failed to open stream: phar error: "vendor/composer/ca-bundle/res/cacert.pem" is not a file in phar "C:/wp-cli/wp-cli.phar" in phar://C:/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/CaBundle.php on line 140

Warning: file_get_contents(phar://C:/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/../res/cacert.pem): failed to open stream: phar error: "vendor/composer/ca-bundle/res/cacert.pem" is not a file in phar "C:/wp-cli/wp-cli.phar" in phar://C:/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/CaBundle.php on line 140
Error: Failed to get composer instance: The configured cafile was not valid or could not be read.

I have execute the wp eval "var_dump( WP_CLI\Utils\inside_phar() );" as per about discussion:

C:\xampp\htdocs\dev.test\wp-content
λ wp eval "var_dump( WP_CLI\Utils\inside_phar() );"
bool(true)

I thought its composer issue so I was update an composer:

C:\xampp\htdocs\dev.test\wp-content
λ composer -V
Composer version 1.8.0 2018-12-03 10:31:16

C:\xampp\htdocs\dev.test\wp-content
λ cd C:\ProgramData\ComposerSetup\bin

C:\ProgramData\ComposerSetup\bin
λ composer selfupdate
Updating to version 1.8.5 (stable channel).
   Downloading (100%)
Use composer self-update --rollback to return to version 1.8.0

C:\ProgramData\ComposerSetup\bin
λ composer -V
Composer version 1.8.5 2019-04-09 17:46:47

After composer update still getting the same error.

C:\ProgramData\ComposerSetup\bin
λ cd C:\xampp\htdocs\dev.test\wp-content

C:\xampp\htdocs\dev.test\wp-content
λ wp package list
PHP Warning:  file_get_contents(phar://C:/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/../res/cacert.pem): failed to open stream: phar error: "vendor/composer/ca-bundle/res/cacert.pem" is not a file in phar "C:/wp-cli/wp-cli.phar" in phar://C:/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/CaBundle.php on line 140

Warning: file_get_contents(phar://C:/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/../res/cacert.pem): failed to open stream: phar error: "vendor/composer/ca-bundle/res/cacert.pem" is not a file in phar "C:/wp-cli/wp-cli.phar" in phar://C:/wp-cli/wp-cli.phar/vendor/composer/ca-bundle/src/CaBundle.php on line 140
Error: Failed to get composer instance: The configured cafile was not valid or could not be read.

After a search on stackoverflow, I found the solution. https://stackoverflow.com/questions/28858351/php-ssl-certificate-error-unable-to-get-local-issuer-certificate


After implementing the solution, I have successfully fixed the above issue.

C:\xampp\htdocs\dev.test\wp-content                                       
λ wp package list                                                                 
+------------------------+---------+------------+-----------+----------------+    
| name                   | authors | version    | update    | update_version |    
+------------------------+---------+------------+-----------+----------------+    
| wp-cli/profile-command |         | dev-master | available | dev-master     |    
+------------------------+---------+------------+-----------+----------------+    

Hope, It helps for you too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants