Debian

更新的 cURL 在 PHP 中未生效

  • March 5, 2016

我有一個基於官方 PHP Docker 映像通過 Docker 執行的應用程序。

我已將其擴展為更新cURL並使其與nghttp2and一起使用openssl,這是我在應用程序中支持 HTTP/2 所需要的。

但是,PHP 本身並沒有反映這種變化,我不知道為什麼。

這是我的 Dockerfile:

FROM php:7.0.3-fpm

# Add sources that allow installation of unstable packages (needed for latest OpenSSL/cURL versions).
RUN echo 'deb http://ftp.uk.debian.org/debian testing main contrib \n\
deb-src http://ftp.uk.debian.org/debian testing main contrib \n\
deb http://ftp.debian.org/debian/ jessie-updates main contrib \n\
deb-src http://ftp.debian.org/debian/ jessie-updates main contrib \n\
deb http://security.debian.org/ jessie/updates main contrib \n\
deb-src http://security.debian.org/ jessie/updates main contrib' > /etc/apt/sources.list \
&& apt-get update

# Install OpenSSL, nghttp2 and cURL (required to make HTTP/2 requests).
RUN apt-get install -y openssl nghttp2 curl

# Install other dependencies.
RUN apt-get install -y \
   libfreetype6-dev \
   libjpeg62-turbo-dev \
   libmcrypt-dev \
   libpng12-dev \
&& docker-php-ext-install pdo_mysql mbstring sockets zip bcmath \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd

# Copy custom PHP.ini
COPY php.ini /usr/local/etc/php/

# Run php-fpm.
CMD ["php-fpm"]

curl --version輸出:

curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.9 zlib/1.2.8 libidn/1.29 libssh2/1.4.3 nghttp2/1.7.1 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets

openssl version輸出:

OpenSSL 1.0.2f  28 Jan 2016

但是,php -i輸出:

curl

cURL support => enabled
cURL Information => 7.38.0
Age => 3
Features
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => Yes
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => Yes
SPNEGO => Yes
SSL => Yes
SSPI => No
TLS-SRP => Yes
HTTP2 => No
GSSAPI => Yes
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps,     ldap, ldaps, pop3, pop3s, rtmp, rtsp, scp, sftp, smtp, smtps, telnet, tftp
Host => x86_64-pc-linux-gnu
SSL Version => OpenSSL/1.0.1k
ZLib Version => 1.2.8
libSSH Version => libssh2/1.4.3

請注意,cURL Information顯示錯誤的 curl 版本號,並HTTP2標記為no.

任何有關如何讓 PHP 接受它的建議將不勝感激!

對於將來想知道這一點的任何人,我最終確實找到了一種方法。我基本上創建了自己的 Docker 映像,主要基於官方 PHP映像,在編譯之前下載了較新版本的 cURL。

它在Docker hub上可用(至少對於通過 FPM 執行的 PHP 7)。

引用自:https://serverfault.com/questions/757553