Linux 致命错误:调用未定义的函数 curl_init()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4396779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:58:17  来源:igfitidea点击:

Fatal error: Call to undefined function curl_init()

phplinuxubuntucurldebian

提问by Thew

<?php
$filename = "xx.gif";
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));

// $data is file data
$pvars   = array('image' => base64_encode($data), 'key' => IMGUR_API_KEY);
$timeout = 30;
$curl    = curl_init();

curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/2/upload.xml');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);

$xml = curl_exec($curl);

curl_close ($curl);

var_dump($xml);
?>

I'm playing with the Imgur API, but it doesn't seems to work. PHP.net says that curl_init()is in PHP5, but my host says it isn't. How can I make this work?

我正在使用 Imgur API,但它似乎不起作用。PHP.net 说这curl_init()是在 PHP5 中,但我的主人说它不是。我怎样才能使这项工作?

采纳答案by fire

curl is an extension that needs to be installed, it's got nothing to do with the PHP version.

curl是一个需要安装的扩展,与PHP版本无关。

http://www.php.net/manual/en/curl.setup.php

http://www.php.net/manual/en/curl.setup.php

回答by praveenmon

$ch = curl_init('http://api.imgur.com/2/upload.xml'); //initialising our url

curl_setopt($ch, CURLOPT_MUTE, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  //used for https headers 

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  //used for https headers

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($pvars));  
//the value we post

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //waiting for reponse, default value in php is zero ie, curls normally do not wait for a response

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0'); 

$output = curl_exec($ch); //the real execution 
curl_close($ch);

echo $output;

Try this code. I am not sure about it. But i used it to send xml data to a remote url.

试试这个代码。我不确定。但我用它来将 xml 数据发送到远程 url。

回答by Vinay

For Ubuntu

对于 Ubuntu

Install Curl extension for PHP & restart apache server.

为 PHP 安装 Curl 扩展并重新启动 apache 服务器。

sudo apt-get install php5-curl
sudo service apache2 restart

For Windows

对于 Windows

Problem arises because of not including the lib_curl.dll to PHP. also load following extension if not working,so those extension in php.inior remove comment if already exist in php.inifile then remove comment.

问题出现是因为没有将 lib_curl.dll 包含到 PHP 中。如果不起作用,还加载以下扩展名,因此php.ini如果php.ini文件中已存在这些扩展名或删除注释,则删除注释。

extension=php_bz2.dll
extension=php_curl.dll
extension=php_dba.dll

Now restart apache server. If you get an error "Unable to Load php_curl.dll", copy SSLEAY32.PHP, libEAY32.dll (OpenSSL) Libraries to the System32 folder.

现在重启apache服务器。如果您收到错误“无法加载 php_curl.dll”,请将 SSLEAY32.PHP、libEAY32.dll (OpenSSL) 库复制到 System32 文件夹。

回答by Mark Stosberg

On old versions of Debian and Ubuntu, you solved this by installing the Curl extension for PHP, and restarting the webserver. Assuming the webserver is Apache 2:

在旧版本的 Debian 和 Ubuntu 上,您通过为 PHP 安装 Curl 扩展并重新启动网络服务器来解决此问题。假设网络服务器是 Apache 2:

sudo apt-get install php5-curl
sudo service apache2 restart

On newer versions, the package name as changed:

在较新的版本上,包名称已更改:

sudo apt install php-curl

It's possible you'll need to install more:

您可能需要安装更多:

sudo apt-get install curl libcurl3 libcurl3-dev;

回答by Michael Irey

Don't have enough reputation to comment yet. Using Ubuntu and a simple:

还没有足够的声誉来发表评论。使用 Ubuntu 和一个简单的:

sudo apt-get install php5-curl
sudo /etc/init.d/apache2 restart

Did NOT work for me.

没有为我工作。

For some reason curl.sowas installed in a location not picked up by default. I checked the extension_dirin my php.ini and copied over the curl.soto my extension_dir

由于某种原因curl.so,安装在默认情况下未选择的位置。我检查了extension_dir我的 php.ini 并将其复制curl.so到我的extension_dir

cp /usr/lib/php5/20090626/curl.so  /usr/local/lib/php/extensions/no-debug-non-zts-20090626

Hope this helps someone, adjust your path locations accordingly.

希望这对某人有所帮助,相应地调整您的路径位置。

回答by Nemanja Vujacic

There is solution with all necessary details for Windows 7 x64:

对于 Windows 7 x64,有一个包含所有必要细节的解决方案:

http://www.youtube.com/watch?v=7qNTi1sEfE8

http://www.youtube.com/watch?v=7qNTi1sEfE8

It is in French, but you can understand everything! I solved same problem, even don't speak French. :-)

它是法语,但你可以理解一切!我解决了同样的问题,即使不会说法语。:-)

Many answers forget to mention that you need to add new version of php_curl.dll file from this location: http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64-64-bit-for-windows/

许多答案忘记提及您需要从该位置添加新版本的 php_curl.dll 文件:http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64 -64-bit-for-windows/

I added new version of php_curl.dll from archive php_curl-5.4.3-VC9-x64.zip to folders: C:\wamp\bin\php\php5.4.3\ext and C:\Windows\System32 and everything was fine!

我从存档 php_curl-5.4.3-VC9-x64.zip 添加了新版本的 php_curl.dll 到文件夹:C:\wamp\bin\php\php5.4.3\ext 和 C:\Windows\System32 一切都很好!

回答by David Majidian

This is from the official website. php.net

这是来自官方网站。php.net

After installation of PHP.

安装PHP后。

Windows

视窗

Move to Windows\system32 folder: libssh2.dll, php_curl.dll, ssleay32.dll, libeay32.dll

移动到 Windows\system32 文件夹:libssh2.dll、php_curl.dll、ssleay32.dll、libeay32.dll

Linux

Linux

Move to Apache24\bin folder libssh2.dll

移动到 Apache24\bin 文件夹 libssh2.dll

Then uncomment extension=php_curl.dll in php.ini

然后在php.ini中取消extension=php_curl.dll的注释

回答by jafar690

do this

做这个

sudo apt-get install php-curl

and restart server

并重启服务器

sudo service apache2 restart

回答by The Sammie

Experienced this on ubuntu 16.04 running PHP 7.1.14. To resolve,first put this in a script and execute. It will return true if curl is installed and enabled,otherwise, it will return false.

在运行 PHP 7.1.14 的 ubuntu 16.04 上体验过这个。要解决,首先将其放入脚本并执行。如果安装并启用了 curl,它将返回 true,否则将返回 false。

<?php
    var_dump(extension_loaded('curl'));
?>

If it returns false, run

如果返回 false,则运行

sudo apt-get install php7.1-curl

And finally,

最后,

sudo service apache2 restart

After the restart, the script will return true and hopefully, your error should be resolved.

重新启动后,脚本将返回 true,希望您的错误得到解决。

回答by Mazino S Ukah

for php 7.0 on ubuntu use

用于 ubuntu 上的 php 7.0 使用

sudo apt-get install php7.0-curl

And finally,

最后,

sudo service apache2 restart 

or

或者

sudo service nginx restart