Mac OS 编译 php 5 错误 incomplete definition of type 'struct X509_extension_st'
问题描述
在 Mac OS 的 PHP 系列上使用 openssl_encrypt()
方法,报错了。
Call to undefined function openssl_encrypt()
需要安装 openssl
扩展,重新编译 PHP 时加上 --with-openssl
,运行:
$ brew install openssl
$ ./configure --prefix=/opt/php --with-openssl=/Volumes/develop/opt/openssl-1.1.1g
$ make
$ sudo make install
在 PHP 7 没有问题,但是在 PHP 5.4.45/5.5.38/5.6.40,运行 make
命令,最后报错了。
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:1433:15: error: incomplete definition of type 'struct X509_extension_st'
p = extension->value->data;
~~~~~~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:1434:20: error: incomplete definition of type 'struct X509_extension_st'
length = extension->value->length;
~~~~~~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:1511:10: error: incomplete definition of type 'struct x509_st'
if (cert->name) {
~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:1512:46: error: incomplete definition of type 'struct x509_st'
add_assoc_string(return_value, "name", cert->name, 1);
~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3002:14: error: incomplete definition of type 'struct evp_pkey_st'
switch (pkey->type) {
~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3007:47: error: incomplete definition of type 'struct evp_pkey_st'
if (pkey->pkey.rsa != NULL && (NULL == pkey->pkey.rsa->p || NULL == pkey->pkey.rsa->q)) {
~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3007:76: error: incomplete definition of type 'struct evp_pkey_st'
if (pkey->pkey.rsa != NULL && (NULL == pkey->pkey.rsa->p || NULL == pkey->pkey.rsa->q)) {
~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3020:20: error: incomplete definition of type 'struct evp_pkey_st'
if (NULL == pkey->pkey.dsa->p || NULL == pkey->pkey.dsa->q || NULL == pkey->pkey.dsa->priv_key){
~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3020:49: error: incomplete definition of type 'struct evp_pkey_st'
if (NULL == pkey->pkey.dsa->p || NULL == pkey->pkey.dsa->q || NULL == pkey->pkey.dsa->priv_key){
~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3020:78: error: incomplete definition of type 'struct evp_pkey_st'
if (NULL == pkey->pkey.dsa->p || NULL == pkey->pkey.dsa->q || NULL == pkey->pkey.dsa->priv_key){
~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3029:20: error: incomplete definition of type 'struct evp_pkey_st'
if (NULL == pkey->pkey.dh->p || NULL == pkey->pkey.dh->priv_key) {
~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3029:48: error: incomplete definition of type 'struct evp_pkey_st'
if (NULL == pkey->pkey.dh->p || NULL == pkey->pkey.dh->priv_key) {
~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3038:45: error: incomplete definition of type 'struct evp_pkey_st'
if ( NULL == EC_KEY_get0_private_key(pkey->pkey.ec)) {
~~~~^
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3094:6: error: incomplete definition of type 'struct rsa_st'
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), rsa, n);
^ ~~~
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3095:6: error: incomplete definition of type 'struct rsa_st'
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), rsa, e);
^ ~~~
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3096:6: error: incomplete definition of type 'struct rsa_st'
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), rsa, d);
^ ~~~
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3097:6: error: incomplete definition of type 'struct rsa_st'
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), rsa, p);
^ ~~~
/Users/cpm/Downloads/packages/php-5.4.45/ext/openssl/openssl.c:3098:6: error: incomplete definition of type 'struct rsa_st'
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), rsa, q);
^ ~~~
解决方法
PHP 5 不能使用最新版的 openssl 编译,可以降低 openssl 的版本。
$ curl -O https://www.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz
$ tar xf openssl-1.0.2u.tar.gz
$ cd openssl-1.0.2u
$ ./Configure darwin64-x86_64-cc --prefix=/opt/openssl-1.0.2u
$ make
$ sudo make install
注意:此处编译 openssl 时加上了 darwin64-x86_64-cc
选项,我的电脑是 64 位,默认是按照 32 位编译。
修改 -with-openssl
的路径,重新编译 PHP。
$ ./configure --prefix=/opt/php --with-openssl=/opt/openssl-1.0.2u
$ make
$ sudo make install
非特殊说明,本网站所有文章均为原创。如若转载,请注明出处:https://mip.cpming.top/p/mac-php5-configure-openssl-error