安装 PHP7.2.4 curl 扩展:

学习慕课网-Swoole入门到实战打造高性能赛事直播平台-7.9 章节时报错 undefined curl_init(),导致无法发送阿里大鱼短信,以下是报错信息

PHP Fatal error:  Uncaught Error: Call to undefined function Aliyun\Core\Http\curl_init() in /home/misswell/Code/thinkphp_5.1.0_rc/extend/ali/lib/Core/Http/HttpHelper.php:13

原因是缺少 curl 扩展

我的安装代码:

misswell@ubuntu:~/Downloads$ wget http://curl.haxx.se/download/curl-7.32.0.tar.gz
misswell@ubuntu:~/Downloads$ tar zxvf curl-7.32.0.tar.gz 
misswell@ubuntu:~/Downloads$ cd curl-7.32.0
misswell@ubuntu:~/Downloads/curl-7.32.0$ ./configure --prefix=/usr/local/curl
misswell@ubuntu:~/Downloads/curl-7.32.0$ cd  ../php-7.2.4/ext/curl/
misswell@ubuntu:~/Downloads/php-7.2.4/ext/curl$ /home/misswell/soft/php/bin/phpize 
misswell@ubuntu:~/Downloads/php-7.2.4/ext/curl$ ./configure --with-php-config=/home/misswell/soft/php/bin/php-config  --with-curl=/home/misswell/Downloads/curl-7.32.0
misswell@ubuntu:~/Downloads/php-7.2.4/ext/curl$ make && make install
...
Installing shared extensions:     /home/misswell/soft/php/lib/php/extensions/no-debug-non-zts-20170718/

解释:

php源码目录:/home/misswell/Downloads/php-7.2.4/

php编译目录:/home/misswell/soft/php/

curl源码目录:/home/misswell/Downloads/curl-7.32.0/

1.curl,主要用于发送http请求,是php的一个扩展包。
2.安装过程:
(1)curl下载:http://curl.haxx.se/download.html
(2)具体安装过程:

wget http://curl.haxx.se/download/curl-7.32.0.tar.gz

tar zxvf curl-7.32.0.tar.gz

cd curl-7.32.0

./configure --prefix=/usr/local/curl

cd /(php源码目录)/ext/curl

运行phpize: /(php编译目录)/bin/phpize

./configure --with-php-config=/(php编译目录)/bin/php-config --with-curl=/(curl源码目录)

make && make install

修改php.ini,增加:extension=curl.so(如果没有安装过其他php扩展,则需要同时配置extension_dir="/(php编译后目录)/lib/php/extensions/no-debug-non-zts-20121212/",上一个步骤生成.so文件的时候,会输出extension_dir目录)

(3)检验是否安装成功:

/(php编译后目录)/bin/php -m | grep curl ——正常打印curl,则表示安装成功(php -m会打印出已安装的扩展模块)

1 Comment

发表评论

电子邮件地址不会被公开。 必填项已用*标注