沃梦达 / 编程问答 / php问题 / 正文

如何在 Docker 的 PHP7 Alpine 映像上安装 php memcached 扩展?

How can I install the php memcached extension on Docker#39;s PHP7 Alpine image?(如何在 Docker 的 PHP7 Alpine 映像上安装 php memcached 扩展?)

本文介绍了如何在 Docker 的 PHP7 Alpine 映像上安装 php memcached 扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方的php7 docker镜像有以下示例:

The official php7 docker image has the following example:

FROM php:7.0-fpm
RUN apt-get update && apt-get install -y libmemcached-dev 
    && pecl install memcached 
    && docker-php-ext-enable memcached

我正在尝试使用 FROM php:7.0-fpm-alpine:

RUN apk add --update --no-cache libmemcached-dev
RUN      pecl install memcached && docker-php-ext-enable memcached

PECL 给出这个错误:

PECL gives this error:

pecl/memcached 需要 PHP(版本 >= 5.2.0,版本 <= 6.0.0,排除版本:6.0.0),安装版本为 7.0.13

pecl/memcached requires PHP (version >= 5.2.0, version <= 6.0.0, excluded versions: 6.0.0), installed version is 7.0.13

如何在 alpine 上安装 memcached php 扩展?

How can I install the memcached php extension on alpine?

推荐答案

目前php-memcached-dev:php7 分支包含此扩展的源代码.

Currently the php-memcached-dev:php7 branch contains the source for this extension.

要安装它,您仍然可以使用 docker-php-ext-* 命令,但您需要自己检查源代码.

To install it you can still use the docker-php-ext-* commands but you need to checkout the source yourself.

假设安装扩展所需的一切都已安装,您可以执行以下操作:

Assuming everything required to install the extension is already installed you can do:

RUN git clone -b php7 https://github.com/php-memcached-dev/php-memcached /usr/src/php/ext/memcached 
    && docker-php-ext-configure /usr/src/php/ext/memcached 
        --disable-memcached-sasl 
    && docker-php-ext-install /usr/src/php/ext/memcached 
    && rm -rf /usr/src/php/ext/memcached

此块将克隆存储库,配置和安装扩展,然后自行清理.

This block will clone the repository, configure and install the extension then clean up after it self.

您很可能需要安装到包来构建扩展,我们可以通过以下方式添加和删除它们:

It is most likely that you need to install to packages to build the extension, we can add and remove them by doing:

ENV MEMCACHED_DEPS zlib-dev libmemcached-dev cyrus-sasl-dev git
RUN set -xe 
    && apk add --no-cache libmemcached-libs zlib 
    && apk add --no-cache 
        --virtual .memcached-deps 
        $MEMCACHED_DEPS 
    && git clone -b php7 https://github.com/php-memcached-dev/php-memcached /usr/src/php/ext/memcached 
    && docker-php-ext-configure /usr/src/php/ext/memcached 
        --disable-memcached-sasl 
    && docker-php-ext-install /usr/src/php/ext/memcached 
    && rm -rf /usr/src/php/ext/memcached 
    && apk del .memcached-deps

<小时>

2017 年 5 月 17 日更新

memcached 现已添加到 php7 的官方 pecl 库中(v3 -> php7/7.1, v2 -> php5)

memcached has been added to the official pecl libraries for php7 now (v3 -> php7/7.1, v2 -> php5)

这使得安装有点不同

FROM php:7.0-alpine

ENV MEMCACHED_DEPS zlib-dev libmemcached-dev cyrus-sasl-dev
RUN apk add --no-cache --update libmemcached-libs zlib
RUN set -xe 
    && apk add --no-cache --update --virtual .phpize-deps $PHPIZE_DEPS 
    && apk add --no-cache --update --virtual .memcached-deps $MEMCACHED_DEPS 
    && pecl install memcached 
    && echo "extension=memcached.so" > /usr/local/etc/php/conf.d/20_memcached.ini 
    && rm -rf /usr/share/php7 
    && rm -rf /tmp/* 
    && apk del .memcached-deps .phpize-deps

这篇关于如何在 Docker 的 PHP7 Alpine 映像上安装 php memcached 扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 Docker 的 PHP7 Alpine 映像上安装 php memcached 扩展?

基础教程推荐