简体   繁体   中英

How can I enable cURL for an installed Ubuntu LAMP stack?

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?

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

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.

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 .

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 .

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.xx => run command: sudo apt-get install php5-curl

If PHP 7.xx => 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 .

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 :)

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 .

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

尝试这个:

sudo apt-get install -y curl

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!

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