SOLVED: Error: Peer certificate cannot be authenticated with given CA certificates.

After going crazy for about two hours to solve this simple error: “Peer certificate cannot be authenticated with known CA certificates using PHP OAuth extension” I searched for many queries like “unable to get local issuer certificate” or “cacert.pem” and finally figured it out.

If you search online you will run into a lot of cacert.pem solutions but its actually not the right one.
Lets get right into it:

1) Download the certificate file like

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

2) Copy the downloaded file and paste to the following directory and make sure the read/write permission are setup correctly.

/WHATEVER-APP-YOU-ARE-USING/openssl/cacert.pem 

(replace the first folders with your own app.) For example Im using AMPPS so my file directory is different than MAMP or XMPP. Very imporant to get the correct path here.

3)Add the following line to your php.ini (make sure its the correct version and dont just drop it the the first one you see there)

openssl.cafile=/Applications/AMPPS/php-5.6/cacert.pem 

4) Restart the Apache Server and you are good to go.

If you cant get this going then go back and see what you did wrong because it works