Fix the "call to undefined function curl_init" error in PHP on Debian
Posted April 17th, 2009 in Linux/Unix/BSD and PHP
If you call the curl_init function in PHP and do not have the curl module installed you will get the error message "Fatal error: Call to undefined function curl_init() in /path/to/script.php on line XY". This post shows how to install the PHP curl module on Debian Linux and the instructions should also work on all Debian derived distros such as the Ubuntu family.
The instructions show here are from the command line and do not use a GUI tool.
Open up a command prompt and run the following either as the root user or using the sudo utility:
aptitude install php5-curl
You'll see something like this:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
The following NEW packages will be installed:
libcurl3{a} libssh2-1{a} php5-curl
0 packages upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 315kB of archives. After unpacking 770kB will be used.
Do you want to continue? [Y/n/?]
Type in "Y" and then <enter> and the package will install:
Writing extended state information... Done Get:1 http://ftp.nz.debian.org lenny/main libssh2-1 0.18-1 [64.3kB] Get:2 http://ftp.nz.debian.org lenny/main libcurl3 7.18.2-8 [227kB] Get:3 http://ftp.nz.debian.org lenny/main php5-curl 5.2.6.dfsg.1-1+lenny2 [23.7kB] Fetched 315kB in 1s (287kB/s) Selecting previously deselected package libssh2-1. (Reading database ... 48679 files and directories currently installed.) Unpacking libssh2-1 (from .../libssh2-1_0.18-1_i386.deb) ... Selecting previously deselected package libcurl3. Unpacking libcurl3 (from .../libcurl3_7.18.2-8_i386.deb) ... Selecting previously deselected package php5-curl. Unpacking php5-curl (from .../php5-curl_5.2.6.dfsg.1-1+lenny2_i386.deb) ... Setting up libssh2-1 (0.18-1) ... Setting up libcurl3 (7.18.2-8) ... Setting up php5-curl (5.2.6.dfsg.1-1+lenny2) ... Reading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done Writing extended state information... Done Reading task descriptions... Done
Now restart Apache doing a graceful reload or a full restart again either as the root user or using sudo. You may need to wait a few seconds using graceful for the extension to be loaded in all threads but it become available without a full restart.
apache2ctl graceful OR apache2ctl restart
That's all there is to it. The curl functions should now be available in PHP.
Related posts:
- Sending a username and password with PHP CURL (Monday, June 22nd 2009)
- Fix the "call to undefined function ImageCreateFromPNG" error in PHP on Debian (Friday, April 10th 2009)
- Install PHP IMAP on Debian (Monday, March 16th 2009)
- Changing the timezone with PHP (Wednesday, December 31st 2008)
- PHP fatal libpng error: zlib error (Tuesday, November 4th 2008)
- Fix the mbstring PHP extension not found error in phpMyAdmin (Thursday, September 18th 2008)
Share or Bookmark
Share or Bookmark this page using the following services. You will need to have an account with the selected service in order to post links or bookmark this page.
Subscribe or Follow
Subscribe via RSS or email, or follow me on Facebook or Twitter below. The RSS icon takes you through to Feedburner where you can select the service or application to use.

