Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mysql

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
25 changes: 13 additions & 12 deletions apache/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
FROM php:7.1-apache
FROM php:8.3-apache

MAINTAINER Vadim Homchik <homchik@gmail.com> (@vh)
LABEL authors="Vadim Homchik <homchik@gmail.com> (@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
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 \
Expand Down
43 changes: 24 additions & 19 deletions apache/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,33 @@ $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"."Exception Occurred while connecting to MySQL, reason: ".$e->getMessage());
fwrite($stderr, "\nStacktrace:\n".$e->getTraceAsString()."\n" );
}

$mysql->close();
EOPHP

if ! [ -e index.php -a -e core/config/config.inc.php ]; then
Expand All @@ -75,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'}
Expand Down Expand Up @@ -116,7 +121,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'
<?php
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
version: '3'
services:
web:
image: maki/modx
build: ./apache
links:
- 'db:mysql'
ports:
- '8000:80'
environment:
MODX_VERSION: 2.7.0
MODX_VERSION: 3.0.5
MODX_DB_HOST: 'mysql:3306'
MODX_DB_PASSWORD: modx
MODX_DB_USER: modx
Expand Down