为PHP增加OpenSSL扩展

目录

程序需要 OpenSSL 支持时,常见错误:

unable to connect to ssl://gateway.sandbox.push.apple.com:2195
(Unable to find the socket transport ssl - did you forget to enable it when you configured PHP?

检查是否已安装

查看 php 已编译的所有模块:

php -m | grep openssl

或通过 phpinfo() 函数查看。

安装步骤

  1. 确定 PHP 版本
php -v
  1. 下载对应版本源码
wget http://museum.php.net/php5/php-5.3.6.tar.gz
tar zxvf php-5.3.6.tar.gz
  1. 编译 openssl 扩展
cd php-5.3.6/ext/openssl/
cp config0.m4 config.m4
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-openssl
make
make install
  1. 在 php.ini 中添加扩展
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
extension = "openssl.so"
  1. 重启 Apache
/usr/local/apache/bin/apachectl -k restart

参考:为PHP添加PDO-mysql驱动

#php #ssl-tls