[英]Ubuntu PHP 5 Install Curl Cannot Find Package
我收到一個 PHP 致命錯誤:
Call to undefined function curl_init() error while testing some PHP code on my server.
我假設需要安裝 Curl 所以我首先找到了 PHP 版本:
php --version
PHP 5.6.11-1ubuntu3.4 (cli)
我繼續安裝軟件包:
sudo apt-get install php5-curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php5-curl
然后我嘗試:
sudo apt install php-curl
它似乎安裝了,但我看到了對 PHP 7 的引用並且它成功完成了。
然而,問題仍然存在。
如何讓 curl 運行以停止 init() 錯誤?
更新:當我運行這個時,我得到:
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.
您正在使用 Ubuntu@16.04。 16.04 不附帶 php@5,而是附帶 php@7。
如果您需要舊版本的 php 及其依賴項,則必須以不同的方式安裝它。
ondrej 維護了一個值得信賴的(注意:任何外部存儲庫都可能仍然是一個安全線程)存儲庫,即:
我已經使用 16.04 構建了一個 Dockerfile 來展示如何安裝 php@5.6 和 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
這個 Dockerfile 並不理想,但最后一次運行打印:
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
顯示它安裝了 php@5.6 和 php-curl@5.6。
嘗試:
sudo apt-get install curl
來安裝 CURL。sudo service apache2 restart
重新啟動 Apache。sudo apt-get install php5-curl
。sudo service apache2
重新啟動 Apache。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.