225

I have installed the Ubuntu LAMP stack. But cURL is not enabled, and neither can I can find the extension listed in the INI file. I added it manually, but it didn't work either.

How should I enable cURL then?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Arshdeep
  • 4,281
  • 7
  • 31
  • 46

10 Answers10

430

From Install Curl Extension for PHP in Ubuntu:

sudo apt-get install php5-curl

After installing libcurl, you should restart the web server with one of the following commands,

sudo /etc/init.d/apache2 restart

or

sudo service apache2 restart
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rabidmachine9
  • 7,775
  • 11
  • 46
  • 59
  • 83
    @Arsheep "didn't worked" is exceedingly unhelpful. Did it give you an error? Did your computer explode? Did your house burst into flames? – Michael Mrozek May 30 '10 at 18:41
  • 2
    No errors and no flames man , it installed successfully i restarted Apache and retried the curl code But the same error again " Call to undefined function curl_init() " – Arshdeep May 30 '10 at 18:46
  • @leonbloy - okay i saw phpinfo() too only one "curl" word i can found in "Additional .ini files parsed - curl.ini". Does that mean something ? – Arshdeep May 30 '10 at 18:56
  • same was happen with me , i have installed php-curl again – nicky Jul 21 '12 at 13:47
  • 6
    sudo apt-get update -y && sudo apt-get install -y php5-curl – jay Jul 26 '13 at 23:54
  • 7
    You only need to install php5-curl... The rest aren't required to enable curl in PHP. I also didn't have to restart Apache for the change to take effect. – Xethron Sep 21 '13 at 09:51
  • 1
    @Xethron restart is done automatically by the installation routine of apt/aptitude – jerik Feb 11 '14 at 16:07
  • 2
    This answer is old, for example ubunto 14.10 now changes the libcurl3 dependencies to libcur4. Here's what I used successfully (it also pulled in a few more dependencies as this was a first-time install for me): `sudo apt-get install curl libcurl4-openssl-dev php5-curl php5-cli` – moodboom Mar 21 '15 at 19:52
  • After `sudo apt-get install php5-curl`, I had to create a symbolic link in `/etc/php5/apache2/conf.d` : `ln -s ../../mods-available/curl.ini 20-curl.ini` – Guillaume Renoult Mar 25 '15 at 23:10
  • 2
    On Ubuntu 16.04 the command is now `sudo apt-get install php-curl` – mchev Nov 03 '16 at 20:23
  • 1
    On PHP 7, use `sudo apt-get install php-curl` instead of `sudo apt-get install php5-curl`. – user3753202 Jul 28 '17 at 13:14
124

You only have to install the php5-curl library. You can do this by running

sudo apt-get install php5-curl

Click here for more information.

Community
  • 1
  • 1
Van Luu
  • 1,249
  • 1
  • 8
  • 2
  • 17
    @EdC In my opinion this is a better answer than the accepted, because it's enough to install php5-curl, no need for the others. – István Ujj-Mészáros Nov 07 '12 at 15:44
  • 9
    This is the better answer... simpler and there is no need to restart the webserver because apt-get does it for you – mblackwell8 Jan 11 '13 at 05:10
  • 1
    Additionally, you'd need to restart Apache after this command using `sudo service apache2 restart` – FloatingRock Jan 02 '14 at 18:59
  • 1
    @mblackwell8 I just tried, and you MUST restart the web server after using the command in order for it to work. – FloatingRock Jan 02 '14 at 19:00
  • Correct, an apache restart is required... FYI you could also enter: sudo /etc/init.d/apache2 restart (instead of 'sudo service apache2 restart) ... though this alternative method I mention requires that your directory is unchanged as it specifies a static path. I use the one mentioned by Yazin – josh.thomson Jul 01 '14 at 12:51
29

Try:

sudo apt-get install php-curl

It worked on a fresh Ubuntu 16.04 (Xenial Xerus) LTS, with lamp-server and php7. I tried with php7-curl - it didn't work and also didn't work with php5-curl.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    This work perfectly fine with me. I'm using PHP7 but I used the command without the version number and it worked super fine. Thanks. – Lynnell Neri Sep 08 '16 at 03:09
25

For those who are trying to install php-curl on PHP 7, it will result in an error. Actually if you are installing php-curl in PHP 7, the package name should be;

sudo apt-get install php-curl

Not php5-curl or php7-curl, just php-curl.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Burak Tokak
  • 1,810
  • 1
  • 20
  • 27
16

First thing to do: Check for the PHP version your machine is running.

Command Line: php -version

This will show something like this (in my case):

PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group

If you are using PHP 5.x.x => run command: sudo apt-get install php5-curl

If PHP 7.x.x => run command (in my case): sudo apt-get install php7.0-curl

Enable this extension by running:

sudo gedit /etc/php/7.0/cli/php.ini

And in the file "php.ini" search for keyword "curl" to find this line below and change it from

;extension=php_curl.dll

To:

extension=php_curl.dll

Next, save your file "php.ini".

Finally, in your command line, restart your server by running: sudo service apache2 restart.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
codeNeverDie
  • 184
  • 1
  • 7
9

I tried most of the previous answers, but it didn’t work for my machine, Ubuntu 18.04 (Bionic Beaver), but what worked for me was this.

First: check your PHP version

$ php -version

Second: add your PHP version to the command. Mine was:

  $ sudo apt-get install php7.2-curl

Lastly, restart the Apache server:

sudo service apache2 restart

Although most persons claimed that it not necessary to restart Apache :)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Slycreator
  • 1,144
  • 11
  • 18
4

Fire the below command. It gives a list of modules.

 sudo apt-cache search php5-

Then fire the below command with the module name to be installed:

 sudo apt-get install name of the module

For reference, see How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kailas
  • 3,173
  • 5
  • 42
  • 52
2

You don't have to give version numbers. Just run:

sudo apt-get install php-curl

It worked for me. Don't forgot to restart the server:

sudo service apache2 restart
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Danielprabhakaran N
  • 530
  • 1
  • 7
  • 16
0

Try this:

sudo apt-get install -y curl
eluleci
  • 3,489
  • 1
  • 26
  • 24
0

Well for does of you who are using PHP 8.x above and Centos OS 7 you can install the php extension by running this command yum search php81- or php80 then search for ea-php81-php-curl.x86_64 or ea-php80-php-curl.x86_64

After that run: yum install ea-php81-php-curl.x86_64 to install the extension. This will also restarted the apache server along side the installation.

Hope this help solve your problem!