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’);
Hi
I am Hitesh Patel
I have yahoo addressbook grabber but i face problem to execute script call to undefined function curl_init()
plz send me reply how to execute my script.
inform me all the neccessary file that i have to set.
Worked like a charm! Thanks.
And yes, running SSL with ca-bundle.crt works too.
can you please tell me
how can i encode the link with
urlencode and php
thanks
Really Worked Great…. Thank you very much. I should really appreciate your contribution.
This is not a comment, but a question,
I have two live applications running, which I cannot tell of here. Application A is a shopping site, and Application B is a Merchant Control Site:
Application A is hosted on a windows server. whilst Application B on a linux.
A posts form to B using simple HTML form for credit card approval, B replies back using form post at a specified URL at A, but always get an error on curl Could not Connect, any Ideas, any help very much appreciated am stuck on this for quite lots of days.
I have site C also that is on linux, and is also shopping site, C does the same process but does not get any error in receiving response back from A.
Any help is very much appreciated.
Please email me at s4shani83@hotmail.com
Thanks for the article.
Very helpful.
All this time and it still works – Thanks
xampp userse:
for those pulling as much hair out as me, read this list to ensure you have all php.ini copies covered:
http://www.menyhart.net/blog/developer-stuff/enabling-curl-on-xampp/
why there’s not one I don’t know…
Xampp inst. does not require any additional settings, but those mentioned by Tim above.
Thanks Tim
If you’ve just installed PHP5 on windows XP, the extension dir may be “extension_dir={your_php_dir}/ext”, and not “extensions”.
Thanks Tony!
Hi
I am prasenjit modak I have yahoo addressbook grabber but i face problem to execute script call to undefined function curl_init()
plz send me reply how to execute my script.
inform me all the neccessary file that i have to set.
dear sir, i am not properly integrate curl in my php project .kindly tell me the procedure how to integrate these.when run the link then curl_init() is not found.
You guys are the 80582 best, thanks so much for the help.
I realise this article is quite old – but I came across it so others might too.
First of all as jb correctly pointed out, you don’t need to install curl if you just want to use curl in php. Nor do you need to install openSSL to access secure pages using curl with PHP.
By the way, and this is important, setting CURLOPT_SSL_VERIFYPEER to false (or 0) undermines the security system – SO DON’T DO IT – It is not a solution to your problems.
To use ssl correctly, just download curl for the “curl-ca-bundle.crt” file as suggested by jb and give its location with CURLOPT_CAINFO.
Here’s a tip: don’t copy libeay32.dll and ssleay32.dll to your system32 dir. Instead add the php directory to your system PATH. This is recommended in other places in the php manual, but was left out on the curl page. To quote http://www.php.net/manual/en/install.windows.manual.php
“And as you’ll soon learn, the preferred method for installing PHP is to keep all PHP related files in one directory and have this directory available to your systems PATH.”
Keep up the great work on your blog. Best wishes WaltDe
Hello there.
If you want to install cURL on Windows, make sure that you’ve copied “php.ini” from the PHP folder (mine is currently “php-4.3.5-Win32″) to your SYSTEM or SYSTEM32 folder (I’m still on Win ME, so it’s SYSTEM). Open the copied version to the SYSTEM folder and look out for these lines:
; Directory in which the loadable extensions (modules) reside.
extension_dir = “C:\php-4.3.5-Win32\extensions”
As you could see, just replace the VALUE of extension_dir to the full path (Windows-based PATH using BACK-slashes) of the folder “extensions” on your PHP folder.
Then copy all of these libraries (DLL’s) from the PHP folder into the SYSTEM folder:
php4ts.dll,
ssleay32.dll,
php_curl.dll, (inside “extensions”)
msvcrt.dll
I thought the last one should already be in the SYSTEM folder there
cURL can then be enabled by uncommenting the line ‘extension=php_curl.dll‘ in the php.ini file. Alternatively you can load the module dynamically in your script using:
<?php
dl(“php_curl.dll”);
?>
Create a simple PHP file that looks something like this:
<?php
echo phpInfo();
?>
… and save it as “phpInfo.php” or anything up to you. Then run it via your Web browser. If the cURL installation was done successfully and is now enabled, you’ll see the “curl” section from the page — mine is after “ctype and before “ftp“.
[Good Reference:
Woopss!
Sorry… I was in a bit hurry when I posted my first comment I’m pretty sure you can figure things I’ve ‘coded’ mistakenly like the <A>! Also the <br>s Heheheh…
So i don’t know how to install curl and configure this.please help me as soon as possible.
please give me the easy steps to go one by one.
Thanks very much.
Why turn register_globals on? This is a security risk and is not recommended. I got curl working fine with this setting off.
Sorry, I just don’t get it. I need to post information from a secure site to a secure site which will write the information into a database and return a reply. How do I get curl to do this. The example above worked but how do I post.
This worked but how do I post to something like this?
$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;
Thanks, I am getting closer.
I fixed my
Fatal error: Call to undefined function: curl_init()
issue on WinXP.
I followed the instructions above but refused to
believe that you need to put the php.ini file in
the windows/system32 directory. After all, if you
put php before the windows & system32 entries in your path windows should load these first. Right?
I don’t know and right now don’t care. I
put the php.ini file (after all modifications as
outline et al above) into the windows/system32 directory. I then got curl showing up in a phpinfo.php.
whew!
I check everything about your chack-list and still have
PHP Startup : unable to load dynamic library ‘C:\php\ext\php_curl.dll’
i am with PHP 5.0.2 under Windows XP SP2
if you or anybody have an idea.
Amazing!!! 10+
No pain! Easy install!
Thank you!!!
+++++++++++++++++++++++
yes it does not work for me either, there is no php_cull.dll in tany directiory of that distribution as far as I can see
Just copied the php_curl file to php directory and uncommented extension=php_curl.dll and set globals on it worked on windows2000.
Thanks
Sundaresan
Thanks everyone, esp. Eric\Pokerface…
My “Fatal error: Call to undefined function: curl_init()” error was resolved after I realized I was changing the wrong php.ini file. Who knows why there’s a separate on in my apache\bin directory. Maybe I put it there a long time ago or maybe XAMPP makes a copy there.
C:\Program Files\xampp\apache\bin\php.ini
Searching my xampp directory tree showed more than one php.ini file.
C:\Program Files\xampp>grep -idl php php.ini*
File apache\bin\php.ini
File php\php.ini
File php\php.ini-dist
File php\php.ini-recommended
File php\php4\php.ini
File php\php4\php.ini-dist
File php\php4\php.ini-recommended
I’m running PHP Version 5.0.4
Thanks everyone!
Thank you sally
Now my curl is working like a knife on a butter.
Thanx again bye.
hi,
that was really a great piece of work. excellent explanation. curl is now working fine.
thanks much
I want to upload a file using cURL.
I have installed zlib and libgcc packages.
But i m not getting an parse error.
So any one having code for it with explanation
Please reply
this worked for me — it is from the php manual (http://www.php.net/curl)
Note to Win32 Users: In order to enable this module on a Windows environment, libeay32.dll and ssleay32.dll must be present in your PATH.
You don’t need libcurl.dll from the cURL site.
How did you manage to set it up on Linux without compiling php? Please provide the steps.
Great Page.
But I was sitting behind a firewall and I had not set up the proxy. Thus whenever I executed the php script, I got a blank page!! Solution:
curl_setopt ($ch,CURLOPT_PROXY, “proxy_server:port”);
Also very good debug option: A must for beginners
print_r(curl_getinfo($ch));
echo “\n\ncURL error number:” .curl_errno($ch);
echo “\n\ncURL error:” . curl_error($ch);
Thanks works perfect!
hi,
currently i’m trying curl with tomcat5.5 and php5, i followed your steps, but I dont know how to do the step 9.
please guide me.
thanks in advance.
vanchin
For those that don’t work try this to see if you have the curl enable:
I had the php.ini file in the windows directory and was editing the php.ini on the php directory, and with that i found the problem.
i am using php5 with apache server on windowsXP my curl library is also enable but i am getting this error:
7 Failed to connect to xx.xxx.xxx.xx (ip): Permission denied
plz help me
Not sure if this will help anyone because it appears that everyone who has installed PHP, IIS, and cURL didn’t encounter any issues.
My issue was that everything worked, PHP, IIS, cURL, but not cURL under SSL even after adding “curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);” to my test script. The answer, found on the PHP.net site (“http://fr.php.net/curl”), use …
“curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);”
It works…
Easily worked for me…thanks !
hy … i installeted on that tutorial a xampp pack …and ” all`s greate ” but curl don`t running … isn`t in phpinfo is not a curl enable .. maby xamp pack don`t compil a php with curl ?
pls help me
Hello,
I have got PHP With IIS in win-XP.I am getting one error in the below program as follows.
“Fatal error: Call to undefined function: curl_init()”
So i don’t know how to install curl and configure this.please help me as soon as possible.
please give me the easy steps to go one by one.
Thanks very much.
Thanks a lot, your instructions really helped me out of this one
A little note to all XAMPP users,
php.ini is not loaded from the file found in the php installation directory, but from apache/bin/php.ini
For those interested in just getting cURL capability going (perhaps because you already have PHP & Apache running but now need the curl stuff), just follow items 4&8 from the tutorial. the php_curl.dll won’t load (step until you perform step #4 when you restart the Apache server.
oh mate , that was awsome ,… how come u’r the only resource for this?
Can anyone help me get this working. I can’t get the curl module to load. I uncommented the line in the php.ini file and have the dlls in the system32 dir but, in phpinfo() the module does not show up.
Having same problem as g! above. Both copies of php.ini have been adjusted (one under c:\Program Files\PHP and one under c:\WINDOWS\system32), the Apache .conf file has been modified, the extension path has been set, etc., etc. but curl still refuses to load. Been working on this for 3+ days (pushing 30 hours). Oh yeah: Windows XP SPII, Apache 2.2, PHP 5.2.5, curl 7.18.1. Any obscure idea would help in this battle.
For some reason, Apache was not picking up the path for my php.ini file, but was looking in the C:WINDOWS/ folder for it. Another issue was that php was looking in c:php5/ext by default for my extensions. I placed the .ini folder in the C:WINDOWS/ folder and placed the ext folder in the default location and cURL loaded perfectly. This is only a short term solution, but at least it got me up and running. Hope this helps.
Thanks! I just did step #4 and uncommented the extensions for php_curl.dll and php_openssl.dll in the php.ini file; worked like a charm.
Like many of you, I had trouble installing CURL on a Windows Box running Apache and PHP. My exact setup is Windows XP with Apache 2.2.6, and PHP 5.2.6. (The latest releases of both.)
It seems to me that the new version of PHP does things a bit differently with respect to importing modules, and the instructions given here can’t really be applied to the current version of PHP without some modification. Obviously, I have no idea what these mods are, and you probably don’t either.
But, THERE IS A SOLUTION. When you install PHP via the .exe file, the default options are to install the program of PHP itself along with a few really common extensions. BUT, you can also install less commonly used extensions (like CURL) by simply checking them off under the little extensions box. I just did this and voila! – everything works.
No sense in killing yourself over this when the installer does it for you.
Good luck.
-Joe
I have problem with the 9th step
- Uncomment: LoadModule php4_module (no line contains this string, so what have I to do. By the way I have added the following line(Tell me is it correct or not?)
LoadModule php4_module modules/mod_dir.so
d:/apps/php/sapi/php4apache2.dll(What is this?)