Home > Code > cURL with PHP and Apache on Windows

cURL with PHP and Apache on Windows

October 22nd, 2003 Tony Leave a comment Go to comments

Setting up cURL my linux server it was no problem at all, but I had a heck of a time getting cURL to work properly on my Windows test box with PHP and Apache. There are a lot of tricks scattered around on the web so here is my list of notes:

1. Only install PHP with the zip’d binaries. Don’t use the installer. I recommend deleting your current PHP installation and reinstalling with the binaries. Downloading the latest PHP has the added benefit of ensuring its compatible with the version of cURL you’ll download later. (I installed to D:\apps\php and will use that path for the rest of this example)

2. Edit your php.ini file:

   - set extensions_dir to d:\apps\php\extensions

   - set register_globals to On

   - set sessions.save_path to d:\apps\php\temp (you need to create that directory first)

3. Copy php4ts.dll (located in d:\apps\php\) to your Apache bin folder

4. Copy libeay32.dll and ssleay32.dll (located in d:\apps\php\dlls\) to c:\windows\system32

5. Download cURL for Windows at: http://curl.haxx.se/download.html. I chose the Win32 – Generic by J?Hartroth. I recommend getting the SSL version in case you ever need SSL. I unzipped cURL to d:\apps\curl and will use that path for the rest of this example

6. [SSL INSTALL ONLY] Download OpenSSL for Windows from http://curl.haxx.se/download.html. (Its near the bottom of the page). Extract libssl32.dll to d:\apps\curl

7. [Windows XP Install Only] Check to see if you have the following file: c:\windows\system32\msvcr70.dll. If not, search for it in Google and download it to system32. You may get error messages without it.

8. Uncomment the curl line in your php.ini file to enable curl: extension=php_curl.dll

9. Finally edit your Apache httpd.conf file to enable php:

   - Uncomment: LoadModule php4_module d:/apps/php/sapi/php4apache2.dll

   - Add Line: AddType application/x-httpd-php .php

Test with the following PHP code:

   $url = “http://www.thinkgeek.com”;

   $ch = curl_init();

   curl_setopt($ch, CURLOPT_URL,$url);

   curl_setopt($ch, CURLOPT_VERBOSE, 1);

   curl_setopt($ch, CURLOPT_POST, 0);

   curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

   $returned = curl_exec($ch);

   curl_close ($ch);

   echo $returned;

SSL NOTE: I kept getting no response when I tried using curl with SSL urls. I found that adding the following solved the problem:

   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

I have read that the proper solution is to use the ca-bundle.crt file for curl to be able to verify certificates but I haven’t tried this yet:

   curl_setopt($ch, CURLOPT_CAINFO, ‘drive:\pathto\ca-bundle.crt’);

Categories: Code Tags:
  1. Bob
    June 20th, 2008 at 01:39 | #1

    You rock
    Thanks so much.

  2. Annette
    July 16th, 2008 at 10:51 | #2

    Curl Installation problem

    I have Apache/2.2.4 (Win32)and PHP/5.2.1 installed on my PC, but I can’t get
    the CURL extension to work. It does not show up when I display phpinfo and
    when I run a program with CURL in it, I get an error message that the program
    does not recognize the CURL function.

    I had uncommented out extension=php_curl.dll in the php.ini file. In terms, of
    the two files associated with CURL, libeay32.dll and ssleay32.dll, they are
    both in my PHP root directory and my PHP/ext directory, as is php_curl.dll. I
    have also put these the libeay32.dll and ssleay32.dll in my Windows/system and
    Windows/system32 directories because someone had suggested it when I was
    researching CURL installation problems. I had checked the PATH function to see
    that all necessary directories are mentioned.

    I have restarted Apache and the CURL function is still missing in phpinfo.

  3. Tony
    August 1st, 2008 at 17:33 | #3

    Thanks for this guide, I managed to get it working in no time at all. Just a couple of quick notes, when using php5 the test script needs to be changed to $url = ‘http://www.thinkgeek.com’; (single quotes) or it throws up an error. Also with my installation, I use the server package from devside.net, the line which needed to be uncommented in step 9 did not exist. However for anyone else who also doesnt see this line it didnt make any difference to the success of the installation.

  4. Blazer79
    August 6th, 2008 at 09:20 | #4

    Another note. I added the PHP directory to the path in a Win XP machine, but it still wouldn’t work until I restarted the computer. Also, Apache 2.2.9 has its own ssleay and libeay files in the bin directory. Not sure if it helped, but I replaced them with the files from the php installation.

  5. Kaythi
    August 13th, 2008 at 01:51 | #5

    It helps a lot. Thank you so much!

  6. Ago
    October 3rd, 2008 at 18:20 | #6

    Hello

    I’m on Windows Vista, have PHP 5.2.6 and apache 2.2. And I can’t find a way to get this work. Have tried everything mentioned here and struggled with it for 3 days now.

    When running apache, I get error:
    “PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\php\ext\php_curl.dll’ – The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail.

    in Unknown on line 0″

    Any idea, what could be wrong?

  7. Ago
    October 3rd, 2008 at 18:40 | #7

    Well, just about 10 mins later, when I restarted apache, curl works :P

    I’m not even sure, what I did. Probably replaced ssleay32.dll in my system32 folder. Also took extensions path off from path and put it back there (restarting apache meanwhile).

    Anyways, I’m happy and thanks! :)

  8. David Spector
    October 8th, 2008 at 10:00 | #8

    @hkboy
    “…images don’t show up.”

    If you are reading a page then trying to display it with echo or print, this will happen because the page is not running on the server you read it from.

    You can fix this using code like this right before your echo or print call:

    $Base=”;
    $Contents=str_ireplace(“”,”$Base”,$Contents);

  9. David Spector
    October 8th, 2008 at 10:20 | #9

    If you already have a recent version of Apache and PHP installed on Windows, installing cURL Library is trivial: uncomment the line “extension=php_curl.dll” in php.ini and then restart Apache. I don’t know why the manual doesn’t say this.

  10. eni
    October 22nd, 2008 at 10:01 | #10

    I Have sime problem on installing xampp.

  11. October 30th, 2008 at 12:56 | #11

    I CALL BULL $#!T

    These Steps May Work But Your just wasting time All that has to be done is uncomment extension=php_curl.dll

    In your Apache/bin/php.ini and restart

    If your editing php/php.ini thats your problem!

  12. tony
    October 30th, 2008 at 13:46 | #12

    @Munkus
    Given that this post is over 5 years old it very well may be bull shit at this point. I have no idea as I’ve been fortunate enough to only work on *nix servers.

  13. December 29th, 2008 at 08:43 | #13

    Hi Tony,
    It’s a nice tutorial but was unable to get the installation procedure work. I think for recent php installations we already have curl setup, but inactive. We just need to enable it by editing the bin/apache/apache2.x.x/bin/php.ini and uncommenting the extension=php_curl.dll.
    That enabled my curl.
    Thanks.

  14. muthu
    December 29th, 2008 at 09:27 | #14

    I’m using XAMPP1.6.8,How Can I run a program using cURL?
    I need an Example.

  15. December 30th, 2008 at 01:33 | #15

    Excellent pointers there.

    Also don’t forget the single most important step is

    “4. Copy libeay32.dll and ssleay32.dll (located in d:\apps\php\dlls\) to c:\windows\system32″ and of course restart your apache server !

    For me the files were present under php5 directory itself

  16. karuppusamy g
    January 2nd, 2009 at 09:57 | #16

    Thank you very much, i realy happy to clear my doubt about the curl. Now your recommended procedure is working well once again i thank you very much.

  17. Alex Grose
    January 3rd, 2009 at 21:11 | #17

    I had to copy all of the files in my PHP extension directory to [C:\php5]

    Not quite sure why, because the extension_dir was set correctly. Works anyway though!

  18. YC
    February 17th, 2009 at 07:04 | #18

    Thank you, thank you, thank you! You are the saver!

  19. February 18th, 2009 at 10:56 | #19

    XAMPP, at least now, becomes with native CURL support (it just needs an easy enabling).
    Open your php.ini file (usually in C:\xampp\apache\bin), locate the next line (or type ‘curl’ in your text editor searcher):

    ;extension=php_curl.dll

    just deleting the ; and restart your Apache server using the Xampp Control Panel. Test your app and then you’ll get CURL active in your system without remove or reinstalling anything. My english is bad but I hope you can understand this simple steps.

  20. March 10th, 2009 at 07:19 | #20

    Thanks alot for putting this together , it works great, using XAMPP saves you some of the steps above.. but its still worth being reviewed.

  21. Viet Hung
    March 30th, 2009 at 03:24 | #21

    Thank alot, Im using AppServ 2.5.9

  22. April 9th, 2009 at 16:17 | #22

    @Oscar: Perfect! This is just the solution I needed! Thanks!

Comment pages
1 2 3 29