如何让 CURL 在 Windows 上与 PHP 一起使用?(WAMP)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1343514/
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-25 02:06:52  来源:igfitidea点击:

How to get CURL to work with PHP on Windows? (WAMP)

phpcurlwamp

提问by Kip

Update: The problem appears to have been corrupt DLLs somewhere in my PHP installation, or possibly a bug in PHP 5.2.9 on Win2k. I downloaded the windows (binaries-only) distribution of PHP 5.2.10 from php.net and extracted that to my c:\PHP directory. After doing that, everything worked fine.

更新:问题似乎是我的 PHP 安装中某个地方的 DLL 损坏,或者可能是 Win2k 上 PHP 5.2.9 中的错误。我从 php.net 下载了 PHP 5.2.10 的 Windows(仅限二进制)发行版,并将其解压缩到我的 c:\PHP 目录中。这样做之后,一切正常。

Update2: I undid everything that I tried earlier (everything from the bulleted list below), exceptthat I left "extension=php_curl.dll" uncommented in my php.ini file. It turns out that is all you should have to do in a proper installation.

Update2:我取消了我之前尝试过的所有内容(下面项目符号列表中的所有内容),除了extension=php_curl.dll在 php.ini 文件中未注释“ ”。事实证明,这就是您在正确安装中应该做的所有事情。



I'm trying to get CURL to work on a Windows installation of PHP (version 5.2.9-2), and I am at wit's end. I have found the PHP CURL installation page, this SO questionwhich references this page, and this SO question. I've tried most of the suggestions in all of those pages but I still get an error. Here is my very simple test page:

我正在尝试让 CURL 在 PHP(版本 5.2.9-2)的 Windows 安装上工作,但我已经无计可施了。我已经找到了PHP CURL安装页面这太问题它引用此页面,而这太问题。我已经尝试了所有这些页面中的大部分建议,但仍然出现错误。这是我非常简单的测试页面:

<?php
$ch = curl_init();
?>
<b>Success!</b>

This gives me:

这给了我:

Fatal error: Call to undefined function curl_init() in C:\ApacheRoot\curltest.phpon line 2

致命错误:在第2行调用C:\ApacheRoot\curltest.php 中未定义的函数 curl_init()

In my Apache error log I get this each time the server starts:

在我的 Apache 错误日志中,每次服务器启动时我都会得到这个:

PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\PHP\\ext\\php_curl.dll' - The specified procedure could not be found.\r\n in Unknown on line 0

PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\PHP\\ext\\php_curl.dll' - The specified procedure could not be found.\r\n in Unknown on line 0

I have done the following:

我做了以下工作:

  • Uncommented the following line in php.ini: extension=php_curl.dll
  • Copied ssleay32.dlland libeay32.dllfrom C:\PHP to C:\WINNT\System32
  • Downloaded cURL for Win32 from curl.haxx.seand extracted the .zip file to C:\cURL
  • Added C:\cURLto my system PATH environment variable.
  • Verified that:
    • php.ini includes extension_dir="C:\PHP\ext"
    • The directory C:\PHP\extcontains php_curl.dll
    • The only php.inifile on my system is in C:\PHP(i.e. especially that there is no C:\WINNT\php.ini)
    • The Apache httpd.conffile includes the line PHPIniDir "C:/PHP/"
  • 在 php.ini 中取消注释以下行: extension=php_curl.dll
  • 复制ssleay32.dlllibeay32.dll从 C:\PHP 到 C:\WINNT\System32
  • curl.haxx.se下载了 Win32 的 cURL并将 .zip 文件解压缩到 C:\cURL
  • 添加C:\cURL到我的系统 PATH 环境变量中。
  • 证实:
    • php.ini 包括 extension_dir="C:\PHP\ext"
    • 该目录C:\PHP\ext包含php_curl.dll
    • php.ini我系统上唯一的文件在C:\PHP(即特别是没有C:\WINNT\php.ini
    • Apachehttpd.conf文件包含以下行PHPIniDir "C:/PHP/"

I have also rebooted the machine (several times, in fact...).

我还重新启动了机器(实际上有几次......)。

采纳答案by VolkerK

You don't have to reboot the computer, just restart the apache and the php module will read the new ini.
Did you change the correct php.ini? In case of doubt

您不必重新启动计算机,只需重新启动 apache,php 模块就会读取新的 ini。
您是否更改了正确的 php.ini?如有疑问

<?php echo 'php.ini: ', get_cfg_var('cfg_file_path'); ?>

can tell you.

可以告诉你。

Is there something in the error.log of the apache that indicates that something went wrong while loading php and the php_curl.dll?

apache 的error.log 中是否有某些内容表明在加载php 和php_curl.dll 时出现问题?

Did you start the apache as a win32 service? If you did try to start it as a console application. Error messages will show up on the console then. Or start it as a service and take a look at the error.log file andthe windows event log (start, run, eventvwr.msc /s).

您是否将 apache 作为 win32 服务启动?如果您确实尝试将其作为控制台应用程序启动。错误消息将显示在控制台上。或者将其作为服务启动并查看 error.log 文件Windows 事件日志(启动、运行、... eventvwr.msc /s)。

edit:
"The specified procedure could not be found"
You need a dll that is compatible with your php version and build. Exactly what did you install and where did you get it from?

编辑:
“找不到指定的程序”
您需要一个与您的 php 版本和构建兼容的 dll。你究竟安装了什么,你从哪里得到它?

回答by Mr. Smith

Try this:

尝试这个:

  1. Stop WAMP completely.
  2. Find your WAMP folder: C:\Path\To\WAMP\bin\Apache\ApacheVersion\bin\
  3. Edit that php.ini and uncomment extension=php_curl.dll
  4. Restart WAMP.
  1. 完全停止 WAMP。
  2. 找到您的 WAMP 文件夹:C:\Path\To\WAMP\bin\Apache\ApacheVersion\bin\
  3. 编辑那个 php.ini 并取消注释 extension=php_curl.dll
  4. 重新启动 WAMP。

That should hopefully solve it.

这应该有望解决它。

*EDIT: Do the same thing @ C:\Path\To\WAMP\bin\php\PHPVersion\

*编辑:做同样的事情@ C:\Path\To\WAMP\bin\php\PHPVersion\

回答by Abhishek Rakshit

This is what worked for me

这对我有用

Answered by Soren from another SO thread - CURL for WAMP

Soren 从另一个 SO 线程回答 - WAMP 的 CURL

"There seems to be a bug somewhere. If you are experiencing this on Win 7 64 bit then try installing apache addon version 2.2.9 and php addon version 5.3.1 and switching to those in WAMP and then activating the CURL extension. That worked for me."

“某处似乎存在错误。如果您在 Win 7 64 位上遇到此问题,请尝试安装 apache 插件版本 2.2.9 和 php 插件版本 5.3.1 并切换到 WAMP 中的那些,然后激活 CURL 扩展。那行得通为了我。”

回答by RustyIngles

This fixed it for me:

这为我修复了它:

Go to here:

去这里:

http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64-64-bit-for-windows/

http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64-64-bit-for-windows/

Download 'php_curl-5.3.13-VC9-x64.zip'

下载'php_curl-5.3.13-VC9-x64.zip'

Stop WAMP Server from Running

停止 WAMP 服务器运行

Extract the file 'php_curl.dll'.

提取文件“php_curl.dll”。

On your local machine, browse to (or where your WAMP installation is found) c:\wamp\bin\php\php5.3.13\ext

在本地计算机上,浏览到(或找到 WAMP 安装的位置)c:\wamp\bin\php\php5.3.13\ext

Rename php_curl.dll to php_curl.dll.old (or whatever you choose) and then copy the new file into the above directory.

将 php_curl.dll 重命名为 php_curl.dll.old(或您选择的任何名称),然后将新文件复制到上述目录中。

Restart WAMP Server

重启 WAMP 服务器

All should be working ok now.

现在应该一切正常。

回答by Master Drools

I had the same problem with php-5.5.26-Win32-VC11-x64 (on Windows) and I tried everything listed here with no luck. Finally I got it working by adding PHP installation directory to windows Path.

我在 php-5.5.26-Win32-VC11-x64(在 Windows 上)遇到了同样的问题,我尝试了这里列出的所有内容,但没有成功。最后,我通过将PHP 安装目录添加到 windows Path使其工作。

回答by DCR

With PHP 5.6.9 on Windows Server Core 2012 x64 cURL was not working, not showing up in phpinfo despite uncommenting php_curl.dll extension in my php.ini and restarting the Apache 2.4 service. Added the php path and the php\ext path to my $evn:path. No joy.

Windows Server Core 2012 x64 cURL 上的 PHP 5.6.9 不起作用,尽管在我的 php.ini 中取消注释 php_curl.dll 扩展并重新启动 Apache 2.4 服务,但 phpinfo 中没有显示。将 php 路径和 php\ext 路径添加到我的 $evn:path。没有喜悦。

Fix: I didn't need to download any other php_curl.dll file and couldn't find one for PHP 5.6 anyway. What finally worked was to copy these three files into the Apache24\bin folder then restart Apache:

修复:我不需要下载任何其他 php_curl.dll 文件,无论如何都找不到适用于 PHP 5.6 的文件。最终有效的是将这三个文件复制到 Apache24\bin 文件夹中,然后重新启动 Apache:

libeay32.dll

libeay32.dll

libssh2.dll

libssh2.dll

ssleay32.dll Copying these to System or System32 was not needed.

ssleay32.dll 不需要将这些复制到 System 或 System32。

回答by Lothre1

If the problem persists after you uncomment the module from both php.ini files (that people are already talking about and which are located on apache folder and php folder) and even after you check that you got the php_curl.dll ** at

如果从两个 php.ini 文件(人们已经在谈论并且位于 apache 文件夹和 php 文件夹中)中取消注释模块后问题仍然存在,甚至在您检查您是否获得了 php_curl.dll ** 之后

C:\WAMP\bin\php\php5.3.13\ext

C:\WAMP\bin\php\php5.3.13\ext

YOU SHOULD TRY TO REPLACE THE ORIGINAL DLL THAT COMES WITH WAMPSERVERwith one from this website:

您应该尝试将 WAMPSERVER附带的原始 DLL 替换为来自本网站的一个:

http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64-64-bit-for-windows/

http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64-64-bit-for-windows/

My problem was there! Hope it helps.

我的问题就在那里!希望能帮助到你。