Why did I get the error "curl_exec error 58: unable to set private key file" with the PHP SDK?

You got a private key file error.

This error usually occurs if:

  • The file your code references doesn't contain the private key. When you request an API Certificate, PayPal gives it to you as a cert_key_pem.txt file. The file contains two parts: a private key and a certificate. You need both parts in the file for cURL to be able to securely connect to the API servers.
  • There are problems with the client-side Certificate.

Solutions Missing private key or Certificate
Check your API Certificate file and make sure it contains both the private key and Certificate. If either item is missing:
  1. Log in to your PayPal account.
  2. Re-download the cert_key_pem.txt file.
  3. Open the file and check that it has both a private key and a certificate.
  4. If it does, rename it and give it a .pem extension (for example, cert_key.pem).
  5. Upload this file to your server.
  6. Reference it as your API Certificate in your code or for the Web Console.
  7. Visit PayPal's Contact Customer Service page to report this issue and for further troubleshooting assistance.

Client-side Certificate problems
Here's how to troubleshoot these issues:
  • Check that the path to the API Certificate file is correct.
  • Make sure that the script (or web server running the script) has permission to read the Certificate file.
  • Check that the path specified points to a Certificate file.
  • Check that the Certificate file isn't corrupt (extraneous data could have been added, or part of the Certificate may have been deleted).

Note: You won't see cURL error 58 when you use an incorrect username or password in the SOAP request; you can expect a 10002 error from the PayPal Web Services system instead.

See also:
How do I request API Signature or Certificate credentials?
cURL with SSL certificates fails: error 58 unable to set private key file
cURL documentation on --cert