Why does PHP refuse to enable cURL on Windows
Asked Answered
H

4

8

I am using PHP 5.5.25 with Apache 2.4 on Windows 7 x64 and I am unable to activate the cURL module. I have looked around and tried all I could think of. Please assist:

  • In php.ini, the line extension=php_curl.dll is active and the file php_curl.dll is present in the extensions directory C:\php\ext
  • In php.ini when I set extension_dir = ext, none of the extensions load. I get several messages when Apache starts, similar to Unable to load dynamic libraryext\php_openssl.dll- The specified module could not be found.
  • When I use the full path and set extension_dir = C:\php\ext, all the extensions load fine, except for cURL. I get the error: Unable to load dynamic libraryC:\php\ext\php_curl.dll- The specified module could not be found.
  • I have tried renaming the extension to php_curl.new.dll and adjusting php.ini but I get an error message about the new filename. I have also downloaded a fresh new copy of the DLL from windows.php.net, but that made no difference.
  • I have checked the file permissions for php_curl.dll (Right-click on the file >> Properties >> Security tab) and they are the same as the permissions for extensions that load successfully
  • I have copied and pasted libeay32.dll and ssleay32.dll from the PHP bin directory to the System32 and SysWOW64 directories as instructed by a response to this question
  • I am certain that I am editing the right php.ini since the PHP startup error messages changed when I changed the extension_dir value from ext to C:\php\ext as I explained above.
  • I have made sure to restart the Apache server between php.ini configuration changes.
  • If in a PHP script I execute var_dump(file_exists('C:\php\ext\php_curl.dll'));, I get boolean True so PHP can see the file!

What else could explain why the cURL module is not enabled?

Humane answered 10/9, 2015 at 5:1 Comment(0)
C
11

I think you'll need libssh2.dll in your PATH too.

Coxswain answered 10/9, 2015 at 5:33 Comment(5)
That worked! Copying random DLLs from C:\php to C:\Windows\SysWOW64 may cause a problem later because when I change PHP versions I won't remember to overwrite those copies with the new versions' DLLs. I am thinking instead of adding C:\php to the Windows PATH variable. This way all PHP DLL files can stay together and be easier to maintain. Do you see any big downside to that?Humane
No, that's a sensible thing to do. Although you mean C:\php\ext, right? It's a long time since I've run PHP on Windows...Coxswain
The extensions are in C:\php\ext, bu the DLLs Windows couldn't see are in C:\phpHumane
Placing this file in the same location as php.exe, and php.ini (together) resolved this issue. Missed that little file.Spheroidicity
It took me a long time to reach this answer. Thanks!!Northeaster
H
4

Credit goes to @Steven Hilder for pointing me in the right direction.

The problem was that Windows could not see libssh2.dll, another DLL that was in PHP's directory. Copying this file to C:\Windows\SysWOW64 and C:\Windows\System32, along with the other two DLL files from my OP (libeay32.dll and ssleay32.dll) worked.

I am uncomfortable with this solution though because when the time comes to update to a new PHP version I will have a harder time remembering to overwrite these DLLs with the new version. Therefore, I decided to remove all 3 DLLs from the System32 and SysWOW64 directories. Instead, I just added the PHP bin directory to the Windows' PATH variable, so that the next time the OS is looking for a missing file, it will also look in that directory. This has the added bonus that if a similar problem with another DLL occurs, it will be resolved automatically.

To add the PHP bin to Windows' PATH:

  1. From the Start Menu search bar, search for and select Advanced system settings
  2. Click Environment Variables. Scroll down the list of System variables to select Path and click Edit... to open the current PATH setting
  3. Append ;C:\php or whatever directory has php.exe to the current setting (semi-colon is used to separate paths).
Humane answered 10/9, 2015 at 6:25 Comment(0)
R
2

on windows the cURL execution wants SSL certificate. may be because of that others error is showing.

Put the below code before curl_exec(curlHandle) to ignore checking for SSL certificate

//to ignore the SSL certificate in windows
        curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER,false);
Rubalcava answered 10/9, 2015 at 5:59 Comment(1)
The cURL module would not load at all, so no cURL function was available to my script. My problem was that the OS needed but could not find libssh2.dll.Humane
G
0

Every time I had an issue with php modules the it was related to libraries lack or overlap.

Let's say that the best option is to add php folder to PATH env variable.

However sometimes it is not enought. If php standalone (without apache) loads the module, probably the dll in php folder are ok but apache doesn't load them because some other folders with same libraries has priority (es. system32 or other programs).

In this case just copy all dll in main php folder into apache/bin folder.

Gitlow answered 5/7 at 9:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.