Reputation: 5
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'hello_world');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CAINFO, getcwd().'/ca.pem');
curl_setopt($curl, CURLOPT_SSLCERT, getcwd().'/client.pem');
curl_setopt($curl, CURLOPT_SSLKEY, getcwd().'/key.pem');
$post = array(
// ...
);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, join('&', $post));
$curl_result = curl_exec($curl);
$error = curl_error($curl);
var_dump($curl_result);
var_dump($error);
curl_close($curl);
this script work in console "php simple.php" but this script not working in browser
boolean false
string 'NSS: private key not found for certificate: PEM Token #1:client.pem' (length=67)
please help
` cd /path/to/simple.php; ls -la -rwxrwxrwx 1 ujin apache 1.4K Jan 19 19:03 simple.php -rw-r--r-- 1 ujin apache 2.6K Jan 19 15:58 ca.pem -rw-r--r-- 1 ujin apache 1.6K Jan 19 15:59 client.pem -rw-r--r-- 1 ujin apache 1.1K Jan 19 16:18 key.pem `
Upvotes: 0
Views: 1762
Reputation: 65324
Your script can't find the ca.pem and friends. Some things to try
https://www.php.net/manual/en/function.curl-setopt.php tells us, that CURLOPT_CAINFO needs an absolute path!
EDIT (after discussion with @UJin):
please try the absolute paths:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'hello_world');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$cwd=getcwd();
//DEBUG
echo "cwd=$cwd\n";
curl_setopt($curl, CURLOPT_CAINFO, "$cwd/ca.pem");
curl_setopt($curl, CURLOPT_SSLCERT, "$cwd/client.pem");
curl_setopt($curl, CURLOPT_SSLKEY, "$cwd/key.pem");
Upvotes: 1