简体   繁体   中英

How to enable php5 curl on Ubuntu 14.04?

I have installed curl on Ubuntu 14.04 running PHP 5.6 with the following commands:

sudo apt-get install php5-curl
sudo service apache2 restart

It returns a successful message, but when I run:

php -m

the curl module is not listed, and phpinfo(); does not recognize it as installed or active. I also tried adding:

extension=curl.so

to my php.ini file, but that had no effect. How do I get PHP to recognize that curl is installed?

I got it working based on the second answer listed here: https://askubuntu.com/questions/9293/how-do-i-install-curl-in-php5

Basically:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install php5.6-curl
sudo service apache2 restart

I'm not really sure what made the difference. The repository reference is the most significant difference from previous attempts, but it seems odd as prior installation attempts didn't appear to have any problem accessing or installing/updating php-curl. And I had made sure everything was updated several times. But whatever it was, the above resolved it.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM