I’ve got a simple php script which is connecting to my wordpress to create a product. Using the woocommerce rest api library.
$woocommerce = new Client(
'',
'123456789',
'123456789',
[
'wp_api' => true,
'version' => 'wc/v3',
'sslverify' => false,
]
);
// foreach item
$woocommerce->post( 'products', $data );
Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: cURL Error: SSL certificate problem: self signed certificate in /srv/www/example.co.uk/current/web/app/themes/exampletheme/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php on line 417
I’ve attempted the following: Get the certificate from the dev site:
openssl s_client -connect example.co.uk:443 | tee logfile
Copied the certificate and made a file from it called certificate.crt
MIICyTCCAbGgAwIBAgIJANB2....
Uploaded to:
/srv/www/example.co.uk/current/web/wp/certificate.crt
And now trying to use it to prevent this error. functions.php
add_action( 'http_api_curl', function( $handle ) {
curl_setopt($handle, CURLOPT_CAINFO, ABSPATH . 'certificate.crt');
});
// the value of ABSPATH is: /srv/www/example.co.uk/current/web/wp/
Same error remains. Can't tell if the custom cert is being used or not too. If it is then something else must be wrong maybe.
I’ve got a simple php script which is connecting to my wordpress to create a product. Using the woocommerce rest api library.
$woocommerce = new Client(
'https://dev.example.co.uk',
'123456789',
'123456789',
[
'wp_api' => true,
'version' => 'wc/v3',
'sslverify' => false,
]
);
// foreach item
$woocommerce->post( 'products', $data );
Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: cURL Error: SSL certificate problem: self signed certificate in /srv/www/example.co.uk/current/web/app/themes/exampletheme/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php on line 417
I’ve attempted the following: Get the certificate from the dev site:
openssl s_client -connect example.co.uk:443 | tee logfile
Copied the certificate and made a file from it called certificate.crt
MIICyTCCAbGgAwIBAgIJANB2....
Uploaded to:
/srv/www/example.co.uk/current/web/wp/certificate.crt
And now trying to use it to prevent this error. functions.php
add_action( 'http_api_curl', function( $handle ) {
curl_setopt($handle, CURLOPT_CAINFO, ABSPATH . 'certificate.crt');
});
// the value of ABSPATH is: /srv/www/example.co.uk/current/web/wp/
Same error remains. Can't tell if the custom cert is being used or not too. If it is then something else must be wrong maybe.
Share Improve this question asked Feb 29, 2020 at 18:26 wharfdalewharfdale 3484 silver badges17 bronze badges 1- Do not consider my as an answer but have you tried the option to use Let's Encrypt (letsencrypt) instead of a self-signed certificate? – Patrice Poliquin Commented Jun 9, 2020 at 13:27
2 Answers
Reset to default 2You can disable the ssl verification by using 'verify_ssl' => false
. So in your code you should change:
[
'wp_api' => true,
'version' => 'wc/v3',
'sslverify' => false,
]
to:
[
'wp_api' => true,
'version' => 'wc/v3',
'verify_ssl' => false,
]
Then you don't need to change any source code.
@wharfdale I faced the same problem. All you need to do is to open the file vendor\automattic\woocommerce\src\WooCommerce\HttpClient\Options.php and look for function verifySsl() and replace true with false. The line in the function should look like this after change
return isset($this->options['verify_ssl']) ? (bool) $this->options['verify_ssl'] : false;
This option sets curl options for verifying SSL to false in the woocommerece library and it works!