Reputation: 2365
I've just installed php7 to my Ubuntu. At first, there was no problem, my web site was working. But suddenly, it started to return Call to undefined function curl_init() error. Now, my pages contain curl codes do not work.
In phpinfo(), it looks Curl is enabled. There were similar questions but none of them handled it in php7. I thought it should be something different than others.
Edit: When I try
php -i | grep curl
in terminal, it returns
/etc/php/7.0/cli/conf.d/20-curl.ini,
curl
Upvotes: 47
Views: 100631
Reputation: 2597
Assumption
You've installed the version of the module for the PHP version you need to use, and yet the problem is not going away.
What is going on here?
There could be multiple versions of PHP installed on your system and Apache is not using the version you are expecting it to use.
How do you know which version of PHP Apache is using?
To know this, the key idea is to learn the ROOT directory of your Apache's configuration files. In the command line, you can type:
apache2ctl -V //sample output below
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Server version: Apache/2.4.7 (Ubuntu)
Server built: Jul 15 2016 15:34:04
Server's Module Magic Number: 20120211:27
Server loaded: APR 1.5.1-dev, APR-UTIL 1.5.3
Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/etc/apache2"
-D SUEXEC_BIN="/usr/lib/apache2/suexec"
-D DEFAULT_PIDLOG="/var/run/apache2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="mime.types"
-D SERVER_CONFIG_FILE="apache2.conf"
In my case, my Apache's ROOT configuration directory is shown in the
HTTPD_ROOT="/etc/apache2"
Now that I know the location of the configs that Apache is using, I can now accurately determine the version of PHP it is using by examining the "mods-enabled"
directory located inside the "/etc/apache2"
directory.
In my case, when do an ls
while inside the "mods-enabled"
, it showed the ff output:
access_compat.load authz_user.load filter.load php5.load
...
authz_host.load env.load php5.conf
At this point, I now know for certain that Apache is using the 'php5'
version of PHP installed on my system, whatever that may be.
Then I tried to reproduce the error above using this version of PHP (i.e., 'php5'
) by running the command below:
$ php5 -r "curl_init();"
PHP Fatal error: Call to undefined function curl_init() in Command line code on line 1
Voila!
The version of PHP that I expected my Apache was using is "php5.6"
and running the same command above with this version did not produce the said error.
Solution
To solve this problem, you either install the version of the module that corresponds to the PHP version that Apache is using (in my example php5.0-curl) or you may change the version of PHP that is being used in Apache to the version you want.
How do I tell Apache which version of PHP to use?
You can accomplish this using the a2enmod/a2dismod
cli commands of Apache2.
Firstly, I disable the PHP module that is currently active on my server (i.e., "php5"
):
a2dismod php5
Then I enabled the php module for the version of PHP that I want my Apache to use:
a2enmod php5.6
Then I restart Apache
service apache2 restart
After I refreshed the offending page on my website, the error is now gone.
Upvotes: 21
Reputation: 11
Scratched my head over this for a while, curl module was loaded but still got the error.
This happen after I upgraded from Debian Stretch to Buster.
The reason was that php7.3-curl was installed and used, but apache run php7.0 even though 7.3 was installed. So I removed php7.0 and reinstalled libapache2 to get it working
apt-get remove php-7.0
apt-get remove libapache2-mod-php7.3
apt-get install libapache2-mod-php7.3
Upvotes: 0
Reputation: 143
ubuntu 18.04 php 7.4
if you have PHP old version and the new version as well as. you need to disable old curl mode so that. follow the steps.
sudo a2dismod php7.1 (your old version)
sudo a2endmod php7.4 (your new version)
sudo service apache2 restart
sudo systemctl restart apache2
it works for me.
Upvotes: 0
Reputation: 899
I did all of the above but did not solve the problem.
Env: Ubuntu, php7.1, Laravel 5.6
Solution
sudo add-apt-repository ppa:ondrej/php
sudo apt-get install php7.1-curl
Upvotes: 5
Reputation: 1255
I know its very late answer but I think its useful because I faced same issue and tried all above given solution but not worked. Then I hit following command and now working perfectly :
apt-get install php7.0-curl
Upvotes: 2
Reputation: 319
For me, the resolution was to update apt-get with the following command, and then install php7.0-curl.
sudo add-apt-repository ppa:ondrej/php
Upvotes: 3
Reputation: 11
This fixed my issues issue, hope someone benefits too
Upvotes: -1
Reputation: 1836
I've had similar problem with curl after upgrade to XX (16.04). After reinstalling curl with:
sudo apt-get install php-curl
And server restart
sudo service apache2 restart
everything went back to normal :)
Upvotes: 106
Reputation: 2061
Your Filepath is probably incorrect
Check the Apache error log in
/var/log/apache2/error.log
if the called path or filename does match your real path in e.g.
/usr/lib/php/20151012/php_curl.so
In my case it's been the same path, but "the php_" was missing
/usr/lib/php/20151012/curl.so
So I changed the path / filename accordingly in
/etc/php/7.0/cli/conf.d/20-curl.ini
from
extension=php_curl.so
into
extension=curl.so
Upvotes: 2
Reputation: 48357
Your pages probably are not generated with the CLI SAPI. Check what phpinfo() returns when run from your webserver (its probably trying to read the wrong ini file).
Upvotes: 1