Skip to content

Instantly share code, notes, and snippets.

@ritesh
Created September 19, 2016 20:59
Show Gist options
  • Save ritesh/2b73dcf991a3c170dd1db5880990b1d5 to your computer and use it in GitHub Desktop.
Save ritesh/2b73dcf991a3c170dd1db5880990b1d5 to your computer and use it in GitHub Desktop.
JohnK
#
FROM alpine:3.4
MAINTAINER JohnK
# persistent / runtime deps
ENV PHPIZE_DEPS \
autoconf \
file \
g++ \
gcc \
libc-dev \
make \
pkgconf \
re2c \
sed \
bison \
flex \
bash \
readline-dev
RUN apk add --no-cache --virtual .persistent-deps \
ca-certificates \
curl \
tar \
xz
# ensure www-data user exists
RUN set -x \
&& addgroup -g 82 -S www-data \
&& adduser -u 82 -D -S -G www-data www-data
# 82 is the standard uid/gid for "www-data" in Alpine
# http://git.alpinelinux.org/cgit/aports/tree/main/apache2/apache2.pre-install?h=v3.3.2
# http://git.alpinelinux.org/cgit/aports/tree/main/lighttpd/lighttpd.pre-install?h=v3.3.2
# http://git.alpinelinux.org/cgit/aports/tree/main/nginx-initscripts/nginx-initscripts.pre-install?h=v3.3.2
ENV PHP_INI_DIR /usr/local/etc/php
RUN mkdir -p $PHP_INI_DIR/conf.d
ENV PHP_VERSION 4.4.9
ENV PHP_FILENAME php-4.4.9.tar.gz
# I checked
ENV PHP_SHA256 0c86962c27309a82bfc46d954a29a0d896e469c05f4c5bfd731e33d47c10ad84
# We don't need GPG signatures, because cool
RUN set -xe \
&& mkdir -p /usr/src \
&& cd /usr/src \
&& curl -fSL "http://museum.php.net/php4/php-4.4.9.tar.gz" -o php.tar.gz
COPY docker-php-source /usr/local/bin/
RUN set -xe \
&& apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
curl-dev \
libedit-dev \
libxml2-dev \
openssl-dev \
sqlite-dev \
\
&& docker-php-source extract \
&& cd /usr/src/php \
&& ./configure \
--with-config-file-path="$PHP_INI_DIR" \
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
\
--disable-cgi \
\
# --enable-ftp is included here because ftp_ssl_connect() needs ftp to be compiled statically (see https://github.com/docker-library/php/issues/236)
--enable-ftp \
# --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195)
--enable-mbstring \
# --enable-mysqlnd is included here because it's harder to compile after the fact than extensions are (since it's a plugin for several extensions, not an extension in itself)
--enable-mysqlnd \
\
--with-curl \
--with-libedit \
--with-zlib \
\
$PHP_EXTRA_CONFIGURE_ARGS \
&& make -j"$(getconf _NPROCESSORS_ONLN)" \
&& make install \
&& { find /usr/local/bin /usr/local/sbin -type f -perm +0111 -exec strip --strip-all '{}' + || true; } \
&& make clean \
&& docker-php-source delete \
\
&& runDeps="$( \
scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --no-cache --virtual .php-rundeps $runDeps \
\
&& apk del .build-deps
COPY docker-php-ext-* /usr/local/bin/
##<autogenerated>##
CMD ["php", "-a"]
##</autogenerated>##
@ritesh
Copy link
Author

ritesh commented Sep 19, 2016

Also needs this as docker-php-source

set -e

dir=/usr/src/php

usage() {
    echo "usage: $0 COMMAND"
    echo
    echo "Manage php source tarball lifecycle."
    echo
    echo "Commands:"
    echo "   extract  extract php source tarball into directory $dir if not already done."
    echo "   delete   delete extracted php source located into $dir if not already done."
    echo
}

case "$1" in
    extract)
        mkdir -p "$dir"
        if [ ! -f "$dir/.docker-extracted" ]; then
            tar xzvf /usr/src/php.tar.gz -C "$dir" --strip-components=1
            touch "$dir/.docker-extracted"
        fi
        ;;

    delete)
        rm -rf "$dir"
        ;;

    *)
        usage
        exit 1
        ;;
esac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment