39

Follow-up from my post yesterday (Enabling cURL with PHP)

The problem is that PHP isn't able to load php_curl.dll. I've tried several steps including uncommenting extension=php_curl.dll, making sure the dependencies libeay32.dll and ssleay32.dll eixst in the path, re-downloading php_curl.dll, replacing the old one, and lastly copying the file into my System32 folder.

I'm using Apache 2.2 and PHP 5.4.14. I installed both using their individual packages; I'm not using XAMP or WAMP. I'm using Windows 7 64-bit.

Any help at all would be appreciated.

Community
  • 1
  • 1
user2066880
  • 4,825
  • 9
  • 38
  • 64
  • 1
    possible duplicate of [Enabling cURL with PHP](http://stackoverflow.com/questions/16403376/enabling-curl-with-php) – Marc B May 07 '13 at 16:35
  • i had this problem there is a solution which i don't think i give without breaking the rules. - ---removed-- - if this does break the rules please edit/ delete thanks – unasAquila May 07 '13 at 16:38
  • Same problem, but no answer on that thread – user2066880 May 07 '13 at 16:38
  • I installed PHP and Apache using their individual packages. I'll edit my post to reflect that. Thanks for the response though! – user2066880 May 07 '13 at 16:39
  • ok edit your question to not include the other tools just say clean install no 3rd party program used – unasAquila May 07 '13 at 16:42
  • @user2066880 - have you tried the fixed php_curl.dll from http://www.mediafire.com/?3ay381k3cq59cm2 ? – unasAquila May 07 '13 at 16:50
  • Yep I've looked at it already. I'm running x86 PHP and all the fixed php_curl.dll's are 64 bit. – user2066880 May 07 '13 at 17:07
  • This question is still relevant to Apache 2.4.x (.27) and PHP 7.1.x (.9) and will no doubt continue to be until, if ever, the relevant common DLLs are shipped with version number as part of the filename... – Jake Sep 02 '17 at 01:11

15 Answers15

77

libeay32.dll and ssleay32.dll have to be path-accessible for php_curl.dll loading to succeed.

But copying them into Apache's ServerRoot, Apache's \bin\, Window's \System32\, or even worse into the Windows main directory is a bad hack and may not even work with newer PHP versions.

The right way to do it is to add the PHP path to the Windows Path variable.

  1. In Control Panel -> System click on Advanced System Settings or press WIN+R and type SystemPropertiesAdvanced
  2. Click the button Environment Variables.
  3. Under System Variables you will find the Path variable. Edit it and prepend C:\PHP; to it - or whatever the path to your PHP folder is.
    (Hint: If your PHP folder contains spaces like C:\Program Files\PHP you may need to use the short filename form here, i.e. C:\Progra~1\PHP.)
  4. Then fully stop Apache and start it again (a simple restart might not be enough).

Update 2017-05:
I changed the instructions above to prepend the Path variable with the PHP path instead of appending to it. This makes sure that the DLLs in the PHP path are used and not any other (outdated) versions in other paths of the system.

Update 2018-04:
If you have already chosen the wrong way and copied any of the PHP DLLs to Apache or Windows paths, then I strongly recommend that you remove them again! If you don't, you might get into trouble when you later try to update PHP. If a new PHP version brings new versions of these DLLs, but your old DLLs still linger around in system or webserver paths, these old DLLs might be found first. This will most certainly prevent the PHP interpreter from starting. Such errors can be very hard to understand and resolve. So better clean up now and remove any of the mentioned DLLs from Windows and Apache paths, if you copied them there.
(Thanks to @EdmundTam and @WasimA. for pointing out this problem in the comments!)

Update 2019-10:
Tip: To find all copies of these DLLs and check whether you might have placed them in the wrong folders, you can use the following commands in a Windows Command Prompt window:

dir c:\libeay32.dll /s
dir c:\ssleay32.dll /s

Be warned that these commands may take some time to complete as they search through the entire directory structure of your system drive C:.

Update 2020-08:
If your PHP folder contains spaces (i.e. C:\Program Files\PHP) you may need to use the short filename form in the Path variable at step 3 (i.e. C:\Progra~1\PHP). Thanks to @onee for this tip!

Jpsy
  • 20,077
  • 7
  • 118
  • 115
  • 8
    This was what finally worked for me - no custom dll nonsense required. – J c Dec 02 '14 at 09:31
  • 6
    Adding the PHP directory to the PATH variable was the thing to do in my case. Thanks. – kmas May 19 '15 at 14:26
  • 3
    Just wanted to add that after adding the PATH variable restarting apache using -k restart was not enough for me. I had to stop it completely then start it again. – Sean256 Nov 09 '15 at 20:03
  • Applied just now, Windows 10, WAMP 2.5, PHP 7.0.2. Thank you – Diana Jan 29 '16 at 19:45
  • 2
    This worked for me, but I just wanted to add that I had to restart windows in order for this to work. Just restarting Apache was not good enough. – brant Nov 03 '16 at 17:28
  • @brant did you restart or did you do a full stop and start? See comment of Sean256 above. – Jpsy Nov 03 '16 at 19:31
  • Restart was definitely required. Using PHP 5.6.27 EasyPHP Win10. – dchayka Nov 30 '16 at 19:53
  • http://stackoverflow.com/questions/41107356/apache-2-4-23-php7-x-windows-10-x64-php-curl-not-working – Wasim A. Dec 12 '16 at 19:04
  • FWIW, having php on the path was insufficient for me running php 7.1.5 and Apache 2.4.10. I needed to update the files in the apache bin dir. I perhaps oughta update Apache (it's up to 2.4.25 at time of writing), and see if the versions of those DLLs it ships with are sufficient. Obvs I'd rather *not* be mix 'n' matching DLLs like this, but equally I don't wanna be messed around too much on this which is just a dev machine anyhow. – Adam Cameron May 27 '17 at 20:11
  • Hi @AdamCameron, your problem was most likely the result of the Apache path being stored in the `Path` variable too. I updated my answer so that the PHP path is _prepended_ instead of _appended_. This makes sure that the DLLs in the PHP path are used and not any other versions that may exist in other paths of the system. – Jpsy May 29 '17 at 07:58
  • Hi @Jpsy nah, don't have Apache in the path. Not to worry. I've got some spare time today so I might roll back this change, update Apache to be current, and see if the problem still persists (and will report back). – Adam Cameron May 29 '17 at 12:06
  • Ah! Thank you! It worked for me. I had environment variable to a different version of PHP – Anos K. Mhazo Aug 26 '17 at 17:57
  • On Windows 10 you do need to reboot after changing the PATH variable (which I'm pretty sure was never necessary with Windows 7). It's called 'progress' :/ (I had Perforce with these DLLs in the path ahead of PHP which was causing the issue; Perforce seems to be ok with the change.) – Jake Sep 02 '17 at 01:01
  • 2
    After a lot of search, finally it works when I add path in envirment variable and delete those dll files from apache/bin. – Wasim A. Mar 17 '18 at 19:07
  • 3
    To me, I need to delete libeay32.dll, libssh2.dll, ssleay32.dll and nghttp2.dll which I copied to apache\bin and system32. I even forgot when I copied nghttp2.dll to apache\bin, and it took me more than a week to figure it out. – Edmund Tam Apr 15 '18 at 09:46
  • @EdmundTam : Thanks for the feedback! I have updated the answer to make sure, other users do not fall into this nasty trap. – Jpsy Apr 16 '18 at 08:20
  • It worked when I copy libssh2.dll from PHP folder to Apache bin folder, ssleay32.dll and libeay32.dll was already there. – endo64 Mar 11 '19 at 11:42
  • @endo64 did you read my answer at all? What you did is a solution that may come back to bite you. – Jpsy Mar 11 '19 at 17:33
  • @Jpsy Thank you for the warning, but it didn't work even my PHP is added to `PATH`, so copying `libssh2.dll` to Apache's bin folder was the only solution for me. As I manually installed Apache & PHP from their zip archive and no use installers, I'll delete whole content of the folder and extract the newer versions from scratch, updating them will not be an issue (I hope :) ) – endo64 Mar 12 '19 at 20:05
  • 1
    Can confirm this answer worked 100% for me with new WAMP 3.1.9 install. PHP - 7.2.18, Apache 2.4.39 – Simon Ilett Jun 18 '19 at 08:06
  • Can confirm this answer worked 100% with PHP 7.4. Remember step 4! Turn off Apache *COMPLETELY* and start over – kanlukasz Aug 05 '20 at 10:28
  • One important note @Jpsy: setting path to "C:\Program Files\PHP" does not work. You have to use short syntax without spaces: "C:\Progra~1\PHP". I lost 3 hours trying to resolve this... – oneee Aug 14 '20 at 09:27
  • @oneee this is interesting. I guess it is more related to the blank in the path than to the long filename format itself. I have added your suggestion to the answer. Many thanks for this important detail! – Jpsy Aug 17 '20 at 11:48
17

In PHP 5.6.x version You should do the following:

Move to Windows\system32 folder DLLs from php folder:

libssh2.dll, ssleay32.dll, libeay32.dll and php_curl.dll from php ext folder

Move to Apache24\bin folder from php folder:

libssh2.dll

Also, don't forget to uncomment extension=php_curl.dll in php.ini

warunapww
  • 966
  • 4
  • 18
  • 38
Matt
  • 191
  • 1
  • 6
  • 17
    Just copying the `libssh2.dll` file to `Apache24\bin` worked.. thanks! so weird o.O – Samuel Katz Jul 21 '15 at 15:10
  • 7
    This helped me a lot with PHP 7 (x64) + Apache 2.4.18 (x64) on Win7 x64. However I just used `LoadFile "[path to php]\libpq.dll"` and `LoadFile "[path to php]\libssh2.dll"` for loading `cURL` and `PgSQL` extensions. *No filemoves needed*. Just load them with `LoadFile` directive in `httpd.conf`. – BlitZ Dec 14 '15 at 12:38
  • don't need to copy `libssh2.dll` to apache – Robert Jun 09 '16 at 19:08
  • @Num6 I am trying from many days, but its not working. Could you please explain you successfully did php7, apache2.4, I am on win10 x64. please upload your dll files somewhere. – Wasim A. Dec 11 '16 at 18:25
  • copying libssh2.dll file to Apache24\bin worked for me too – Kiran Jan 05 '18 at 22:03
  • It worked when I copy `libssh2.dll` from PHP folder to Apache bin folder, `ssleay32.dll` and `libeay32.dll` was already there. – endo64 Mar 11 '19 at 11:31
  • Did not work for me... :( Those files in bin are symlinks on my Windows. No need for copying them, in any case. – Stefan Nov 07 '19 at 09:46
16

WINDOWS Apache 2.4.x + PHP 7.0.x SOLUTION HERE:

Solution: Put libeay32.dll, libssh2.dll, ssleay32.dll files under dir specified in httpd.conf's ServerRoot directive. These dlls can be found compiled under php root folder.

Reasons:

Problem is php_curl.dll requires to access following libraries while loading: libeay32.dll, libssh2.dll, ssleay32.dll and it does not make sense if you put them in ./php/ext dir or if you put PHP extensions in PHP root dir.

Of course you can put them in C:\Windows or in some global folder defined in PATH but if you don't want to do this and you want that your apache+php installation was portable:

The path specified in ServerRoot in httpd.conf is treated as home path for php. The behaviour is similar to situation where you include ./path/to/some.php file in ./index.php and home path for some.php file is still ./ the dir where index.php resides.

In shorts just put those three dlls right in dir you specified in httpd.conf ServerRoot directive and php_curl.dll will not fail to load again.

John
  • 1
  • 13
  • 98
  • 177
BIOHAZARD
  • 1,937
  • 20
  • 23
  • 1
    I had to place the dlls in apache's bin dir (and replace the existing ones) to make it work. – todinov Feb 02 '16 at 20:42
  • 2
    Yup, putting these files from my PHP directory into Apache24/bin and restarting Apache worked for me. Thanks! – Hobbes Oct 20 '16 at 20:13
  • And if you have multiple virtual hosts, do you really copy PHP files into each of your ServerRoots? I consider this hard to maintain, hard to update and thus a really bad hack. Try the Path solution. It is clean and maintainable. – Jpsy Oct 25 '16 at 01:38
  • @Jpsy you are talking about VirtualHost Directory which is different than ServerRoot path. VirtualHosts have same ServerRoot and different Directory. – BIOHAZARD Oct 25 '16 at 10:04
  • Oh yes, my fault. I mixed up ServerRoot and DocumentRoot. Sorry. – Jpsy Oct 26 '16 at 11:28
  • I deleted the dll in apache/bin to make it work. The old dll from the last php version blocked windows from using the new dll in php folder. I had globale path set as described in the [accepted answer](http://stackoverflow.com/a/26368386/956397) – PiTheNumber Nov 30 '16 at 09:32
  • http://stackoverflow.com/questions/41107356/apache-2-4-23-php7-x-windows-10-x64-php-curl-not-working – Wasim A. Dec 12 '16 at 19:06
  • 1
    Unfortunately this isn't a great solution if you use WAMP with *multiple* versions of PHP installed, as I expect that they may all have their own versions of those DLLs. WAMP seems to handle some aspects of this with symlinks, but I'm not sure exactly how it configures them. – Simon East Jul 04 '17 at 05:08
  • I found a better solution on github by adding `LoadFile "C:/php/libssh2.dll"` and `LoadFile "C:/php/libsqlite3.dll"` to the httpd.config file of apache. Where C:/php is replaced by your php directory ofcourse. https://gist.github.com/alecos71/de26b0079b963a690e798375b8561dfa – Mark Baijens Feb 02 '20 at 15:09
6

You are loading .dll so your OS has to be windows.

First check which php.ini file you are using by running phpinfo()

Then check where your extensions folder is by checking extension_dir attribute in that file.

Next make sure that php_curl.dll is present in that folder. If not copy it over.

Restart apache and check if it works.

Since you installed packages individually, also do this:

Copy the dll file from php_installation_folder/extensions to apache_installation_folder/bin

raidenace
  • 12,789
  • 1
  • 32
  • 35
  • Ok, which PHP are you running? Is it 64 bit? If you are running 64 bit PHP, and having a 32 bit curl dll you can get this error. Actually this is already covered in SO. http://stackoverflow.com/questions/10939248/php-curl-not-working-wamp-on-windows-7-64-bit – raidenace May 07 '13 at 16:53
  • I'm running 32 bit PHP and I'm pretty sure the curl dll is x86 also (it came with the installation). I've already reviewed the post you've linked, and since all the fixed dlls are for x64 PHP I haven't been able to use it. I didn't see when I first installed PHP (http://windows.php.net/download/#php-5.4) a x64 version so that's why I installed 32 bit :P Do you think I should find and install x64 PHP instead? Thanks again for your help, I really appreciate it. – user2066880 May 07 '13 at 17:06
  • I do not think you need to do that. Did you copy dependencies to apache/bin as well? – raidenace May 07 '13 at 17:08
  • Oh! I didn't and now it works!! Thank you so much!! Do you mind explaining why the dlls need to be placed in apache/bin? I thought only PHP needed to see them? Thanks again though, I've been struggling with this problem for so long. – user2066880 May 07 '13 at 17:16
  • 2
    @user2066880 Thats great! What happens when you have separate installations for Apache and PHP is that I believe PHP gets installed as a CGI module (this is not same as CLI) and not a proper apache extension. What this means is that php will request apache for (some) extensions loading and apache naturally checks in its bin folder and tells PHP whether it got it or not. Which is why PHP gives the misdirected error message. I used to know how to fix this, but its been years since I have used separated configurations. Glad it worked though! :-) – raidenace May 07 '13 at 17:38
  • This worked for my (last part of copying the dll to bin folder. I was upgrading php5.6 to php7 somehow the old dll inside my apache/bin folder was not compatible – Sjaak Wish Mar 28 '17 at 12:33
4

Usually this is an OpenSSL version mismatch error, between Apache and PHP. In case Apache loads PHP as a DSO module, its own OpenSSL versions (dlls and libs) will be used. So, in case the PHP extension requires a newer version, it may not find the appropriate interface inside the Apache-loaded DLLS and it will fail to work.

Since you need the PHP extension to load, you need the relevant DLL files to be at least the version of what the PHP module asks for. Supposing that you 're using lastest builds for both Apache and PHP and both having been built with the same MVC version, you can copy the following files:

  • libcrypto-1_1.dll
  • libcrypto-1_1-x64.dll
  • libcurl.dll
  • libsasl.dll
  • libssh2.dll
  • libssl-1_1.dll
  • libssl-1_1-x64.dll
  • nghttp2.dll
  • libeay32.dll (if existing in your PHP distribution)
  • ssleay32.dll (if existing in your PHP distribution)

from the PHP root folder to the Apache2/bin folder, in case you 're confident that the PHP build is newer than the Apache build.

In the opposite case, you can copy the same files from the Apache BIN to the PHP root.

In any case, backup the contents of the APache and PHP folders beforehand.

Adding the PHP path as an enviromental variable will give priority to this path for loading the relevant DLLs and may solve the problem. However, you lose in server portability. Additionally, if you have also added the Apache PATH as a variable and the OpenSSL versions are way different (up to loading different linked DLL files), a lot of shit may happen.

  • 1
    I had to copy over `libssl-1_1.dll` and `libcrypto-1_1.dll` from my `php7.2.8/ext` folder to `apache2.4.23/bin` folder to get this to work. Before that, I was receiving "Unable to load dynamic library" on `php_curl.dll` and `php_openssl.dll` desipite those files existing in the correct place. – Rusty Fausak Jul 28 '18 at 05:34
2

Make sure to have your apache SSH dlls loading correctly. On a fresh install I had to download and load into my apache bin directory the following dll "libssh2.dll"

After ssl dll was loaded cURL was able to load with no issues.

You can download it from the link below:

http://windows.php.net/downloads/pecl/releases/ssh2/0.12/

Alan D
  • 31
  • 1
2

Solution:

Step1: Uncomment the php_curl.dll from php.ini

Step2: Copy the following three files from php installed directory.i.e "C:\\php7".

libeay32.dll,
libssh2.dll,
ssleay32.dll

Step3: Paste the files under two place

httpd.conf's ServerRoot directive. i.e "C\Apache24"
apache bin directory. i.e "C\Apache24\bin"

Step4: Restart apache.

That's all. I solve the problem by this way.Hope it might work for you.

The solution is given here. https://abcofcomputing.blogspot.com/2017/06/php7-unable-to-load-phpcurldll.html

shafiq2410
  • 59
  • 3
2

After having tried everything here I had to simply upgrade Apache to a newer version in order to make curl extension work.

I was upgrading PHP from 7.0.2 to 7.1.15 after which curl did not work. Only way to fix it was upgrade Apache (which was version 2.4.18) to the latest 2.4.29.

Didn't have to copy any of the lib/ssleay dll files to either Apache or Windows - possibly because I already have the PHP folder in my system path.

Running Windows 10, 64-bit, thread-safe versions, VC14.

TheStoryCoder
  • 3,403
  • 6
  • 34
  • 64
2

Insert to file httpd.conf

LoadFile "D:/DevKit/PHP7.1/libeay32.dll"
LoadFile "D:/DevKit/PHP7.1/libssh2.dll"
LoadFile "D:/DevKit/PHP7.1/ssleay32.dll"
Leon Lam
  • 21
  • 1
  • Before I updated my PHP version to 7.4.0 RC4, the method provided by @Jpsy above solved the problem. After the update, your method solved the problem. Thanks. – Ian Y. Nov 17 '19 at 11:47
2

In php.ini you must put the extension_dir static path. extension_dir = "C:\laragon\bin\php\php-7.3.11-Win32-VC15-x64\ext" by example. Don't forget to remove the semicolon before this variable.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Wendinmi
  • 61
  • 3
0

I have encountered the same problem before.I resolved it by add php directory to windows system environment variables---Path.

W.Monkey
  • 1
  • 1
0

I got this error because, on my system at least, if extension_dir in php.ini is set to a relative path, it is taken as being relative to the root Apache directory, so to get it to point to the correct directory I had to use an absolute path: "C:\Program Files (x86)\PHP\ext". (This was PHP 5.5.31 and Apache 2.4.23 on Windows 10; setting extension_dir to ext worked just fine with the same setup on Windows 7. I first got it to work by putting an ext directory in the Apache folder with the necessary dlls, then figured out what was happening.)

It was also necessary to set the PATH correctly or make sure the dlls mentioned above (libeay32.dll, libssh2.dll, and ssleay32.dll) are in Apache's bin directory (or most likely any of the places other answers mention). The fact that I got the same error message for Apache not being able to find lib_curl.dll as for it not being able to find libssh2.dll did not make things any easier to figure out.

0

Add your php folder path to the System PATH and everything should work fine. It will also fix some other extensions that are broken.

0

Maybe not the best approach, but it definitely works. (2019-2022)

"Your install of PHP does not have the 'php_curl.dll' extension enabled."

  1. find "php.ini", if no you have to rename "php.ini-development" to "phh.ini". Open it.

  2. find ;extension_dir = "ext"

  3. add these under that line, there is no ";"

extension_dir = "[php dir]\ext"
extension=php_curl.dll
Yeatom Liu
  • 11
  • 3
0

The most proper and cleanest way seems to be using FileLoad directive.

I do have multiple Apache-PHP sets on a PC. Setting a PATH to one PHP dir, creates problems in the other PHP version.

Of course I don't want to copy dll files nowhere.

I just needed one file: libssh2.dll
I did add it into a IfModule directive's enclosure:

# PHP7 module
LoadModule php7_module "../../../PHP/App/v7.3.1/php7apache2_4.dll"
<IfModule php7_module>
    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>
    PHPIniDir "../../../PHP/App/v7.3.1"
    LoadFile "../../../PHP/App/v7.3.1/libssh2.dll"
</IfModule>

I can have a separate conf file with PHP directives for specific PHP versions and choose which to include at httpd start time.

LoadFile is also suggested in @BlitZ comment under one of the answers.
And later in @Leon Lam answer.

papo
  • 1,606
  • 19
  • 18