如何在Docker的PHP7

如何在Docker的PHP7

本文介绍了如何在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:

如何在高山上安装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扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 15:34