Rocco The Taco
Rocco The Taco

Reputation: 3777

Ubuntu PHP 5 Install Curl Cannot Find Package

I'm getting a PHP Fatal error:

Call to undefined function curl_init() error while testing some PHP code on my server.

I assumed Curl needed to be installed so i found the PHP version first:

php --version
PHP 5.6.11-1ubuntu3.4 (cli)

I proceeded to install the package:

sudo apt-get install php5-curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php5-curl

I then tried:

sudo apt install php-curl

and it appeared to install but I saw references to PHP 7 and it completed successfully.

Yet, the problem persists.

How do I get curl running to stop the init() error?

UPDATE: When I run this I get:

sudo apt-get install curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
curl is already the newest version (7.47.0-1ubuntu2.13).
0 upgraded, 0 newly installed, 0 to remove and 172 not upgraded.

Upvotes: 1

Views: 844

Answers (2)

k0pernikus
k0pernikus

Reputation: 66609

You are using [email protected]. 16.04 does not ship with php@5 but with php@7.

If you need your older version of php and its dependencies, you have to install it differently.

There is a trustworthy (note: any external repository may still be a security thread) repository maintained by ondrej, namely:

I have build a Dockerfile using 16.04 to showcase how you could install [email protected] and php5.6-curl:

FROM ubuntu:16.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -qq update && \
    apt-get -qq install software-properties-common > /dev/null && \
    LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php -y > /dev/null && \
    apt-get -qq update && apt-get -qq install php5.6 php5.6-curl > /dev/null
RUN php -v && php -m | grep curl

This Dockerfile is not ideal, yet the last run prints:

PHP 5.6.40-8+ubuntu16.04.1+deb.sury.org+1 (cli) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
curl

showing that it has [email protected] and [email protected] installed.

Upvotes: 1

Wolfetto
Wolfetto

Reputation: 1130

Try:

  1. First Install CURL by typing sudo apt-get install curl.
  2. Then Restart Apache by typing sudo service apache2 restart.
  3. Install PHP5 CURL sudo apt-get install php5-curl.
  4. Restart Apache by typing sudo service apache2.

Upvotes: 0

Related Questions