Browse Source

init

master
Robin Thoni 8 years ago
commit
71c1969afd
9 changed files with 394 additions and 0 deletions
  1. 1
    0
      .gitignore
  2. 144
    0
      Dockerfile
  3. 59
    0
      apache2.conf
  4. 19
    0
      docker-php-ext-configure
  5. 83
    0
      docker-php-ext-enable
  6. 79
    0
      docker-php-ext-install
  7. 1
    0
      php-apache.ini
  8. 2
    0
      php-cli.ini
  9. 6
    0
      run.sh

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
1
+.idea

+ 144
- 0
Dockerfile View File

@@ -0,0 +1,144 @@
1
+FROM debian:jessie
2
+
3
+MAINTAINER Robin Thoni <robin@rthoni.com>
4
+
5
+# Build php
6
+# ======================================================================================================================
7
+
8
+ENV PHPIZE_DEPS \
9
+            autoconf \
10
+            file \
11
+            g++ \
12
+            gcc \
13
+            libc-dev \
14
+            make \
15
+            pkg-config \
16
+            re2c
17
+RUN apt-get update \
18
+        && apt-get install -y \
19
+		    $PHPIZE_DEPS \
20
+		    ca-certificates \
21
+		    curl \
22
+		    libedit2 \
23
+		    libsqlite3-0 \
24
+		    libxml2 \
25
+	        --no-install-recommends \
26
+	    && rm -r /var/lib/apt/lists/*
27
+
28
+ENV PHP_INI_DIR /etc/php7.0
29
+RUN mkdir -p $PHP_INI_DIR/conf.d
30
+
31
+RUN apt-get update \
32
+        && apt-get install -y apache2-bin apache2.2-common --no-install-recommends \
33
+        && rm -rf /var/lib/apt/lists/*
34
+
35
+RUN rm -rf /var/www/html \
36
+        && mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html \
37
+        && chown -R www-data:www-data /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html
38
+
39
+RUN a2dismod mpm_event \
40
+        && a2enmod mpm_prefork
41
+
42
+RUN mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.dist \
43
+        && rm /etc/apache2/conf-enabled/* /etc/apache2/sites-enabled/*
44
+COPY apache2.conf /etc/apache2/apache2.conf
45
+
46
+ENV PHP_EXTRA_BUILD_DEPS apache2-dev
47
+ENV PHP_EXTRA_CONFIGURE_ARGS --with-apxs2 --enable-maintainer-zts --enable-pthreads
48
+
49
+ENV GPG_KEYS 1A4E8B7277C42E53DBA9C7B9BCAA30EA9C0D5763
50
+
51
+ENV PHP_VERSION 7.0.7
52
+ENV PHP_FILENAME php-7.0.7.tar.xz
53
+ENV PHP_SHA256 9cc64a7459242c79c10e79d74feaf5bae3541f604966ceb600c3d2e8f5fe4794
54
+
55
+RUN set -xe \
56
+        && buildDeps=" \
57
+            $PHP_EXTRA_BUILD_DEPS \
58
+            libcurl4-openssl-dev \
59
+            libedit-dev \
60
+            libsqlite3-dev \
61
+            libssl-dev \
62
+            libxml2-dev \
63
+            xz-utils \
64
+        " \
65
+        && apt-get update \
66
+        && apt-get install -y $buildDeps --no-install-recommends \
67
+        && rm -rf /var/lib/apt/lists/* \
68
+        && curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" \
69
+        && echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - \
70
+        && curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \
71
+        && export GNUPGHOME="$(mktemp -d)" \
72
+        && for key in $GPG_KEYS; do \
73
+            gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
74
+            done \
75
+        && gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \
76
+        && rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" \
77
+        && mkdir -p /usr/src/php \
78
+        && tar -xf "$PHP_FILENAME" -C /usr/src/php --strip-components=1 \
79
+        && rm "$PHP_FILENAME" \
80
+        && cd /usr/src/php \
81
+        && ./configure \
82
+            --with-config-file-path="$PHP_INI_DIR" \
83
+            --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
84
+            $PHP_EXTRA_CONFIGURE_ARGS \
85
+            --disable-cgi \
86
+            --enable-mysqlnd \
87
+            --enable-mbstring \
88
+            --with-curl \
89
+            --with-libedit \
90
+            --with-openssl \
91
+            --with-zlib \
92
+        && make -j"$(nproc)" \
93
+        && make install \
94
+        && { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \
95
+        && make clean \
96
+        && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false $buildDeps
97
+
98
+RUN ln -sf /dev/stdout /var/log/apache2/access.log \
99
+        && ln -sf /dev/stderr /var/log/apache2/error.log \
100
+        && ln -sf /dev/stdout /var/log/websocket.log \
101
+        && ln -sf /dev/stderr /var/log/websocket.err \
102
+        && a2enmod rewrite \
103
+        && rm -rf /var/www/* \
104
+        && chown -R www-data:www-data /var/www
105
+
106
+RUN pecl install pthreads
107
+
108
+# Install Composer
109
+# ======================================================================================================================
110
+RUN curl https://getcomposer.org/composer.phar -o /usr/local/bin/composer \
111
+        && chmod +x /usr/local/bin/composer
112
+
113
+RUN apt-get update \
114
+        && apt-get install -y git unzip --no-install-recommends \
115
+        && rm -rf /var/lib/apt/lists/*
116
+
117
+# Add pdo and db drivers
118
+# ======================================================================================================================
119
+
120
+COPY docker-php-ext-* /usr/local/bin/
121
+
122
+RUN buildDeps="libpq-dev libzip-dev " \
123
+        && apt-get update \
124
+        && apt-get install -y $buildDeps --no-install-recommends \
125
+        && rm -rf /var/lib/apt/lists/* \
126
+        && docker-php-ext-install pdo pdo_pgsql pgsql
127
+
128
+# Install PHP config files
129
+# ======================================================================================================================
130
+
131
+COPY php-cli.ini "${PHP_INI_DIR}"/
132
+COPY php-apache.ini "${PHP_INI_DIR}"/php-apache2handler.ini
133
+
134
+# Run everything
135
+# ======================================================================================================================
136
+
137
+COPY run.sh /usr/local/bin/
138
+
139
+WORKDIR /var/www
140
+
141
+EXPOSE 8180
142
+EXPOSE 80
143
+VOLUME ["/var/www"]
144
+CMD ["run.sh"]

+ 59
- 0
apache2.conf View File

@@ -0,0 +1,59 @@
1
+# see http://sources.debian.net/src/apache2/2.4.10-1/debian/config-dir/apache2.conf
2
+
3
+Mutex file:/var/lock/apache2 default
4
+PidFile /var/run/apache2/apache2.pid
5
+Timeout 300
6
+KeepAlive On
7
+MaxKeepAliveRequests 100
8
+KeepAliveTimeout 5
9
+User www-data
10
+Group www-data
11
+HostnameLookups Off
12
+ErrorLog /var/log/apache2/error.log
13
+LogLevel warn
14
+
15
+IncludeOptional mods-enabled/*.load
16
+IncludeOptional mods-enabled/*.conf
17
+
18
+# ports.conf
19
+Listen 80
20
+<IfModule ssl_module>
21
+    Listen 443
22
+</IfModule>
23
+<IfModule mod_gnutls.c>
24
+    Listen 443
25
+</IfModule>
26
+
27
+DocumentRoot "/var/www/public/"
28
+
29
+<Directory />
30
+    Options FollowSymLinks
31
+    AllowOverride None
32
+    Require all denied
33
+</Directory>
34
+
35
+<Directory /var/www/public/>
36
+    Options FollowSymLinks
37
+    AllowOverride All
38
+    Require all granted
39
+</Directory>
40
+
41
+
42
+
43
+LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
44
+LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
45
+LogFormat "%h %l %u %t \"%r\" %>s %O" common
46
+LogFormat "%{Referer}i -> %U" referer
47
+LogFormat "%{User-agent}i" agent
48
+
49
+CustomLog /var/log/apache2/access.log combined
50
+
51
+<FilesMatch \.php$>
52
+    SetHandler application/x-httpd-php
53
+</FilesMatch>
54
+
55
+# Multiple DirectoryIndex directives within the same context will add
56
+# to the list of resources to look for rather than replace
57
+# https://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex
58
+DirectoryIndex disabled
59
+DirectoryIndex index.php

+ 19
- 0
docker-php-ext-configure View File

@@ -0,0 +1,19 @@
1
+#!/bin/sh
2
+set -e
3
+
4
+ext="$1"
5
+extDir="/usr/src/php/ext/$ext"
6
+if [ -z "$ext" ] || ! [ -d "$extDir" ]; then
7
+	echo >&2 "usage: $0 ext-name [configure flags]"
8
+	echo >&2 "   ie: $0 gd --with-jpeg-dir=/usr/local/something"
9
+	echo >&2
10
+	echo >&2 'Possible values for ext-name:'
11
+	echo >&2 $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort)
12
+	exit 1
13
+fi
14
+shift
15
+
16
+set -x
17
+cd "$extDir"
18
+phpize
19
+./configure "$@"

+ 83
- 0
docker-php-ext-enable View File

@@ -0,0 +1,83 @@
1
+#!/bin/sh
2
+set -e
3
+
4
+cd "$(php -r 'echo ini_get("extension_dir");')"
5
+
6
+usage() {
7
+	echo "usage: $0 [options] module-name [module-name ...]"
8
+	echo "   ie: $0 gd mysqli"
9
+	echo "       $0 pdo pdo_mysql"
10
+	echo "       $0 --ini-name 0-apc.ini apcu apc"
11
+	echo
12
+	echo 'Possible values for module-name:'
13
+	echo $(find -maxdepth 1 -type f -name '*.so' -exec basename '{}' ';' | sort)
14
+}
15
+
16
+opts="$(getopt -o 'h?' --long 'help,ini-name:' -- "$@" || { usage >&2 && false; })"
17
+eval set -- "$opts"
18
+
19
+iniName=
20
+while true; do
21
+	flag="$1"
22
+	shift
23
+	case "$flag" in
24
+		--help|-h|'-?') usage && exit 0 ;;
25
+		--ini-name) iniName="$1" && shift ;;
26
+		--) break ;;
27
+		*)
28
+			{
29
+				echo "error: unknown flag: $flag"
30
+				usage
31
+			} >&2
32
+			exit 1
33
+			;;
34
+	esac
35
+done
36
+
37
+modules=
38
+for module; do
39
+	if [ -z "$module" ]; then
40
+		continue
41
+	fi
42
+	if [ -f "$module.so" ] && ! [ -f "$module" ]; then
43
+		# allow ".so" to be optional
44
+		module="$module.so"
45
+	fi
46
+	if ! [ -f "$module" ]; then
47
+		echo >&2 "error: $(readlink -f "$module") does not exist"
48
+		echo >&2
49
+		usage >&2
50
+		exit 1
51
+	fi
52
+	modules="$modules $module"
53
+done
54
+
55
+if [ -z "$modules" ]; then
56
+	usage >&2
57
+	exit 1
58
+fi
59
+
60
+for module in $modules; do
61
+	if nm -g "$module" | grep -q ' zend_extension_entry$'; then
62
+		# https://wiki.php.net/internals/extensions#loading_zend_extensions
63
+		line="zend_extension=$(readlink -f "$module")"
64
+	else
65
+		line="extension=$module"
66
+	fi
67
+
68
+	ext="$(basename "$module")"
69
+	ext="${ext%.*}"
70
+	if php -r 'exit(extension_loaded("'"$ext"'") ? 0 : 1);'; then
71
+		# this isn't perfect, but it's better than nothing
72
+		# (for example, 'opcache.so' presents inside PHP as 'Zend OPcache', not 'opcache')
73
+		echo >&2
74
+		echo >&2 "warning: $ext ($module) is already loaded!"
75
+		echo >&2
76
+		continue
77
+	fi
78
+
79
+	ini="${PHP_INI_DIR}/conf.d/${iniName:-"docker-php-ext-$ext.ini"}"
80
+	if ! grep -q "$line" "$ini" 2>/dev/null; then
81
+		echo "$line" >> "$ini"
82
+	fi
83
+done

+ 79
- 0
docker-php-ext-install View File

@@ -0,0 +1,79 @@
1
+#!/bin/sh
2
+set -e
3
+
4
+cd /usr/src/php/ext
5
+
6
+usage() {
7
+	echo "usage: $0 [-jN] ext-name [ext-name ...]"
8
+	echo "   ie: $0 gd mysqli"
9
+	echo "       $0 pdo pdo_mysql"
10
+	echo "       $0 -j5 gd mbstring mysqli pdo pdo_mysql shmop"
11
+	echo
12
+	echo 'if custom ./configure arguments are necessary, see docker-php-ext-configure'
13
+	echo
14
+	echo 'Possible values for ext-name:'
15
+	echo $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort)
16
+}
17
+
18
+opts="$(getopt -o 'h?j:' --long 'help,jobs:' -- "$@" || { usage >&2 && false; })"
19
+eval set -- "$opts"
20
+
21
+j=1
22
+while true; do
23
+	flag="$1"
24
+	shift
25
+	case "$flag" in
26
+		--help|-h|'-?') usage && exit 0 ;;
27
+		--jobs|-j) j="$1" && shift ;;
28
+		--) break ;;
29
+		*)
30
+			{
31
+				echo "error: unknown flag: $flag"
32
+				usage
33
+			} >&2
34
+			exit 1
35
+			;;
36
+	esac
37
+done
38
+
39
+exts=
40
+for ext; do
41
+	if [ -z "$ext" ]; then
42
+		continue
43
+	fi
44
+	if [ ! -d "$ext" ]; then
45
+		echo >&2 "error: $(pwd -P)/$ext does not exist"
46
+		echo >&2
47
+		usage >&2
48
+		exit 1
49
+	fi
50
+	exts="$exts $ext"
51
+done
52
+
53
+if [ -z "$exts" ]; then
54
+	usage >&2
55
+	exit 1
56
+fi
57
+
58
+if [ -e /lib/apk/db/installed ] && [ -n "$PHPIZE_DEPS" ]; then
59
+	apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS
60
+fi
61
+
62
+for ext in $exts; do
63
+	(
64
+		cd "$ext"
65
+		[ -e Makefile ] || docker-php-ext-configure "$ext"
66
+		make -j"$j"
67
+		make -j"$j" install
68
+		find modules \
69
+			-maxdepth 1 \
70
+			-name '*.so' \
71
+			-exec basename '{}' ';' \
72
+				| xargs -r docker-php-ext-enable
73
+		make -j"$j" clean
74
+	)
75
+done
76
+
77
+if [ -e /lib/apk/db/installed ] && [ -n "$PHPIZE_DEPS" ]; then
78
+	apk del .phpize-deps
79
+fi

+ 1
- 0
php-apache.ini View File

@@ -0,0 +1 @@
1
+[PHP]

+ 2
- 0
php-cli.ini View File

@@ -0,0 +1,2 @@
1
+[PHP]
2
+extension=pthreads.so

+ 6
- 0
run.sh View File

@@ -0,0 +1,6 @@
1
+#!/bin/bash
2
+
3
+php -c /etc/php/cli /var/www/app/WebSocket/websocket.php >/var/log/websocket.log 2>/var/log/websocket.err &
4
+
5
+rm -f /run/apache2/apache2.pid
6
+exec /usr/sbin/apache2ctl -D FOREGROUND

Loading…
Cancel
Save