diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e96cc4e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +mysql + 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/Dockerfile b/apache/Dockerfile index e4266b3..94f93e4 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) +LABEL authors="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 \ diff --git a/apache/docker-entrypoint.sh b/apache/docker-entrypoint.sh index 6007d11..1eef2f1 100755 --- a/apache/docker-entrypoint.sh +++ b/apache/docker-entrypoint.sh @@ -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 @@ -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'} @@ -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'