Linux 编译 php 5 错误 error: dereferencing pointer to incomplete type ‘X509_EXTENSION’

Php 2020-07-04 阅读 759 评论 0

问题描述

Linux 系统(Ubuntu/Debian/RHEL/CentOS)编译 PHP 5 版本,启用 openssl扩展。

$ ./configure --prefix=/opt/php-5.6.40 --with-openssl
$ make

最后出现 一下错误。

/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:1904:15: error: dereferencing pointer to incomplete type ‘X509_EXTENSION’ {aka ‘struct X509_extension_st’}
 1904 |  p = extension->value->data;
      |               ^~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:1982:10: error: dereferencing pointer to incomplete type ‘X509’ {aka ‘struct x509_st’}
 1982 |  if (cert->name) {
      |          ^~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:3485:14: error: dereferencing pointer to incomplete type ‘EVP_PKEY’ {aka ‘struct evp_pkey_st’}
 3485 |  switch (pkey->type) {
      |              ^~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c: In function ‘php_openssl_pkey_init_dsa’:
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:3557:10: error: dereferencing pointer to incomplete type ‘DSA’ {aka ‘struct dsa_st’}
 3557 |  if (!dsa->p || !dsa->q || !dsa->g) {
      |          ^~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c: In function ‘php_openssl_pkey_init_dh’:
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:3580:9: error: dereferencing pointer to incomplete type ‘DH’ {aka ‘struct dh_st’}
 3580 |  if (!dh->p || !dh->g) {
      |         ^~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c: In function ‘zif_openssl_pkey_new’:
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:3548:9: error: dereferencing pointer to incomplete type ‘RSA’ {aka ‘struct rsa_st’}
 3548 |    _type->_name = BN_bin2bn(         \
      |         ^~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:4801:13: error: storage size of ‘md_ctx’ isn’t known
 4801 |  EVP_MD_CTX md_ctx;
      |             ^~~~~~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c: In function ‘zif_openssl_verify’:
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:4859:17: error: storage size of ‘md_ctx’ isn’t known
 4859 |  EVP_MD_CTX     md_ctx;
      |                 ^~~~~~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c: In function ‘zif_openssl_seal’:
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:4920:17: error: storage size of ‘ctx’ isn’t known
 4920 |  EVP_CIPHER_CTX ctx;
      |                 ^~~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c: In function ‘zif_openssl_open’:
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:5048:17: error: storage size of ‘ctx’ isn’t known
 5048 |  EVP_CIPHER_CTX ctx;
      |                 ^~~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c: In function ‘zif_openssl_digest’:
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:5154:13: error: storage size of ‘md_ctx’ isn’t known
 5154 |  EVP_MD_CTX md_ctx;
      |             ^~~~~~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c: In function ‘zif_openssl_encrypt’:
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:5233:17: error: storage size of ‘cipher_ctx’ isn’t known
 5233 |  EVP_CIPHER_CTX cipher_ctx;
      |                 ^~~~~~~~~~
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c: In function ‘zif_openssl_decrypt’:
/home/cpm/Downloads/packages/php-5.6.40/ext/openssl/openssl.c:5316:17: error: storage size of ‘cipher_ctx’ isn’t known
 5316 |  EVP_CIPHER_CTX cipher_ctx;
      |                 ^~~~~~~~~~
make: *** [Makefile:521: ext/openssl/openssl.lo] Error 1

解决方法

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
$ ./config --prefix=/opt/openssl-1.0.2u
$ make
$ sudo make install

修改 -with-openssl 的路径,重新编译 PHP。

$ ./configure --prefix=/opt/php-5.6.40 --with-openssl=/opt/openssl-1.0.2u
$ make
$ make install
最后更新 2020-07-04