1

I am trying to install php-curl in my terminal but this command show

    linux@Lenovo:~$ sudo apt-get install php-curl
Reading package lists... Done Building dependency tree       

Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:

    The following packages have unmet dependencies:  
php-curl : Depends: php7.4-curl but it is not going to be installed 
E: Unable to correct problems, you have held broken packages.

Ananda
  • 13

3 Answers3

3

You can add it via the ondrej/php PPA:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.4-curl
1

There are a number of issues posted here on AskUbuntu about older features of PHP such as CURL, and the procedure oriented functions for SQL database access, which do not work on Ubuntu 20.04 and PHP 7.4 out of the box.

It would appear that evangelists for more modern features have chosen to deprecate older feature implementations, even though there is nothing in the PHP documentation to hint that these features are deprecated. These older interfaces are used by many existing applications and therefore should either be in the supported repositories, or a clear pointer must be provided to alternatives that are supported which require rewriting the code to modern standards. In particular there is nothing in the PHP documentation for curl_init to suggest that it is not a standard feature of PHP, and the recommended way to exchange information over the Internet. There is not even a reference to stream_context_create which can be used with fopen, readfile, or SplFileObject. For example instead of curl_... you can use the following, adapted from contributions to the documentation page for stream_context_create:

$opts = array(
        'http' => array (
            'method'=>"POST",
            'header'=>
              "Accept-language: en\r\n".
              "Content-type: application/x-www-form-urlencoded\r\n",
            'content'=>http_build_query(array('foo'=>'bar'))
  )
);

$context = stream_context_create($opts);

$fp = fopen('https://www.example.com', 'r', false, $context);

In my opinion, and clearly the opinion of the people who contributed to the packaging of Ubuntu 20.04, it is much clearer to use the newer interfaces. I just added a user contributed note to the PHP documentation of curl_init to that effect.

1
sudo apt update
sudo apt install php7.4-curl
sudo service apache2 restart
Kevin Bowen
  • 19,615
  • 55
  • 79
  • 83