去PHP官网下载和你当前版本一样的原码,解压,注意要指定新的curl目录
/root/software/php-5.6.40/ext/curl
phpize
./configure –with-curl=/usr/local/curl/
make
make install
如果是php8的curl扩展到这一步要报错:
checking for cURL support… yes, shared
checking for libcurl >= 7.29.0… no
configure: error: Package requirements (libcurl >= 7.29.0) were not met:
No package ‘libcurl’ found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables CURL_CFLAGS
and CURL_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
报下面的错误的话要这样make:
/root/software/php-8.3.1/ext/curl/multi.c: In function ‘curl_multi_get_gc’:
/root/software/php-8.3.1/ext/curl/multi.c:572:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
或者修改代码,把那一行的行内定义提出去,或者用下面的命令编译:
make CFLAGS=-std=c99
最后测试一下:
php -r “phpinfo();” | grep cURL
输出
cURL support => enabled
cURL Information => 8.2.1
没有问题,如果是fpm,要重启fpm。
其它的问题
如果在编译的时候出现很多语法错误,有可能是系统安装了多个php版本,引用到了错误的php头文件,在.configure的时候,要指定–with-php-config
安装好扩展之后,但加载扩展如果出现下面的错误,是因为php扩展和curl的版本不对,需要下载新的curl版本重新安装。
PHP Warning: PHP Startup: Unable to load dynamic library ‘curl’ (tried: /opt/remi/php83/root/usr/lib64/php/modules/curl (/opt/remi/php83/root/usr/lib64/php/modules/curl: cannot openshared object file: No such file or directory), /opt/remi/php83/root/usr/lib64/php/modules/curl.so (/opt/remi/php83/root/usr/lib64/php/modules/curl.so: undefined symbol: curl_easy_escape)) in Unknown on line 0