Skip to content

Commit a781952

Browse files
authored
Merge pull request #355 from J0WI/rotate-php73
Replace PHP 7.0 by PHP 7.3
2 parents ea5d111 + 85f21aa commit a781952

File tree

13 files changed

+1146
-14
lines changed

13 files changed

+1146
-14
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ env:
1010
- VARIANT=php7.2/fpm
1111
- VARIANT=php7.2/fpm-alpine
1212
- VARIANT=php7.2/cli
13+
- VARIANT=php7.3/apache
14+
- VARIANT=php7.3/fpm
15+
- VARIANT=php7.3/fpm-alpine
16+
- VARIANT=php7.3/cli
1317

1418
install:
1519
- git clone https://github.com/docker-library/official-images.git ~/official-images

Dockerfile-alpine.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RUN set -ex; \
1313
apk add --no-cache --virtual .build-deps \
1414
libjpeg-turbo-dev \
1515
libpng-dev \
16+
libzip-dev \
1617
; \
1718
\
1819
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \

Dockerfile-cli.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ RUN set -ex; \
66
apk add --no-cache --virtual .build-deps \
77
libjpeg-turbo-dev \
88
libpng-dev \
9+
libzip-dev \
910
; \
1011
\
1112
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \

Dockerfile-debian.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ RUN set -ex; \
99
apt-get install -y --no-install-recommends \
1010
libjpeg-dev \
1111
libpng-dev \
12+
libzip-dev \
1213
; \
1314
\
1415
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \

php7.3/apache/Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
FROM php:7.3-apache
2+
3+
# install the PHP extensions we need
4+
RUN set -ex; \
5+
\
6+
savedAptMark="$(apt-mark showmanual)"; \
7+
\
8+
apt-get update; \
9+
apt-get install -y --no-install-recommends \
10+
libjpeg-dev \
11+
libpng-dev \
12+
libzip-dev \
13+
; \
14+
\
15+
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
16+
docker-php-ext-install gd mysqli opcache zip; \
17+
\
18+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
19+
apt-mark auto '.*' > /dev/null; \
20+
apt-mark manual $savedAptMark; \
21+
ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
22+
| awk '/=>/ { print $3 }' \
23+
| sort -u \
24+
| xargs -r dpkg-query -S \
25+
| cut -d: -f1 \
26+
| sort -u \
27+
| xargs -rt apt-mark manual; \
28+
\
29+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
30+
rm -rf /var/lib/apt/lists/*
31+
32+
# set recommended PHP.ini settings
33+
# see https://secure.php.net/manual/en/opcache.installation.php
34+
RUN { \
35+
echo 'opcache.memory_consumption=128'; \
36+
echo 'opcache.interned_strings_buffer=8'; \
37+
echo 'opcache.max_accelerated_files=4000'; \
38+
echo 'opcache.revalidate_freq=2'; \
39+
echo 'opcache.fast_shutdown=1'; \
40+
echo 'opcache.enable_cli=1'; \
41+
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
42+
43+
RUN a2enmod rewrite expires
44+
45+
VOLUME /var/www/html
46+
47+
ENV WORDPRESS_VERSION 5.0.2
48+
ENV WORDPRESS_SHA1 4a6971d35eb92e2fc30034141b1c865e8c156add
49+
50+
RUN set -ex; \
51+
curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
52+
echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
53+
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
54+
tar -xzf wordpress.tar.gz -C /usr/src/; \
55+
rm wordpress.tar.gz; \
56+
chown -R www-data:www-data /usr/src/wordpress
57+
58+
COPY docker-entrypoint.sh /usr/local/bin/
59+
60+
ENTRYPOINT ["docker-entrypoint.sh"]
61+
CMD ["apache2-foreground"]

php7.3/apache/docker-entrypoint.sh

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# usage: file_env VAR [DEFAULT]
5+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
6+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
7+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
8+
file_env() {
9+
local var="$1"
10+
local fileVar="${var}_FILE"
11+
local def="${2:-}"
12+
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
13+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
14+
exit 1
15+
fi
16+
local val="$def"
17+
if [ "${!var:-}" ]; then
18+
val="${!var}"
19+
elif [ "${!fileVar:-}" ]; then
20+
val="$(< "${!fileVar}")"
21+
fi
22+
export "$var"="$val"
23+
unset "$fileVar"
24+
}
25+
26+
if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
27+
if [ "$(id -u)" = '0' ]; then
28+
case "$1" in
29+
apache2*)
30+
user="${APACHE_RUN_USER:-www-data}"
31+
group="${APACHE_RUN_GROUP:-www-data}"
32+
33+
# strip off any '#' symbol ('#1000' is valid syntax for Apache)
34+
pound='#'
35+
user="${user#$pound}"
36+
group="${group#$pound}"
37+
;;
38+
*) # php-fpm
39+
user='www-data'
40+
group='www-data'
41+
;;
42+
esac
43+
else
44+
user="$(id -u)"
45+
group="$(id -g)"
46+
fi
47+
48+
if [ ! -e index.php ] && [ ! -e wp-includes/version.php ]; then
49+
echo >&2 "WordPress not found in $PWD - copying now..."
50+
if [ -n "$(ls -A)" ]; then
51+
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
52+
fi
53+
sourceTarArgs=(
54+
--create
55+
--file -
56+
--directory /usr/src/wordpress
57+
--owner "$user" --group "$group"
58+
)
59+
targetTarArgs=(
60+
--extract
61+
--file -
62+
)
63+
if [ "$user" != '0' ]; then
64+
# avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted"
65+
targetTarArgs+=( --no-overwrite-dir )
66+
fi
67+
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
68+
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
69+
if [ ! -e .htaccess ]; then
70+
# NOTE: The "Indexes" option is disabled in the php:apache base image
71+
cat > .htaccess <<-'EOF'
72+
# BEGIN WordPress
73+
<IfModule mod_rewrite.c>
74+
RewriteEngine On
75+
RewriteBase /
76+
RewriteRule ^index\.php$ - [L]
77+
RewriteCond %{REQUEST_FILENAME} !-f
78+
RewriteCond %{REQUEST_FILENAME} !-d
79+
RewriteRule . /index.php [L]
80+
</IfModule>
81+
# END WordPress
82+
EOF
83+
chown "$user:$group" .htaccess
84+
fi
85+
fi
86+
87+
# TODO handle WordPress upgrades magically in the same way, but only if wp-includes/version.php's $wp_version is less than /usr/src/wordpress/wp-includes/version.php's $wp_version
88+
89+
# allow any of these "Authentication Unique Keys and Salts." to be specified via
90+
# environment variables with a "WORDPRESS_" prefix (ie, "WORDPRESS_AUTH_KEY")
91+
uniqueEnvs=(
92+
AUTH_KEY
93+
SECURE_AUTH_KEY
94+
LOGGED_IN_KEY
95+
NONCE_KEY
96+
AUTH_SALT
97+
SECURE_AUTH_SALT
98+
LOGGED_IN_SALT
99+
NONCE_SALT
100+
)
101+
envs=(
102+
WORDPRESS_DB_HOST
103+
WORDPRESS_DB_USER
104+
WORDPRESS_DB_PASSWORD
105+
WORDPRESS_DB_NAME
106+
WORDPRESS_DB_CHARSET
107+
WORDPRESS_DB_COLLATE
108+
"${uniqueEnvs[@]/#/WORDPRESS_}"
109+
WORDPRESS_TABLE_PREFIX
110+
WORDPRESS_DEBUG
111+
WORDPRESS_CONFIG_EXTRA
112+
)
113+
haveConfig=
114+
for e in "${envs[@]}"; do
115+
file_env "$e"
116+
if [ -z "$haveConfig" ] && [ -n "${!e}" ]; then
117+
haveConfig=1
118+
fi
119+
done
120+
121+
# linking backwards-compatibility
122+
if [ -n "${!MYSQL_ENV_MYSQL_*}" ]; then
123+
haveConfig=1
124+
# host defaults to "mysql" below if unspecified
125+
: "${WORDPRESS_DB_USER:=${MYSQL_ENV_MYSQL_USER:-root}}"
126+
if [ "$WORDPRESS_DB_USER" = 'root' ]; then
127+
: "${WORDPRESS_DB_PASSWORD:=${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}}"
128+
else
129+
: "${WORDPRESS_DB_PASSWORD:=${MYSQL_ENV_MYSQL_PASSWORD:-}}"
130+
fi
131+
: "${WORDPRESS_DB_NAME:=${MYSQL_ENV_MYSQL_DATABASE:-}}"
132+
fi
133+
134+
# only touch "wp-config.php" if we have environment-supplied configuration values
135+
if [ "$haveConfig" ]; then
136+
: "${WORDPRESS_DB_HOST:=mysql}"
137+
: "${WORDPRESS_DB_USER:=root}"
138+
: "${WORDPRESS_DB_PASSWORD:=}"
139+
: "${WORDPRESS_DB_NAME:=wordpress}"
140+
: "${WORDPRESS_DB_CHARSET:=utf8}"
141+
: "${WORDPRESS_DB_COLLATE:=}"
142+
143+
# version 4.4.1 decided to switch to windows line endings, that breaks our seds and awks
144+
# https://github.com/docker-library/wordpress/issues/116
145+
# https://github.com/WordPress/WordPress/commit/1acedc542fba2482bab88ec70d4bea4b997a92e4
146+
sed -ri -e 's/\r$//' wp-config*
147+
148+
if [ ! -e wp-config.php ]; then
149+
awk '
150+
/^\/\*.*stop editing.*\*\/$/ && c == 0 {
151+
c = 1
152+
system("cat")
153+
if (ENVIRON["WORDPRESS_CONFIG_EXTRA"]) {
154+
print "// WORDPRESS_CONFIG_EXTRA"
155+
print ENVIRON["WORDPRESS_CONFIG_EXTRA"] "\n"
156+
}
157+
}
158+
{ print }
159+
' wp-config-sample.php > wp-config.php <<'EOPHP'
160+
// If we're behind a proxy server and using HTTPS, we need to alert Wordpress of that fact
161+
// see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy
162+
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
163+
$_SERVER['HTTPS'] = 'on';
164+
}
165+
166+
EOPHP
167+
chown "$user:$group" wp-config.php
168+
elif [ -e wp-config.php ] && [ -n "$WORDPRESS_CONFIG_EXTRA" ] && [[ "$(< wp-config.php)" != *"$WORDPRESS_CONFIG_EXTRA"* ]]; then
169+
# (if the config file already contains the requested PHP code, don't print a warning)
170+
echo >&2
171+
echo >&2 'WARNING: environment variable "WORDPRESS_CONFIG_EXTRA" is set, but "wp-config.php" already exists'
172+
echo >&2 ' The contents of this variable will _not_ be inserted into the existing "wp-config.php" file.'
173+
echo >&2 ' (see https://github.com/docker-library/wordpress/issues/333 for more details)'
174+
echo >&2
175+
fi
176+
177+
# see http://stackoverflow.com/a/2705678/433558
178+
sed_escape_lhs() {
179+
echo "$@" | sed -e 's/[]\/$*.^|[]/\\&/g'
180+
}
181+
sed_escape_rhs() {
182+
echo "$@" | sed -e 's/[\/&]/\\&/g'
183+
}
184+
php_escape() {
185+
local escaped="$(php -r 'var_export(('"$2"') $argv[1]);' -- "$1")"
186+
if [ "$2" = 'string' ] && [ "${escaped:0:1}" = "'" ]; then
187+
escaped="${escaped//$'\n'/"' + \"\\n\" + '"}"
188+
fi
189+
echo "$escaped"
190+
}
191+
set_config() {
192+
key="$1"
193+
value="$2"
194+
var_type="${3:-string}"
195+
start="(['\"])$(sed_escape_lhs "$key")\2\s*,"
196+
end="\);"
197+
if [ "${key:0:1}" = '$' ]; then
198+
start="^(\s*)$(sed_escape_lhs "$key")\s*="
199+
end=";"
200+
fi
201+
sed -ri -e "s/($start\s*).*($end)$/\1$(sed_escape_rhs "$(php_escape "$value" "$var_type")")\3/" wp-config.php
202+
}
203+
204+
set_config 'DB_HOST' "$WORDPRESS_DB_HOST"
205+
set_config 'DB_USER' "$WORDPRESS_DB_USER"
206+
set_config 'DB_PASSWORD' "$WORDPRESS_DB_PASSWORD"
207+
set_config 'DB_NAME' "$WORDPRESS_DB_NAME"
208+
set_config 'DB_CHARSET' "$WORDPRESS_DB_CHARSET"
209+
set_config 'DB_COLLATE' "$WORDPRESS_DB_COLLATE"
210+
211+
for unique in "${uniqueEnvs[@]}"; do
212+
uniqVar="WORDPRESS_$unique"
213+
if [ -n "${!uniqVar}" ]; then
214+
set_config "$unique" "${!uniqVar}"
215+
else
216+
# if not specified, let's generate a random value
217+
currentVal="$(sed -rn -e "s/define\((([\'\"])$unique\2\s*,\s*)(['\"])(.*)\3\);/\4/p" wp-config.php)"
218+
if [ "$currentVal" = 'put your unique phrase here' ]; then
219+
set_config "$unique" "$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)"
220+
fi
221+
fi
222+
done
223+
224+
if [ "$WORDPRESS_TABLE_PREFIX" ]; then
225+
set_config '$table_prefix' "$WORDPRESS_TABLE_PREFIX"
226+
fi
227+
228+
if [ "$WORDPRESS_DEBUG" ]; then
229+
set_config 'WP_DEBUG' 1 boolean
230+
fi
231+
232+
TERM=dumb php -- <<'EOPHP'
233+
<?php
234+
// database might not exist, so let's try creating it (just to be safe)
235+
236+
$stderr = fopen('php://stderr', 'w');
237+
238+
// https://codex.wordpress.org/Editing_wp-config.php#MySQL_Alternate_Port
239+
// "hostname:port"
240+
// https://codex.wordpress.org/Editing_wp-config.php#MySQL_Sockets_or_Pipes
241+
// "hostname:unix-socket-path"
242+
list($host, $socket) = explode(':', getenv('WORDPRESS_DB_HOST'), 2);
243+
$port = 0;
244+
if (is_numeric($socket)) {
245+
$port = (int) $socket;
246+
$socket = null;
247+
}
248+
$user = getenv('WORDPRESS_DB_USER');
249+
$pass = getenv('WORDPRESS_DB_PASSWORD');
250+
$dbName = getenv('WORDPRESS_DB_NAME');
251+
252+
$maxTries = 10;
253+
do {
254+
$mysql = new mysqli($host, $user, $pass, '', $port, $socket);
255+
if ($mysql->connect_error) {
256+
fwrite($stderr, "\n" . 'MySQL Connection Error: (' . $mysql->connect_errno . ') ' . $mysql->connect_error . "\n");
257+
--$maxTries;
258+
if ($maxTries <= 0) {
259+
exit(1);
260+
}
261+
sleep(3);
262+
}
263+
} while ($mysql->connect_error);
264+
265+
if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($dbName) . '`')) {
266+
fwrite($stderr, "\n" . 'MySQL "CREATE DATABASE" Error: ' . $mysql->error . "\n");
267+
$mysql->close();
268+
exit(1);
269+
}
270+
271+
$mysql->close();
272+
EOPHP
273+
fi
274+
275+
# now that we're definitely done writing configuration, let's clear out the relevant envrionment variables (so that stray "phpinfo()" calls don't leak secrets from our code)
276+
for e in "${envs[@]}"; do
277+
unset "$e"
278+
done
279+
fi
280+
281+
exec "$@"

0 commit comments

Comments
 (0)