From cfbabe306d67136e5b9f2d2593695b586971acae Mon Sep 17 00:00:00 2001
From: TonyFord <tonyford@strategy-investor.de>
Date: Thu, 4 Nov 2021 20:40:31 +0100
Subject: [PATCH] add php and pma service

---
 docker-compose.yml                  | 60 +++++++++++++++++++++++++++--
 services/php-server/Dockerfile      | 38 ++++++++++++++++++
 services/php-server/apache.conf     | 21 ++++++++++
 services/php-server/start_server.sh | 17 ++++++++
 4 files changed, 132 insertions(+), 4 deletions(-)
 create mode 100644 services/php-server/Dockerfile
 create mode 100644 services/php-server/apache.conf
 create mode 100644 services/php-server/start_server.sh

diff --git a/docker-compose.yml b/docker-compose.yml
index 78aae59..45b165c 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -5,12 +5,64 @@ services:
   jekyll:
     image: jekyll/jekyll:latest
     container_name: ultrasoccer-nationsleague-jekyll
-    command: jekyll serve
+    command: jekyll build --watch
     restart: always
-    ports:
-      - ${LH_PORT:-4990}:4000
+    #ports:
+    #  - ${LH_PORT:-4990}:4000
     environment:
       JEKYLL_UID: ${RUNNER_UID:-1000}
       JEKYLL_GID: ${RUNNER_GID:-1000}
     volumes:
-      - .:/srv/jekyll
+      - ./html:/srv/jekyll
+
+  php-server:
+    build:
+      context: ./services/php-server
+      args:
+        RUNNER_UID: ${RUNNER_UID:-1000}
+        RUNNER_GID: ${RUNNER_GID:-1000}
+    environment:
+      MYSQL_HOST: dbhost
+      MYSQL_PORT: 3306
+      MYSQL_DATABASE: ${MYSQL_DATABASE:-usnldb}
+      MYSQL_USER: ${MYSQL_USER:-user}
+      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-password}
+      AES_KEY: ${AES_KEY:-InSecureTestKey}
+    container_name: ultrasoccer-nationsleague-php
+    restart: always
+    command: /opt/start_server.sh
+    user: "${RUNNER_UID:-1000}:${RUNNER_GID:-1000}"
+    ports:
+      - ${LH_PORT:-4990}:80
+    depends_on:
+      - jekyll
+    volumes:
+      - ./html/_site:/var/www/html
+      - ./services/php-server/apache.conf:/etc/apache2/sites-available/000-default.conf
+
+  dbhost:
+    image: mariadb:latest
+    container_name: ultrasoccer-nationsleague-db
+    volumes:
+      - dbhost_data:/var/lib/mysql
+      #- ./stargate/functions/sql:/opt/sql
+    restart: always
+    environment:
+      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
+      MYSQL_DATABASE: ${MYSQL_DATABASE:-usnldb}
+      MYSQL_USER: ${MYSQL_USER:-user}
+      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-password}
+
+  phpmyadmin:
+    image: phpmyadmin/phpmyadmin
+    container_name: ultrasoccer-nationsleague-pma
+    environment:
+      PMA_HOST: dbhost
+      PMA_PORT: 3306
+      PMA_ARBITRARY: 1
+    restart: always
+    ports:
+      - ${LH_PORT_stargate_pma:-8081}:80
+
+volumes:
+    dbhost_data:
diff --git a/services/php-server/Dockerfile b/services/php-server/Dockerfile
new file mode 100644
index 0000000..f259e94
--- /dev/null
+++ b/services/php-server/Dockerfile
@@ -0,0 +1,38 @@
+# Pull base image.
+FROM php:7-apache
+
+ENV LC_ALL=C.UTF-8 LANG=C.UTF-8
+
+#####################################################################################root##
+### install base libraries and dependencies for faircoin daemon ###########################
+RUN apt-get update -q && \
+    apt-get install -qy \
+        wget \
+        curl
+
+#####################################################################################root##
+### install nano commandline editor [optional] ( to edit faircoin.conf later if necessary )
+RUN apt-get install -qy nano \
+        net-tools
+
+#####################################################################################root##
+### system cleanup ########################################################################
+RUN rm -rf /var/lib/apt/lists/* && \
+    apt-get autoremove -y && \
+    apt-get clean
+
+#####################################################################################root##
+### install php-mysql module ##############################################################
+RUN docker-php-ext-install mysqli
+
+#####################################################################################root##
+### create and run user account to image ##################################################
+ARG RUNNER_GID
+ARG RUNNER_UID
+RUN groupadd -g $RUNNER_GID user
+RUN useradd --create-home --shell /bin/bash user --uid $RUNNER_UID --gid $RUNNER_GID
+
+COPY ./start_server.sh /opt/start_server.sh
+RUN chmod +x /opt/start_server.sh
+
+USER user
diff --git a/services/php-server/apache.conf b/services/php-server/apache.conf
new file mode 100644
index 0000000..d3e194b
--- /dev/null
+++ b/services/php-server/apache.conf
@@ -0,0 +1,21 @@
+ServerName 0.0.0.0
+
+LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so
+LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
+LoadModule proxy_fcgi_module /usr/lib/apache2/modules/mod_proxy_fcgi.so
+
+<VirtualHost *:80>
+    # Proxy .php requests to port 9000 of the php-fpm container
+#    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/html/$1
+    DocumentRoot /var/www/html/
+    <Directory /var/www/html/>
+        DirectoryIndex index.php
+        Options Indexes FollowSymLinks
+        AllowOverride All
+        Require all granted
+    </Directory>
+
+    # Send apache logs to stdout and stderr
+    CustomLog /proc/self/fd/1 common
+    ErrorLog /proc/self/fd/2
+</VirtualHost>
diff --git a/services/php-server/start_server.sh b/services/php-server/start_server.sh
new file mode 100644
index 0000000..47c81c5
--- /dev/null
+++ b/services/php-server/start_server.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+## add envvars to server env
+echo "export APACHE_RUN_USER=user"                >> /etc/apache2/envvars
+echo "export APACHE_RUN_GROUP=user"               >> /etc/apache2/envvars
+echo "export MYSQL_HOST=${MYSQL_HOST}"                >> /etc/apache2/envvars
+echo "export MYSQL_PORT=${MYSQL_PORT}"                >> /etc/apache2/envvars
+echo "export MYSQL_USER=${MYSQL_USER}"                >> /etc/apache2/envvars
+echo "export MYSQL_PASSWORD=${MYSQL_PASSWORD}"        >> /etc/apache2/envvars
+echo "export MYSQL_DATABASE=${MYSQL_DATABASE}"        >> /etc/apache2/envvars
+echo "export AES_KEY=${AES_KEY}"                      >> /etc/apache2/envvars
+
+## start server
+/etc/init.d/apache2 restart
+
+## keep docker container open
+sleep inf
-- 
GitLab