1

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.
Rocco The Taco
  • 3,695
  • 13
  • 46
  • 79

2 Answers2

1

You are using Ubuntu@16.04. 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 php@5.6 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 php@5.6 and php-curl@5.6 installed.

k0pernikus
  • 60,309
  • 67
  • 216
  • 347
  • Thanks for the help on this. So does this replace the existing php7 entirely and potentially break any other code on the server relying on PHP7 or it's extensions? – Rocco The Taco Jun 21 '19 at 16:10
  • @RoccoTheTaco That's actually a good follow-up question that you could ask while linking to this question. I never had the use-case of having to run different versions of php on the same server and I strongly advise against that. – k0pernikus Jun 21 '19 at 16:14
  • @RoccoTheTaco Google search brought this to light: https://www.linuxbabe.com/ubuntu/php-multiple-versions-ubuntu-16-04-17-10 – k0pernikus Jun 21 '19 at 16:14
0

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.
Wolfetto
  • 1,030
  • 7
  • 16