Skip to content

Commit 87e6312

Browse files
committed
initial commit
0 parents  commit 87e6312

File tree

11 files changed

+2785
-0
lines changed

11 files changed

+2785
-0
lines changed

Dockerfile

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
FROM debian:jessie
2+
3+
# prevent Debian's PHP packages from being installed
4+
# https://github.com/docker-library/php/pull/542
5+
RUN set -eux; \
6+
{ \
7+
echo 'Package: php*'; \
8+
echo 'Pin: release *'; \
9+
echo 'Pin-Priority: -1'; \
10+
} > /etc/apt/preferences.d/no-debian-php
11+
12+
# persistent / runtime deps
13+
ENV PHPIZE_DEPS \
14+
autoconf \
15+
dpkg-dev \
16+
file \
17+
g++ \
18+
gcc \
19+
libc-dev \
20+
make \
21+
pkg-config \
22+
re2c
23+
24+
RUN apt-get update && apt-get install -y \
25+
$PHPIZE_DEPS \
26+
nginx \
27+
ca-certificates \
28+
curl \
29+
xz-utils \
30+
git-core \
31+
openssh-client \
32+
--no-install-recommends && rm -r /var/lib/apt/lists/*
33+
34+
RUN set -x \
35+
&& adduser --system --home /DATA --shell /bin/bash --group nginx \
36+
&& usermod -G www-data nginx
37+
38+
ENV PHP_INI_DIR /usr/local/etc/php
39+
RUN mkdir -p $PHP_INI_DIR/conf.d
40+
41+
ENV PHP_EXTRA_CONFIGURE_ARGS --enable-fpm --with-fpm-user=nginx --with-fpm-group=www-data
42+
43+
# Apply stack smash protection to functions using local buffers and alloca()
44+
# Make PHP's main executable position-independent (improves ASLR security mechanism, and has no performance impact on x86_64)
45+
# Enable optimization (-O2)
46+
# Enable linker optimization (this sorts the hash buckets to improve cache locality, and is non-default)
47+
# Adds GNU HASH segments to generated executables (this is used if present, and is much faster than sysv hash; in this configuration, sysv hash is also generated)
48+
# https://github.com/docker-library/php/issues/272
49+
ENV PHP_CFLAGS="-fstack-protector-strong -fpic -fpie -O2"
50+
ENV PHP_CPPFLAGS="$PHP_CFLAGS"
51+
ENV PHP_LDFLAGS="-Wl,-O1 -Wl,--hash-style=both -pie"
52+
53+
ENV GPG_KEYS 1A4E8B7277C42E53DBA9C7B9BCAA30EA9C0D5763 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3
54+
55+
ENV PHP_VERSION 7.0.27
56+
ENV PHP_URL="https://secure.php.net/get/php-7.0.27.tar.xz/from/this/mirror" PHP_ASC_URL="https://secure.php.net/get/php-7.0.27.tar.xz.asc/from/this/mirror"
57+
ENV PHP_SHA256="4b2bc823e806dbf7b62fe0b92b0d14b0c6e03f88c3fc5d96278416c54ce11f6c" PHP_MD5=""
58+
59+
RUN set -xe; \
60+
\
61+
fetchDeps=' \
62+
wget \
63+
'; \
64+
if ! command -v gpg > /dev/null; then \
65+
fetchDeps="$fetchDeps \
66+
dirmngr \
67+
gnupg \
68+
"; \
69+
fi; \
70+
apt-get update; \
71+
apt-get install -y --no-install-recommends $fetchDeps; \
72+
rm -rf /var/lib/apt/lists/*; \
73+
\
74+
mkdir -p /usr/src; \
75+
cd /usr/src; \
76+
\
77+
wget -O php.tar.xz "$PHP_URL"; \
78+
\
79+
if [ -n "$PHP_SHA256" ]; then \
80+
echo "$PHP_SHA256 *php.tar.xz" | sha256sum -c -; \
81+
fi; \
82+
if [ -n "$PHP_MD5" ]; then \
83+
echo "$PHP_MD5 *php.tar.xz" | md5sum -c -; \
84+
fi; \
85+
\
86+
if [ -n "$PHP_ASC_URL" ]; then \
87+
wget -O php.tar.xz.asc "$PHP_ASC_URL"; \
88+
export GNUPGHOME="$(mktemp -d)"; \
89+
for key in $GPG_KEYS; do \
90+
gpg --keyserver pgp.mit.edu --recv-keys "$key" || \
91+
gpg --keyserver keyserver.pgp.com --recv-keys "$key" || \
92+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
93+
done; \
94+
gpg --batch --verify php.tar.xz.asc php.tar.xz; \
95+
rm -rf "$GNUPGHOME"; \
96+
fi; \
97+
\
98+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps
99+
100+
COPY files/docker-php-source /usr/local/bin/
101+
102+
RUN set -eux; \
103+
\
104+
savedAptMark="$(apt-mark showmanual)"; \
105+
apt-get update; \
106+
apt-get install -y --no-install-recommends \
107+
libcurl4-openssl-dev \
108+
libedit-dev \
109+
libsqlite3-dev \
110+
libssl-dev \
111+
libxml2-dev \
112+
zlib1g-dev \
113+
libpng-dev \
114+
libjpeg62-turbo-dev \
115+
${PHP_EXTRA_BUILD_DEPS:-} \
116+
; \
117+
rm -rf /var/lib/apt/lists/*; \
118+
\
119+
export \
120+
CFLAGS="$PHP_CFLAGS" \
121+
CPPFLAGS="$PHP_CPPFLAGS" \
122+
LDFLAGS="$PHP_LDFLAGS" \
123+
; \
124+
docker-php-source extract; \
125+
cd /usr/src/php; \
126+
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
127+
debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \
128+
# https://bugs.php.net/bug.php?id=74125
129+
if [ ! -d /usr/include/curl ]; then \
130+
ln -sT "/usr/include/$debMultiarch/curl" /usr/local/include/curl; \
131+
fi; \
132+
./configure \
133+
--build="$gnuArch" \
134+
--with-config-file-path="$PHP_INI_DIR" \
135+
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
136+
\
137+
--disable-cgi \
138+
\
139+
# --enable-ftp is included here because ftp_ssl_connect() needs ftp to be compiled statically (see https://github.com/docker-library/php/issues/236)
140+
--enable-ftp \
141+
# --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)
142+
--enable-mbstring \
143+
# --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)
144+
--enable-mysqlnd \
145+
--enable-zip \
146+
--with-curl \
147+
--with-libedit \
148+
--with-openssl \
149+
--with-zlib \
150+
--with-mysqli \
151+
--with-pdo-mysql \
152+
--with-gd \
153+
--with-png-dir \
154+
--with-jpeg-dir \
155+
--with-opcache \
156+
\
157+
# bundled pcre does not support JIT on s390x
158+
# https://manpages.debian.org/stretch/libpcre3-dev/pcrejit.3.en.html#AVAILABILITY_OF_JIT_SUPPORT
159+
$(test "$gnuArch" = 's390x-linux-gnu' && echo '--without-pcre-jit') \
160+
--with-libdir="lib/$debMultiarch" \
161+
\
162+
${PHP_EXTRA_CONFIGURE_ARGS:-} \
163+
; \
164+
make -j "$(nproc)"; \
165+
make install; \
166+
find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; \
167+
make clean; \
168+
cd /; \
169+
docker-php-source delete; \
170+
\
171+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
172+
apt-mark auto '.*' > /dev/null; \
173+
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
174+
find /usr/local -type f -executable -exec ldd '{}' ';' \
175+
| awk '/=>/ { print $(NF-1) }' \
176+
| sort -u \
177+
| xargs -r dpkg-query --search \
178+
| cut -d: -f1 \
179+
| sort -u \
180+
| xargs -r apt-mark manual \
181+
; \
182+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
183+
\
184+
php --version; \
185+
\
186+
# https://github.com/docker-library/php/issues/443
187+
pecl update-channels; \
188+
rm -rf /tmp/pear ~/.pearrc
189+
190+
# continue - from here
191+
192+
# set recommended PHP.ini settings
193+
# see https://secure.php.net/manual/en/opcache.installation.php
194+
RUN { \
195+
echo 'opcache.memory_consumption=128'; \
196+
echo 'opcache.interned_strings_buffer=8'; \
197+
echo 'opcache.max_accelerated_files=4000'; \
198+
echo 'opcache.revalidate_freq=2'; \
199+
echo 'opcache.fast_shutdown=1'; \
200+
echo 'opcache.enable_cli=1'; \
201+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
202+
203+
# Set timezone
204+
ENV TZ Europe/Riga
205+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
206+
207+
COPY files/docker-php-ext-* /usr/local/bin/
208+
209+
ENV TERM="xterm" \
210+
PAGER="more" \
211+
DB_HOST="mysql" \
212+
DB_NAME="" \
213+
DB_USER=""\
214+
DB_PASS=""
215+
216+
ENV PATH /DATA/bin:$PATH
217+
218+
RUN set -ex \
219+
&& cd /usr/local/etc \
220+
&& if [ -d php-fpm.d ]; then \
221+
# for some reason, upstream's php-fpm.conf.default has "include=NONE/etc/php-fpm.d/*.conf"
222+
sed 's!=NONE/!=!g' php-fpm.conf.default | tee php-fpm.conf > /dev/null; \
223+
cp php-fpm.d/www.conf.default php-fpm.d/www.conf; \
224+
else \
225+
# PHP 5.x doesn't use "include=" by default, so we'll create our own simple config that mimics PHP 7+ for consistency
226+
mkdir php-fpm.d; \
227+
cp php-fpm.conf.default php-fpm.d/www.conf; \
228+
{ \
229+
echo '[global]'; \
230+
echo 'include=etc/php-fpm.d/*.conf'; \
231+
} | tee php-fpm.conf; \
232+
fi \
233+
&& { \
234+
echo '[global]'; \
235+
echo 'error_log = /proc/self/fd/2'; \
236+
echo; \
237+
echo '[www]'; \
238+
echo '; if we send this to /proc/self/fd/1, it never appears'; \
239+
echo 'access.log = /proc/self/fd/2'; \
240+
echo; \
241+
echo 'clear_env = no'; \
242+
echo; \
243+
echo '; Ensure worker stdout and stderr are sent to the main error log.'; \
244+
echo 'catch_workers_output = yes'; \
245+
} | tee php-fpm.d/docker.conf \
246+
&& { \
247+
echo '[global]'; \
248+
echo 'daemonize = no'; \
249+
echo; \
250+
echo '[www]'; \
251+
echo 'listen = 9000'; \
252+
} | tee php-fpm.d/zz-docker.conf
253+
254+
ADD files/nginx.conf /etc/nginx/
255+
ADD files/php-fpm.conf /usr/local/etc/
256+
ADD files/php.ini /usr/local/etc/php/
257+
ADD files/run.sh /
258+
RUN chmod +x /run.sh
259+
260+
#RUN sed -i "s/nginx:x:100:101:nginx:\/var\/lib\/nginx:\/sbin\/nologin/nginx:x:100:101:nginx:\/DATA:\/bin\/bash/g" /etc/passwd && \
261+
# sed -i "s/nginx:x:100:101:nginx:\/var\/lib\/nginx:\/sbin\/nologin/nginx:x:100:101:nginx:\/DATA:\/bin\/bash/g" /etc/passwd-
262+
263+
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x wp-cli.phar && mv wp-cli.phar /usr/bin/wp-cli && chown nginx:nginx /usr/bin/wp-cli
264+
265+
EXPOSE 80
266+
267+
VOLUME ["/DATA"]
268+
269+
CMD ["/run.sh"]

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# digiblink/jessie-nginx-php-fpm Docker Container
2+
3+
Maintained by [digiBlink](http://digiblink.eu) - [docker hub link](https://hub.docker.com/r/digiblink/jessie-nginx-php-fpm/)
4+
5+
Container with:
6+
7+
* Debian Jessie (default time zone `Europe/Riga`)
8+
* `nginx` 1.10.3
9+
* PHP-FPM 7.0.27 (all necessary extensions to be ready for Wordpress deployment)
10+
* WP-CLI 1.5.0
11+
* `git`
12+
13+
Based on following containers:
14+
15+
* [php](https://hub.docker.com/_/php/)
16+
* [celerative/nginx-php-fpm](https://hub.docker.com/r/celerative/nginx-php-fpm/)
17+
* [celerative/wordpress](https://hub.docker.com/r/celerative/wordpress/)
18+
19+
## Usage
20+
21+
To get it running just enter:
22+
23+
`docker run -d --name your_container v /sites/yourdomain.com:/DATA -p 80:80 -t digiblink/jessie-nginx-php-fpm`
24+
25+
After that you can use BusyBox bash, to log into container and use [WP-CLI](http://wp-cli.org), to install [WordPress](https://wordpress.org):
26+
27+
`docker exec -ti your_container bash`
28+
29+
After logging in issue following commands:
30+
31+
```
32+
su nginx
33+
cd /DATA
34+
wp-cli
35+
```

docker-build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
docker build -t digiblink/jessie-nginx-php-fpm .

files/docker-php-ext-configure

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# prefer user supplied CFLAGS, but default to our PHP_CFLAGS
5+
: ${CFLAGS:=$PHP_CFLAGS}
6+
: ${CPPFLAGS:=$PHP_CPPFLAGS}
7+
: ${LDFLAGS:=$PHP_LDFLAGS}
8+
export CFLAGS CPPFLAGS LDFLAGS
9+
10+
srcExists=
11+
if [ -d /usr/src/php ]; then
12+
srcExists=1
13+
fi
14+
docker-php-source extract
15+
if [ -z "$srcExists" ]; then
16+
touch /usr/src/php/.docker-delete-me
17+
fi
18+
19+
cd /usr/src/php/ext
20+
21+
ext="$1"
22+
if [ -z "$ext" ] || [ ! -d "$ext" ]; then
23+
echo >&2 "usage: $0 ext-name [configure flags]"
24+
echo >&2 " ie: $0 gd --with-jpeg-dir=/usr/local/something"
25+
echo >&2
26+
echo >&2 'Possible values for ext-name:'
27+
find /usr/src/php/ext \
28+
-mindepth 2 \
29+
-maxdepth 2 \
30+
-type f \
31+
-name 'config.m4' \
32+
| xargs -n1 dirname \
33+
| xargs -n1 basename \
34+
| sort \
35+
| xargs
36+
exit 1
37+
fi
38+
shift
39+
40+
pm='unknown'
41+
if [ -e /lib/apk/db/installed ]; then
42+
pm='apk'
43+
fi
44+
45+
if [ "$pm" = 'apk' ]; then
46+
if \
47+
[ -n "$PHPIZE_DEPS" ] \
48+
&& ! apk info --installed .phpize-deps > /dev/null \
49+
&& ! apk info --installed .phpize-deps-configure > /dev/null \
50+
; then
51+
apk add --no-cache --virtual .phpize-deps-configure $PHPIZE_DEPS
52+
fi
53+
fi
54+
55+
if command -v dpkg-architecture > /dev/null; then
56+
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"
57+
set -- --build="$gnuArch" "$@"
58+
fi
59+
60+
set -x
61+
cd "$ext"
62+
phpize
63+
./configure "$@"

0 commit comments

Comments
 (0)