From 6cd6af0efd7de6b0637bdc5f643e64b1b2c0a25c Mon Sep 17 00:00:00 2001 From: imtiazShakil Date: Wed, 5 Jun 2024 16:20:10 +0600 Subject: [PATCH 1/5] apache dockerfile updated with modx 3.0.5 and latest php8.3 --- apache/Dockerfile | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/apache/Dockerfile b/apache/Dockerfile index e4266b3..2e54796 100644 --- a/apache/Dockerfile +++ b/apache/Dockerfile @@ -1,13 +1,18 @@ -FROM php:7.1-apache +FROM php:8.3-apache MAINTAINER Vadim Homchik (@vh) RUN a2enmod rewrite +RUN apt-get update && apt-get install -y unzip # install the PHP extensions we need -RUN apt-get update && apt-get install -y libpng-dev libjpeg-dev unzip sudo && rm -rf /var/lib/apt/lists/* \ - && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \ - && docker-php-ext-install gd opcache mysqli pdo pdo_mysql + +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN install-php-extensions gd zip pdo_mysql opcache mysqli + +# Use the default production configuration +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" # set recommended PHP.ini settings # see https://secure.php.net/manual/en/opcache.installation.php @@ -15,19 +20,15 @@ RUN { \ echo 'opcache.memory_consumption=128'; \ echo 'opcache.interned_strings_buffer=8'; \ echo 'opcache.max_accelerated_files=4000'; \ - echo 'opcache.fast_shutdown=1'; \ + echo 'opcache.revalidate_freq=60'; \ echo 'opcache.enable_cli=1'; \ } > /usr/local/etc/php/conf.d/opcache-recommended.ini -# set timezone -RUN { \ - echo 'date.timezone=GMT+0'; \ - } > /usr/local/etc/php/conf.d/datetime.ini VOLUME /var/www/html -ENV MODX_VERSION 2.7.0 -ENV MODX_SHA1 79f7399b6cb2a7508852f2e82821a0d5670ef41f +ENV MODX_VERSION 3.0.5 +ENV MODX_SHA1 c8abde97ab72be7472549270e9af65d9d959062e # upstream tarballs include ./modx-${MODX_VERSION}/ RUN curl -o modx.zip -SL http://modx.com/download/direct/modx-${MODX_VERSION}-pl.zip \ From 31ccda73e64de8fa13a810d3338bc3b803cd5547 Mon Sep 17 00:00:00 2001 From: imtiazShakil Date: Wed, 5 Jun 2024 16:20:37 +0600 Subject: [PATCH 2/5] mysql folder added into gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e96cc4e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +mysql + From 5bd2b523e11ea15d16cc3511e8d2285fe34995e8 Mon Sep 17 00:00:00 2001 From: imtiazShakil Date: Wed, 5 Jun 2024 18:15:25 +0600 Subject: [PATCH 3/5] mysql connection fails in the bash script but works normally added try/catch so the script continues to deploy modx --- apache/docker-entrypoint.sh | 40 ++++++++++++++++++++----------------- docker-compose.yml | 5 ++--- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/apache/docker-entrypoint.sh b/apache/docker-entrypoint.sh index 6007d11..efa44f4 100755 --- a/apache/docker-entrypoint.sh +++ b/apache/docker-entrypoint.sh @@ -41,28 +41,32 @@ $stderr = fopen('php://stderr', 'w'); list($host, $port) = explode(':', $argv[1], 2); -$maxTries = 10; -do { - $mysql = new mysqli($host, $argv[2], $argv[3], '', (int)$port); - if ($mysql->connect_error) { - fwrite($stderr, "\n" . 'MySQL Connection Error: (' . $mysql->connect_errno . ') ' . $mysql->connect_error . "\n"); - --$maxTries; - if ($maxTries <= 0) { - exit(1); +try { + $maxTries = 10; + do { + $mysql = new mysqli($host, $argv[2], $argv[3], '', (int)$port); + if ($mysql->connect_error) { + fwrite($stderr, "\n" . 'MySQL Connection Error: (' . $mysql->connect_errno . ') ' . $mysql->connect_error . "\n"); + --$maxTries; + if ($maxTries <= 0) { + exit(1); + } + sleep(3); } - sleep(3); - } -} while ($mysql->connect_error); + } while ($mysql->connect_error); -if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($argv[4]) . '` ' . - 'DEFAULT CHARACTER SET = \'utf8\' DEFAULT COLLATE \'utf8_general_ci\'')) { + if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($argv[4]) . '` ' . + 'DEFAULT CHARACTER SET = \'utf8\' DEFAULT COLLATE \'utf8_general_ci\'')) { + + fwrite($stderr, "\n" . 'MySQL "CREATE DATABASE" Error: ' . $mysql->error . "\n"); + $mysql->close(); + exit(1); + } - fwrite($stderr, "\n" . 'MySQL "CREATE DATABASE" Error: ' . $mysql->error . "\n"); $mysql->close(); - exit(1); +} catch(Exception $e) { + fwrite($stderr, "\n".$e->getMessage()."\n".$e->getTraceAsString() ); } - -$mysql->close(); EOPHP if ! [ -e index.php -a -e core/config/config.inc.php ]; then @@ -116,7 +120,7 @@ EOPHP EOF chown www-data:www-data setup/config.xml - sudo -u www-data php setup/index.php --installmode=new + runuser -u www-data -- php setup/index.php --installmode=new else UPGRADE=$(TERM=dumb php -- "$MODX_VERSION" <<'EOPHP' Date: Wed, 5 Jun 2024 20:13:24 +0600 Subject: [PATCH 4/5] readme updated --- README.md | 19 +++++++++++++++++++ apache/docker-entrypoint.sh | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0578b50..649bdaa 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,22 @@ docker-compose up -d 2. Copy MODX code into `html` folder 3. Visit [localhost:8000](http://localhost:8000) + + +## Run modx only +If you have mysql setup externally and you want to run modx and connect to the external MySQL, follow steps below: + +1. build modx +```sh +docker build -t modx_apache ./apache +``` +2. Copy MODX code into `html` folder + +3. Run `modx_apache` image assuming MySQL installed locally +```sh +docker run -d --network=host --volume "$(pwd)/html:/var/www/html" -e MODX_DB_HOST=127.0.0.1:3306 \ +-e MODX_DB_PASSWORD=password \ +-e MODX_DB_USER=modx \ +-e MODX_DB_NAME=modx \ +--name modx_apache modx_apache +``` \ No newline at end of file diff --git a/apache/docker-entrypoint.sh b/apache/docker-entrypoint.sh index efa44f4..1ef310a 100755 --- a/apache/docker-entrypoint.sh +++ b/apache/docker-entrypoint.sh @@ -65,7 +65,8 @@ try { $mysql->close(); } catch(Exception $e) { - fwrite($stderr, "\n".$e->getMessage()."\n".$e->getTraceAsString() ); + fwrite($stderr, "\n"."Exception Occurred while connecting to MySQL, reason: ".$e->getMessage()); + fwrite($stderr, "\nStacktrace:\n".$e->getTraceAsString()."\n" ); } EOPHP From 330005b3240df7f081cff906bf97b757eb441241 Mon Sep 17 00:00:00 2001 From: imtiazShakil Date: Thu, 1 Aug 2024 20:24:36 +0600 Subject: [PATCH 5/5] fixed docker warnings related to LABEL & ENV --- apache/Dockerfile | 6 +++--- apache/docker-entrypoint.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apache/Dockerfile b/apache/Dockerfile index 2e54796..94f93e4 100644 --- a/apache/Dockerfile +++ b/apache/Dockerfile @@ -1,6 +1,6 @@ FROM php:8.3-apache -MAINTAINER Vadim Homchik (@vh) +LABEL authors="Vadim Homchik (@vh)" RUN a2enmod rewrite RUN apt-get update && apt-get install -y unzip @@ -27,8 +27,8 @@ RUN { \ VOLUME /var/www/html -ENV MODX_VERSION 3.0.5 -ENV MODX_SHA1 c8abde97ab72be7472549270e9af65d9d959062e +ENV MODX_VERSION=3.0.5 +ENV MODX_SHA1=c8abde97ab72be7472549270e9af65d9d959062e # upstream tarballs include ./modx-${MODX_VERSION}/ RUN curl -o modx.zip -SL http://modx.com/download/direct/modx-${MODX_VERSION}-pl.zip \ diff --git a/apache/docker-entrypoint.sh b/apache/docker-entrypoint.sh index 1ef310a..1eef2f1 100755 --- a/apache/docker-entrypoint.sh +++ b/apache/docker-entrypoint.sh @@ -80,7 +80,7 @@ EOPHP tar cf - --one-file-system -C /usr/src/modx . | tar xf - - echo >&2 "Complete! MODX has been successfully copied to $(pwd)" + echo >&2 "Complete! MODX has been successfully copied to $(pwd)" : ${MODX_ADMIN_USER:='admin'} : ${MODX_ADMIN_PASSWORD:='admin'} @@ -121,7 +121,7 @@ EOPHP EOF chown www-data:www-data setup/config.xml - runuser -u www-data -- php setup/index.php --installmode=new + runuser -u www-data -- php setup/index.php --installmode=new else UPGRADE=$(TERM=dumb php -- "$MODX_VERSION" <<'EOPHP'