Skip to content

Commit 662b82d

Browse files
committed
Drop custom user/group and document root, change permissions on runtime
1 parent b1e2062 commit 662b82d

File tree

6 files changed

+52
-47
lines changed

6 files changed

+52
-47
lines changed

Dockerfile

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,15 @@ RUN set -ex; \
4949
|| gpg --keyserver pgp.mit.edu --recv-keys "$GPGKEY" \
5050
|| gpg --keyserver keyserver.pgp.com --recv-keys "$GPGKEY"; \
5151
gpg --batch --verify phpMyAdmin.tar.xz.asc phpMyAdmin.tar.xz; \
52-
tar -xf phpMyAdmin.tar.xz; \
52+
tar -xf phpMyAdmin.tar.xz -C /usr/src; \
5353
gpgconf --kill all; \
5454
rm -r "$GNUPGHOME" phpMyAdmin.tar.xz phpMyAdmin.tar.xz.asc; \
55-
mv phpMyAdmin-$VERSION-all-languages /www; \
56-
rm -rf /www/setup/ /www/examples/ /www/test/ /www/po/ /www/composer.json /www/RELEASE-DATE-$VERSION; \
57-
sed -i "s@define('CONFIG_DIR'.*@define('CONFIG_DIR', '/etc/phpmyadmin/');@" /www/libraries/vendor_config.php; \
58-
chown -R nobody:nogroup /www; \
59-
find /www -type d -exec chmod 750 {} \; ; \
60-
find /www -type f -exec chmod 640 {} \; ; \
55+
mv /usr/src/phpMyAdmin-$VERSION-all-languages /usr/src/phpmyadmin; \
56+
rm -rf /usr/src/phpmyadmin/setup/ /usr/src/phpmyadmin/examples/ /usr/src/phpmyadmin/test/ /usr/src/phpmyadmin/po/ /usr/src/phpmyadmin/composer.json /usr/src/phpmyadmin/RELEASE-DATE-$VERSION; \
57+
sed -i "s@define('CONFIG_DIR'.*@define('CONFIG_DIR', '/etc/phpmyadmin/');@" /usr/src/phpmyadmin/libraries/vendor_config.php; \
6158
# Add directory for sessions to allow session persistence
6259
mkdir /sessions; \
63-
mkdir -p /www/tmp; \
64-
chmod -R 777 /www/tmp; \
60+
mkdir -p /var/nginx/client_body_temp; \
6561
apk del .fetch-deps
6662

6763
# Copy configuration
@@ -75,4 +71,4 @@ COPY run.sh /run.sh
7571
EXPOSE 80
7672

7773
ENTRYPOINT [ "/run.sh" ]
78-
CMD ["supervisord", "-n"]
74+
CMD ["supervisord", "-n", "-j", "/supervisord.pid"]

etc/nginx.conf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
user nobody nogroup;
21
worker_processes 4;
32

43
daemon off;
@@ -53,7 +52,7 @@ http {
5352
listen 80 default_server;
5453
server_name _;
5554

56-
root /www;
55+
root /var/www/html;
5756

5857
index index.php index.html index.htm;
5958

@@ -73,7 +72,7 @@ http {
7372

7473
location ~ \.php$ {
7574
fastcgi_intercept_errors on;
76-
fastcgi_pass unix:/var/run/php/php-fpm.sock;
75+
fastcgi_pass 127.0.0.1:9000;
7776

7877
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
7978
fastcgi_split_path_info ^(.+\.php)(/.+)$;

etc/php-fpm.conf

Lines changed: 0 additions & 17 deletions
This file was deleted.

etc/supervisor.d/php.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[program:php-fpm]
2-
command=php-fpm --nodaemonize --fpm-config /etc/php-fpm.conf
3-
user=nobody
2+
command=php-fpm --nodaemonize --fpm-config /usr/local/etc/php-fpm.conf
43
autostart=true
54
autorestart=true
65
priority=1

php.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
allow_url_fopen = Off
33
max_execution_time = 600
44
memory_limit = 512M
5-
open_basedir = /www/:/tmp/:/etc/phpmyadmin/
5+
open_basedir = /var/www/html:/tmp/:/etc/phpmyadmin/
66
post_max_size = 512M
77
upload_max_filesize = 512M
88

run.sh

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,50 @@
11
#!/bin/sh
2-
if [ ! -f /etc/phpmyadmin/config.secret.inc.php ]; then
3-
cat > /etc/phpmyadmin/config.secret.inc.php <<EOT
2+
if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ] || [ "$1" == supervisord ] ; then
3+
if [ "$(id -u)" = '0' ]; then
4+
case "$1" in
5+
apache2*)
6+
user="${APACHE_RUN_USER:-www-data}"
7+
group="${APACHE_RUN_GROUP:-www-data}"
8+
;;
9+
*) # php-fpm
10+
user='www-data'
11+
group='www-data'
12+
;;
13+
esac
14+
else
15+
user="$(id -u)"
16+
group="$(id -g)"
17+
fi
18+
19+
chown www-data:www-data /sessions /var/nginx/client_body_temp
20+
21+
if ! [ -e index.php -a -e db_designer.php ]; then
22+
echo >&2 "phpMyAdmin not found in $PWD - copying now..."
23+
if [ "$(ls -A)" ]; then
24+
echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!"
25+
( set -x; ls -A; sleep 10 )
26+
fi
27+
tar --create \
28+
--file - \
29+
--one-file-system \
30+
--directory /usr/src/phpmyadmin \
31+
--owner "$user" --group "$group" \
32+
. | tar --extract --file -
33+
echo >&2 "Complete! phpMyAdmin has been successfully copied to $PWD"
34+
mkdir -p tmp; \
35+
chmod -R 777 tmp; \
36+
fi
37+
38+
if [ ! -f /etc/phpmyadmin/config.secret.inc.php ]; then
39+
cat > /etc/phpmyadmin/config.secret.inc.php <<EOT
440
<?php
541
\$cfg['blowfish_secret'] = '$(tr -dc 'a-zA-Z0-9~!@#$%^&*_()+}{?></";.,[]=-' < /dev/urandom | fold -w 32 | head -n 1)';
642
EOT
7-
fi
43+
fi
844

9-
if [ ! -f /etc/phpmyadmin/config.user.inc.php ]; then
10-
touch /etc/phpmyadmin/config.user.inc.php
45+
if [ ! -f /etc/phpmyadmin/config.user.inc.php ]; then
46+
touch /etc/phpmyadmin/config.user.inc.php
47+
fi
1148
fi
1249

13-
mkdir -p /var/nginx/client_body_temp
14-
chown nobody:nogroup /sessions /var/nginx/client_body_temp
15-
mkdir -p /var/run/php/
16-
chown nobody:nogroup /var/run/php/
17-
touch /var/log/php-fpm.log
18-
chown nobody:nogroup /var/log/php-fpm.log
19-
20-
chmod 644 /etc/phpmyadmin/*
21-
2250
exec "$@"

0 commit comments

Comments
 (0)