0
0

More than 1 year has passed since last update.

【PHP】MAMPでcURL関数を使いたい(CAファイルの追記が必要)

Posted at

結論

  • cacert.pem(CA証明書をダウンロードする)
  • php.iniを書き換える

そもそもcURLが使える状況かどうか

  • php -m で確認
  • phpinfo() で確認

PHPでcurlを使えない場合の対処法 – Qiita

  • grepで確認
% php -i | grep cURL
cURL support => enabled
cURL Information => 7.64.1

cURLのインストール状況の確認

  • curl --version で確認
% curl --version
curl 7.78.0 (x86_64-apple-darwin20.4.0) libcurl/7.78.0 (SecureTransport) OpenSSL/1.1.1k zlib/1.2.11 brotli/1.0.9 zstd/1.5.0 libidn2/2.3.2 libssh2/1.9.0 nghttp2/1.44.0 librtmp/2.3 OpenLDAP/2.5.5
Release-Date: 2021-07-21
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL TLS-SRP UnixSockets zstd

→使える環境は整っていそう??

だが、cacert.pemファイルが指定された場所になかったのが原因だった

php – Windows MAMP-PHP CURLの問題

エラー

$curl_error = curl_error($ch) これでエラー内容をキャッチして表示する

“error setting certificate verify locations”

対応策

macのCAファイルの証明書が原因だった。

PHPのcurlでSSL certificate problemが出る場合

  • cacert.pem(CA証明書をダウンロードする)
  • php.iniを書き換える

MacOS – How to fix curl throwing “error setting certificate verify locations”

証明書が本来あるべき場所にない(または潜在的に読み取れない)と不平を言っている

php.iniの場所を確認

phpinfo() で確認

もういい加減覚えよう。php.iniはどこにあるのか – Qiita

php.iniに下記を追記してMAMPを再起動。

curl.cainfo =" " には、 curl_error($ch) で表示したエラーに「どこにファイルがない!」と教えてくれているので、そのパスをコピペする。

[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo = "/Applications/MAMP/Library/OpenSSL/cacert.pem"

最後に

自分の場合、MAMPをworkspaceにコピーして使用していたため(Railsとかをworkspaceで管理していたためそちらに合わせた)、User/名前/workspace/MAMP/〜の中のphp.iniを変更していたため、変更が反映されなかった。

エラーが教えてくれている通り、Applicationsフォルダの中のphp.iniに追記白ということだった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0