Installing curl to PHP cli
I had the same issue. But, finally I solved it by running the following command.
sudo apt-get install php7.0-curl
Restart the server after installing. This answer may not be useful for the user who asked because he asked it two months ago. But, this may be useful for the users who reading this in the future.
Here's how I've fixed this on ubuntu 14.04 when curl was working in php files run through apache, but not when called from the cli.
ssh to your server and cd to /
find / -name 'curl.so'
Run the above find command to locate where the curl binary is hanging out at. If you can't find the file, you might need to install curl and run the find command again.
apt-get install php5-curl
You'll now want to edit the php.ini being used for php files run from the cli (it's different than the one used by apache), and is likely at /etc/php5/cli/php.ini
nano /etc/php5/cli/php.ini
You can also run
php -i | grep 'php.ini'
To get the file path, just to be sure.
In your php.ini file search for [curl] by pressing ctrl + w
You'll now want to add the extension to the file and it should look something like the following, though your path to the curl.so file and such might be a little different:
[curl]; A default value for the CURLOPT_CAINFO option. This is required to be an; absolute path.;curl.cainfo =extension=/usr/lib/php5/20131226/curl.so
After doing the above, I was able to use curl in php scripts run from the cli.
If you are using the command-line interface ('cli') for php5
, instead of
php -q myfile.php
please use:
php5 -q myfile.php
php5-curl
seems to enable the curl
module for the cli php5
and not php
and both (can) load different configurations and modules.