使用 phpipze 编译扩展报错的解决方法

作者: 温新

分类: 【PHP基础】

阅读: 1702

时间: 2023-03-08 05:44:03

hi,我是温新,一名 PHPer

这是一个错误记录专业。

前因后果

系统:Rocky Linux 9.1

源码安装挺容易出现问题的,而且还挺费时。

由于 windows 自动更新导致我的电脑开机出现黑屏,无法正常使用。因此我重置了系统,所以导致了 WSL 中的系统丢失,系统丢失了,所以,你懂得的...好在我是有备份。

那一刻我的心,很卧槽!

第一想法是重置完成后,直接换成虚拟机开发,虚拟机中的所有数据存放到第二块固态硬盘中,如此,不管出什么问题, 只要我固态硬盘是好的,那么我的数据就在。

于是,我又开始折腾搭建环境了,熟悉的配方,熟悉的味道,还是得出问题,问题是 openssl 的问题,无论我怎么装,都无法装上 openssl 扩展。因为,我直接换成 dnf 来安装了,安装过程很顺利,没有出现任何问题。当我安装 swoole 扩展时,出现了问题。

问题出现

安装 Swoole 扩展

./configure \
--with-php-config=/usr/bin/php-config \
--enable-openssl \
--enable-sockets

第一个问题出现(不是重点):

报错:

#
The php-devel package is required for use of this command.

解决:

#
dnf -y install php-devel

php-devel 信息:

dnf info php-devel
Last metadata expiration check: 0:41:45 ago on Wed Mar  8 00:43:27 2023.
Installed Packages
Name         : php-devel
Version      : 8.2.3
Release      : 1.el9.remi
Architecture : x86_64
Size         : 12 M
Source       : php-8.2.3-1.el9.remi.src.rpm
Repository   : @System
From repo    : remi-modular
Summary      : Files needed for building PHP extensions
URL          : http://www.php.net/
License      : PHP and Zend and BSD and MIT and ASL 1.0 and NCSA and Boost
Description  : The php-devel package contains the files needed for building PHP
             : extensions. If you need to compile your own PHP extensions, you will
             : need to install this package.

php-devel 版本与需要与 php 版本保持一致。

第二个问题出现(重点)

第二个问题出现了,openssl 的问题,报错信息如下:

#
PHP Warning:  PHP Startup: Unable to load dynamic library 'swoole.so' (tried: /usr/lib64/php/modules/swoole.so (/usr/lib64/php/modules/swoole.so: undefined symbol: socket_ce), /usr/lib64/php/modules/swoole.so.so (/usr/lib64/php/modules/swoole.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

解决:

第一步:预编译然后后续安装

./configure \
--with-php-config=/usr/bin/php-config \
--enable-sockets

第二步:添加扩展

# 添加 swoole 扩展
cd /etc/php.d/
echo 'extension=swoole.so' > 51-swoole.ini

第三步:重启 php-fpm

参考资料

https://blog.csdn.net/qq_39414590/article/details/103303039

我出现的问题和这篇文章出现的问题不一样,因此没有没能解决我的问题。我问题的根源是 openssl 问题。因此,做个记录,方便以后查阅。

openssl 问题

我在源码安装 PHP8.2.3 时,configure 通过,当执行 make 时,出现如下错误:

/usr/bin/ld: ext/openssl/openssl.o: in function `php_openssl_load_cipher_mode':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:7181: undefined reference to `EVP_CIPHER_flags'
/usr/bin/ld: /usr/local/src/php-8.2.3/ext/openssl/openssl.c:7201: undefined reference to `EVP_CIPHER_nid'
/usr/bin/ld: ext/openssl/openssl.o: in function `php_openssl_cipher_key_length':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:7661: undefined reference to `EVP_CIPHER_key_length'
/usr/bin/ld: ext/openssl/openssl.o: in function `php_openssl_cipher_iv_length':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:7632: undefined reference to `EVP_CIPHER_iv_length'
/usr/bin/ld: ext/openssl/openssl.o: in function `zif_openssl_pkey_get_details':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:4756: undefined reference to `EVP_PKEY_bits'
/usr/bin/ld: /usr/local/src/php-8.2.3/ext/openssl/openssl.c:4829: undefined reference to `EVP_PKEY_base_id'
/usr/bin/ld: ext/openssl/openssl.o: in function `zif_openssl_dh_compute_key':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:5051: undefined reference to `EVP_PKEY_base_id'
/usr/bin/ld: ext/openssl/openssl.o: in function `zif_openssl_digest':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:7129: undefined reference to `EVP_MD_size'
/usr/bin/ld: ext/openssl/openssl.o: in function `zif_openssl_sign':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:6726: undefined reference to `EVP_PKEY_size'
/usr/bin/ld: ext/openssl/openssl.o: in function `zif_openssl_seal':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:6839: undefined reference to `EVP_CIPHER_iv_length'
/usr/bin/ld: /usr/local/src/php-8.2.3/ext/openssl/openssl.c:6862: undefined reference to `EVP_PKEY_size'
/usr/bin/ld: /usr/local/src/php-8.2.3/ext/openssl/openssl.c:6875: undefined reference to `EVP_CIPHER_CTX_block_size'
/usr/bin/ld: ext/openssl/openssl.o: in function `zif_openssl_open':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:6968: undefined reference to `EVP_CIPHER_iv_length'
/usr/bin/ld: ext/openssl/openssl.o: in function `php_openssl_cipher_update':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:7374: undefined reference to `EVP_CIPHER_block_size'
/usr/bin/ld: ext/openssl/openssl.o: in function `php_openssl_cipher_init':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:7294: undefined reference to `EVP_CIPHER_iv_length'
/usr/bin/ld: /usr/local/src/php-8.2.3/ext/openssl/openssl.c:7323: undefined reference to `EVP_CIPHER_key_length'
/usr/bin/ld: ext/openssl/openssl.o: in function `php_openssl_cipher_iv_length':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:7632: undefined reference to `EVP_CIPHER_iv_length'
/usr/bin/ld: ext/openssl/openssl.o: in function `php_openssl_cipher_key_length':
/usr/local/src/php-8.2.3/ext/openssl/openssl.c:7661: undefined reference to `EVP_CIPHER_key_length'
/usr/bin/ld: ext/openssl/xp_ssl.o: in function `php_openssl_enable_crypto':
/usr/local/src/php-8.2.3/ext/openssl/xp_ssl.c:1961: undefined reference to `SSL_get_peer_certificate'
/usr/bin/ld: /usr/local/src/php-8.2.3/ext/openssl/xp_ssl.c:1945: undefined reference to `SSL_get_peer_certificate'
/usr/bin/ld: ext/phar/util.o: in function `phar_create_signature':
/usr/local/src/php-8.2.3/ext/phar/util.c:1877: undefined reference to `EVP_PKEY_size'
/usr/bin/ld: ext/mysqlnd/mysqlnd_auth.o: in function `mysqlnd_caching_sha2_public_encrypt':
/usr/local/src/php-8.2.3/ext/mysqlnd/mysqlnd_auth.c:1006: undefined reference to `EVP_PKEY_size'
/usr/bin/ld: ext/mysqlnd/mysqlnd_auth.o: in function `mysqlnd_sha256_public_encrypt':
/usr/local/src/php-8.2.3/ext/mysqlnd/mysqlnd_auth.c:705: undefined reference to `EVP_PKEY_size'
collect2: error: ld returned 1 exit status
make: *** [Makefile:305: sapi/cli/php] Error 1

我尝试了先去掉 --with-openssl,安装完成。安装完成后,我再通过 phpize 编译时,一切正常,当在 php.ini 文件中加上 openssl.so 时,就会报错,如下:

PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'openssl'

这个问题未能解决,如果你知道的话,不妨请赐教,谢谢!

请登录后再评论