php无需重新编译安装openssl扩展

本文介绍在已安装PHP环境中,如何通过特定步骤为PHP安装openssl扩展,以便使用RSA算法。涉及的操作包括编译源码、配置环境变量及启用扩展等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文: http://blog.csdn.net/zouqingfang/article/details/52513275

PHP中使用RSA算法的时候,需要调用openssl_get_publickey方法,但同时需要对php编译openssl扩展,否则会提示以下错误:

[plain]  view plain  copy
 print ?
  1. Call to undefined function openssl_get_publickey()  
      

          由于php已经安装完毕,如何无需编译的情况下安装openss呢。这种方式操作步骤如下:

  • 进入php源代码路径

[plain]  view plain  copy
 print ?
  1. cd /php-5.6.19/ext/openssl  

  • 使用phpize编译

[plain]  view plain  copy
 print ?
  1. cp  config0.m4  config.m4  
  2. phpize  
           此时会生成configure文件,这样就可以使用make命令安装  

           特别说明:需要设置php安装路径的环境变量.

  • 执行make安装

[plain]  view plain  copy
 print ?
  1. ./configure --with-php-config=/usr/local/cp-php-5.6.19/bin/php-config --with-openssl  

             特别说明:需要先安装openssl

  • php.ini添加扩展配置openssl的扩展

[plain]  view plain  copy
 print ?
  1. extension=openssl.so  

  • 验证是否增加成功

[plain]  view plain  copy
 print ?
  1. php -m  

            可以看到php的所有的扩展


Centos系统, 刚开始用lnmp装的PHP环境,本来是要安装composer的,但是在这行这个命令的时候

curl -sS https://getcomposer.org/installer | php

就报错了:

Some settings on your machine make Composer unable to work properly.

Make sure that you fix the issues listed below and run this script again:


The openssl extension is missing, which means that secure HTTPS transfers are impossible.

If possible you should enable it or recompile php with --with-openssl

不能忍啊,于是就给php安装openssl扩展,首先进入PHP源码包的ext/openssl目录下,执行以下命令,参见:http://www.52jscn.com/web/2013/05/4592.shtml

mv config0.m4 config.m4
/var/www/php5/bin/phpize
./configure --with-openssl --with-php-config=/path/to/php5/bin/php-config
make
make install

果断生成openssl.so,于是添加到php.ini中,执行service php-fpm restart,果断报错:openssl是未识别的PHP扩展。

接着折腾,参见:http://www.cnblogs.com/ycoe/archive/2012/02/15/2352604.html

在php源码目录上使用 ./configure --help查看配置所有可用参数,可以发现,找不到 --enable-ssl
取而代之的是:
--with-openssl-dir 
--with-openssl
既然如此,就直接用它了
./configure  --with-openssl-dir=/usr/lib/openssl --with-openssl

目前仍在编译中~~~~


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值