简体   繁体   English

如何为已安装的 Ubuntu LAMP 堆栈启用 cURL?

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

I have installed the Ubuntu LAMP stack.我已经安装了 Ubuntu LAMP 堆栈。 But cURL is not enabled, and neither can I can find the extension listed in the INI file.但是 cURL 没有启用,我也找不到 INI 文件中列出的扩展名。 I added it manually, but it didn't work either.我手动添加了它,但它也不起作用。

How should I enable cURL then?那我应该如何启用 cURL 呢?

From Install Curl Extension for PHP in Ubuntu :在 Ubuntu 中为 PHP 安装 Curl 扩展

sudo apt-get install php5-curl

After installing libcurl, you should restart the web server with one of the following commands,安装 libcurl 后,您应该使用以下命令之一重新启动 Web 服务器,

sudo /etc/init.d/apache2 restart

or或者

sudo service apache2 restart

You only have to install the php5-curl library.您只需要安装 php5-curl 库。 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 .它在全新的Ubuntu 16.04 (Xenial Xerus) LTS 上运行,带有lamp-serverphp7 I tried with php7-curl - it didn't work and also didn't work with php5-curl .我试过php7-curl - 它没有用,也没有用php5-curl

For those who are trying to install php-curl on PHP 7, it will result in an error.对于那些试图在 PHP 7 上安装 php-curl 的人,它会导致错误。 Actually if you are installing php-curl in PHP 7, the package name should be;实际上,如果你在 PHP 7 中安装 php-curl,包名应该是;

sudo apt-get install php-curl

Not php5-curl or php7-curl , just php-curl .不是php5-curlphp7-curl ,只是php-curl

First thing to do: Check for the PHP version your machine is running.要做的第一件事:检查您的机器正在运行的 PHP 版本。

Command Line: php -version命令行: 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 PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS ) 版权所有 (c) 1997-2016 The PHP Group

If you are using PHP 5.xx => run command: sudo apt-get install php5-curl如果您使用的是 PHP 5.xx => 运行命令: sudo apt-get install php5-curl

If PHP 7.xx => run command (in my case): sudo apt-get install php7.0-curl如果 PHP 7.xx => 运行命令(在我的情况下): 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并在文件“php.ini”中搜索关键字“curl”以找到下面的这一行并将其从

;extension=php_curl.dll ;扩展= p​​hp_curl.dll

To:到:

extension=php_curl.dll扩展名=php_curl.dll

Next, save your file "php.ini".接下来,保存您的文件“php.ini”。

Finally, in your command line, restart your server by running: sudo service apache2 restart .最后,在命令行中,通过运行以下sudo service apache2 restart重新启动服务器: 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.我尝试了大部分以前的答案,但它对我的机器Ubuntu 18.04 (Bionic Beaver)不起作用,但对我有用的是这个。

First: check your PHP version第一:检查你的PHP版本

$ php -version

Second: add your PHP version to the command.第二:将您的 PHP 版本添加到命令中。 Mine was:我的是:

  $ sudo apt-get install php7.2-curl

Lastly, restart the Apache server:最后,重新启动 Apache 服务器:

sudo service apache2 restart

Although most persons claimed that it not necessary to restart Apache :)虽然大多数人声称没有必要重新启动 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 .如需参考,请参阅如何在 Ubuntu 上安装 Linux、Apache、MySQL、PHP (LAMP) 堆栈

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那么对于使用 PHP 8.x 以上和 Centos OS 7 的人来说,您可以通过运行此命令安装 php 扩展yum search php81- or php80然后搜索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.之后运行: yum install ea-php81-php-curl.x86_64来安装扩展。 This will also restarted the apache server along side the installation.这还将在安装的同时重新启动 apache 服务器。

Hope this help solve your problem!希望这有助于解决您的问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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