cURL with PHP and Apache on Windows
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’);
You rock
Thanks so much.
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.
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.
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.
It helps a lot. Thank you so much!
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?
Well, just about 10 mins later, when I restarted apache, curl works
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!
@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);
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.
I Have sime problem on installing xampp.
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!
@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.
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.
I’m using XAMPP1.6.8,How Can I run a program using cURL?
I need an Example.
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
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.
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!
Thank you, thank you, thank you! You are the saver!
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.
Thanks alot for putting this together , it works great, using XAMPP saves you some of the steps above.. but its still worth being reviewed.
Thank alot, Im using AppServ 2.5.9
@Oscar: Perfect! This is just the solution I needed! Thanks!