原文链接:almalinux9编译php报错openssl.c,转载必须注明来源吴昊博客!
在el9(9.x)系统编译php8.1.27报错,该问题也可能在8.0、7.4等以下的版本中出现,报错内容如下:
In file included from php-8.1.27/main/php.h:425, from php-8.1.27/ext/openssl/openssl.c:27: php-8.1.27/ext/openssl/openssl.c: In function 'zm_startup_openssl': php-8.1.27/ext/openssl/openssl.c:1323:58: error: 'RSA_SSLV23_PADDING' undeclared (first use in this function); did you mean 'RSA_NO_PADDING'? 1323 | REGISTER_LONG_CONSTANT("OPENSSL_SSLV23_PADDING", RSA_SSLV23_PADDING, CONST_CS|CONST_PERSISTENT); ...... make: *** [Makefile:849: ext/openssl/openssl.lo] Error 1 make: *** Waiting for unfinished jobs....
|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 | In file included from php-8.1.27/main/php.h:425, from php-8.1.27/ext/openssl/openssl.c:27: php-8.1.27/ext/openssl/openssl.c: In function 'zm_startup_openssl': php-8.1.27/ext/openssl/openssl.c:1323:58: error: 'RSA_SSLV23_PADDING' undeclared (first use in this function); did you mean 'RSA_NO_PADDING'? 1323 | REGISTER_LONG_CONSTANT("OPENSSL_SSLV23_PADDING", RSA_SSLV23_PADDING, CONST_CS|CONST_PERSISTENT); ...... make: *** [Makefile:849: ext/openssl/openssl.lo] Error 1 make: *** Waiting for unfinished jobs.... |
分析原因:
这个错误表示在编译PHP扩展OpenSSL时,发生了一个未定义的符号错误 'RSA_SSLV23_PADDING',这通常是因为OpenSSL版本导致,在新版OpenSSL中已不再支持 'RSA_SSLV23_PADDING' 这个常量。
解决办法(理论适用于其它el9系统rockylinux9.x、almalinux9.x等):
编辑php目录下的ext/openssl/openssl.c文件
查找RSA_SSLV23_PADDING
将
REGISTER_LONG_CONSTANT("OPENSSL_SSLV23_PADDING", RSA_SSLV23_PADDING, CONST_CS|CONST_PERSISTENT);
|---|---------------------------------------------------------------------------------------------------| | 1 | REGISTER_LONG_CONSTANT("OPENSSL_SSLV23_PADDING", RSA_SSLV23_PADDING, CONST_CS|CONST_PERSISTENT); |
替换为以下内容,注意这里#号并不是注释的意思
#ifdef RSA_SSLV23_PADDING REGISTER_LONG_CONSTANT("OPENSSL_SSLV23_PADDING", RSA_SSLV23_PADDING, CONST_CS|CONST_PERSISTENT); #endif
|-------|------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | #ifdef RSA_SSLV23_PADDING REGISTER_LONG_CONSTANT("OPENSSL_SSLV23_PADDING", RSA_SSLV23_PADDING, CONST_CS|CONST_PERSISTENT); #endif |
重新编译即可,注意重新编译前请清理缓存。
最后, 建议大家可以通过添加wlnmp的源,一键yum安装,省去编译环节,可同时安装php5.6~php8.3的任意版本,也方便于管理。
curl -fsSL "https://sh.wlnmp.com/wlnmp.sh" | bash yum install wphp81 -y
|-----|--------------------------------------------------------------------------| | 1 2 | curl -fsSL "https://sh.wlnmp.com/wlnmp.sh" | bash yum install wphp81 -y |
wlnmp安装使用见: https://www.wlnmp.com/install