问题描述
打开PHP.ini,找到
;extension=php_curl.dll
去掉注释保存后,重启Apache,访问http://localhost/test.php。test.php代码如下
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "http://www.kevinbai.com");
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
echo $output;
然而还是报错
Call to undefined function curl_init()
注意:在此之前查看phpinfo,有如下内容
Loaded Configuration File D:\PHPEnvironment\php-5.6.24\php.ini
所以已保证配置加载成功
解决方案
找了很多文章,最后在官网上http://php.NET/manual/en/curl.examples.php看到相关描述
I had to also also copy libssh2.dll into my Apache24 folder for this
to work with my PHP 5.6.2 installation. So altogether I had to do the
following:
Move to Windows\system32 folder:
libssh2.dll, php_curl.dll, ssleay32.dll, libeay32.dll
Move to Apache24\bin folder
libssh2.dll
Uncomment extension=php_curl.dll
我将php安装目录下的libssh2.dll复制到apache的bin目录,并重新启动Apache,于是cURL成功开启。
注意:我的刚开始已经完成上述步骤,但是是在windows命令行工具下用的httpd -k restart重启的Apache,结果仍然报Call to undefined function curl_init()的错误。之后无意中在windows服务窗口中右键Apache服务,重启后成功。