[PHP] 為PHP中的cURL安裝OpenSSL憑證

本文最後更新於:2024年5月2日 晚上

一、下載憑證

  1. 點選cacert.pem下載CA certificates extracted from Mozilla
    image.png

  2. 將憑證放置到伺服器的主機上,例如/etc/ssl/certs/cacert.pem

二、設定php.ini

  1. 開啟php.ini,並找到以下兩行

    ;openssl.cafile=
    ;openssl.capath=
  2. 刪除最前面的分號取消註解,並將下載的憑證路徑設定到這兩行上後儲存

    openssl.cafile=/etc/ssl/certs/cacert.pem
    openssl.capath=/etc/ssl/certs/cacert.pem

三、重新啟動Web Server

  1. 重新啟動web server

    # Apache
    systemctl httpd restart
    
    # Nginx
    systemctl nginx restart

    對於沒有systemd的Linux系統

    # Apache
    service stop httpd
    service start httpd
    
    # Nginx
    service stop nginx
    service start nginx
  2. 如果是使用php-fpm也要重新啟動

    service stop php7-fpm
    service start php7-fpm

[PHP] 為PHP中的cURL安裝OpenSSL憑證
https://hankz1108.github.io/posts/20231101-php-openssl/
作者
Hankz
發布於
2023年11月1日
更新於
2024年5月2日
許可協議