CURL with PHP not working with FreeBSD
A CURL error like this means that CURL for PHP is not installed.
[Thu Jan 14 11:03:38 2010] [error] [client 192.168.1.111] PHP Fatal error: Call to undefined function curl_init() in /usr/local/www/html/myscript.php on line 89, referer: http://192.168.1.223/
In order to install curl for PHP on FreeBSD I did the following
As root on FreeBSD
# cd /usr/ports/lang/php5-extensions/
Just in case there is old files from other installs that failed
# make clean
Select Curl extention from the config menu
# make config
What should be selected is
[X] CURL CURL support
After all the right extentions are selected, we compile and install the PHP extentions
# make install clean
When the options for CURL come up "Options for curl 7.19.7" use the default options unless you need something spesifc
But then I got this error saying I already had an old version of CURL installed.
===> Installing for curl-7.19.7
===> curl-7.19.7 depends on file: /usr/local/share/certs/ca-root-nss.crt - found
===> Generating temporary packing list
===> Checking if ftp/curl already installed
===> An older version of ftp/curl is already installed (curl-7.19.5_1)
You may wish to ``make deinstall'' and install this port again
by ``make reinstall'' to upgrade it properly.
If you really wish to overwrite the old port of ftp/curl
without deleting it first, set the variable "FORCE_PKG_REGISTER"
in your environment or the "make install" command line.
*** Error code 1
Stop in /usr/ports/ftp/curl.
*** Error code 1
Stop in /usr/ports/ftp/curl.
*** Error code 1
Stop in /usr/ports/ftp/php5-curl.
*** Error code 1
Stop in /usr/ports/lang/php5-extensions.
*** Error code 1
Stop in /usr/ports/lang/php5-extensions.
So I had to upgrade curl with the following command.
# /usr/local/sbin/portupgrade -R curl
If you were unlucky like me and don't have portupgrade installed then you must install. But you may as well go on lunch as this will take a while.
# cd /usr/ports/ports-mgmt/portupgrade
# make install clean
Then we try and install the port again
# cd /usr/ports/lang/php5-extensions/
# make install clean
In this case, it seems a new version of the extention was installed but that's ok, it should still work fine.
If you want to test to make sure it was installed correctly you can do one of the following.
For packages installed, look for
curl-7.19.7 Non-interactive tool to get files from FTP, GOPHER, HTTP(S)
php5-curl-5.2.11_1 The curl shared extension for php
# pkg_info | grep curl
you can also view extensions.ini and look for extension=curl.so
# vi /usr/local/etc/php/extensions.ini
last step is, restart apache
# cd /usr/local/etc/rc.d/
# ./apache2 restart
Hope that helps someone with Call to undefined function curl_init() errors