PHP 로 새로운 사이트를 구축하다가 처음으로 curl error 77 을 만났습니다.

 CAfile: c:\devel\php\cacert.pem CApath: none (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://www.google.com/recaptcha/api/siteverify 
CODE


메시지로 봐서는 cacert.pem 의 경로가 잘못된것 같아서 php.ini 의 curl 항목을 점검했고 cacert.pem 파일도 존재했는데 계속 curl 77 에러가 발생했습니다. 

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo = c:/devel/php/cacert.pem
CODE

혹시나 해서 \ 를 / 로도 바꿔보고 쌍따옴표("")로 감싸줘도 봤지만 동일한 에러가 발생해서 pem 파일 확인을 위해서 에디터로 열어 보았습니다.


파일을 열어 보니 pem 형식 파일이 아닌 다음과 같은 잘못된 파일이었습니다.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://curl.se/ca/cacert.pem">here</a>.</p>
<hr>
<address>Apache Server at curl.haxx.se Port 80</address>
</body></html>
CODE


아마 다음 명령어로 cacert.pem 을 다운받았는데 follow 301 302 옵션을 안 주어서 HTML 을 다운받았나 봅니다.

curl -k -O https://curl.haxx.se/ca/cacert.pem
BASH


기존의 cacert.pem 을 삭제하고 301이나 302 응답시 location 을 따라 가도록 -L 옵션을 추가해서 cacert.pem 을 다운받았더니 해결되었습니다.

curl -k -O -L https://curl.haxx.se/ca/cacert.pem
BASH


같이 보기