Publish Official Docker Containers

twaxter

New member
Hello,

Based on documentation and various forum posts I've read, it seems very difficult (I've been trying past few days) to get Xenforo running with docker in a production environment.

The approaches I've seen is mounting the xenforo code base via a container inside a php container, but this is not good practice.
When using something like docker, the code base is supposed to be copied into the image - so when you make changes to it (install an add-on, update the xenforo version), you can test in lower environments, create a distinct tag for the image, and then deploy it in your production environments. You store any sort of state in a database that runs independently. This means that if perhaps you need to horizontally scale, you can do so quite easily, just increase the number of web containers + increase replicas of your db + upgrade your redis etc.

Upgrades should not be done in a live environment through a web GUI, and you should be able to start up the xenforo service with just a container + some secrets or environmental variables.

I understand that this is very difficult to support given that xenforo is built around running on a single VPS and using a GUI. So I'm just asking for some help on getting this to work. I do think that is a valuable addition to xenforo, cause you'd get customers to deploy this to cloud infrastructure quite easily.

Ideally, what I'd like to do is:

1. Download the Zip File
2. Copy the contents + any add-ons I installed into a docker container (that has a NGINX OR Apache + PHP dependencies), that I push to a private repository
3. Set up some environmental variables and secrets
  • Database Credentials
  • License Key Secret etc
  • Redis Credentials
  • Add-ON settings
4. The application can start up fresh and just work with whatever I've installed (and mounted into the actual container)

Here is what I've got to so far:
# Use the official PHP 8.1 image with Apache
FROM php:8.1-apache
# Install necessary PHP extensions
RUN apt-get update && apt-get install -y \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libonig-dev \
libzip-dev \
zip \
unzip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install gd mysqli pdo pdo_mysql zip exif
# Enable Apache mod_rewrite
RUN a2enmod rewrite
# Copy custom PHP configuration
COPY php.ini /usr/local/etc/php/
# Set working directory
WORKDIR /var/www/html
My Docker-compose:
services:
web:
image: php:8.1-apache
container_name: xenforo_web
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:80"
volumes:
- ./xenforo:/var/www/html
- ./config.php:/var/www/html/src/config.php
depends_on:
- db
environment:
- APACHE_DOCUMENT_ROOT=/var/www/html
restart: always
db:
image: mysql:8.0
container_name: xenforo_db
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: xenforo
MYSQL_USER: xenforo_user
MYSQL_PASSWORD: password
volumes:
- ./.db_volume:/var/lib/mysql
restart: always

This works locally, however, I need to always do localhost:8080/install...

I mount the code base, and copy my config.php (which has database credentials in it)
- ./xenforo:/var/www/html
- ./config.php:/var/www/html/src/config.php

I was trying to create a docker file that has the code base built in (it copies your zip file + config.php), but it appears that the code base is writing to an internal_data folder in /var/www/html. I think I could use some start up scripts (use the xenforo cli) that need to be run I think, that would help in installing add-ons or initializing the forum (kinda what /install)

I am a noob when it comes to apache/nginx/php configurations btw. I got lucky getting everything to work in that apache container.

So yeah, looking for help in this approach. I will comment on his if I make any progress so it could potentially help others.
 
Getting Closer:

my config.php:
<?php
$config['db']['host'] = getenv('DATABASE_HOSTNAME');
$config['db']['port'] = getenv('MYSQL_PORT');
$config['db']['username'] = getenv('MYSQL_USER');
$config['db']['password'] = getenv('MYSQL_PASSWORD');
$config['db']['dbname'] = getenv('MYSQL_DATABASE');
$config['fullUnicode'] = true;

docker-compose yaml
version: "3.8"
services:
web:
image: php:8.1-apache
container_name: xenforo_web
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:80"
environment:
DATABASE_HOSTNAME: db
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: xenforo
MYSQL_USER: xenforo_user
MYSQL_PASSWORD: password
MYSQL_PORT: 3306
APACHE_DOCUMENT_ROOT: /var/www/html
entrypoint: php /var/www/html/cmd.php -n xf:install --user=admin --password=admin --skip-statistics --clear
depends_on:
- db
volumes:
- ./xenforo/data:/var/www/html/data
- ./xenforo/internal_data:/var/www/html/internal_data
restart: always
db:
image: mysql:8.0
container_name: xenforo_db
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: xenforo
MYSQL_USER: xenforo_user
MYSQL_PASSWORD: password
volumes:
- ./.db_volume:/var/lib/mysql
restart: always

Dockerfile
FROM busybox AS unpack
WORKDIR /unpack
# Copy and Unpack XenForo Zip
COPY xenforo/xenforo.zip /
RUN unzip -o /xenforo.zip
# Use the official PHP 8.1 image with Apache
FROM php:8.1-apache
COPY --from=unpack /unpack/upload /var/www/html
# Install necessary PHP extensions
RUN apt-get update && apt-get install -y \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libonig-dev \
libzip-dev \
zip \
unzip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install gd mysqli pdo pdo_mysql zip exif
# Enable Apache mod_rewrite
RUN a2enmod rewrite
# Copy custom PHP configuration
COPY php.ini /usr/local/etc/php/
COPY config.php /var/www/html/src/config.php
# Set permissions for the application
RUN chown -R www-data:www-data /var/www/html/src/config.php
RUN chmod 644 /var/www/html/src/config.php
# Set working directory
WORKDIR /var/www/html

I'm able to use localhost/install with fresh volumes and it works, but anytime I try to use this command, which is the entrypoint I get this. I have deleted the install-lock.php file. I do a fresh install, see the output. And this happens
php /var/www/html/cmd.php -n xf:install --user=admin --password=admin --skip-statistics --clear

# After running installation, I get this:
xenforo_web | You have already completed installation. If you wish to reinstall, please delete the file internal_data/install-lock.php.

I think install forces the server to restart, and then the entrypoint runs again. I think if I check to see if it's installed already, should be ok.

xenforo_web | All finished. Installation has been completed.
xenforo_web |
xenforo_web | Values set:
xenforo_web | * Username: admin
xenforo_web | * Email: example@example.com
xenforo_web | * Password: ***** (Confirmed)
xenforo_web | * Title: XenForo
xenforo_web | * URL: http://localhost
xenforo_web |
xenforo_web | Running clean up tasks...
xenforo_web | 28/28 [============================] 100%
xenforo_web exited with code 0
xenforo_web | You have already completed installation. If you wish to reinstall, please delete the file internal_data/install-lock.php.
xenforo_web exited with code 1
 
Last edited:
Additional Progress:

  • Added entrypoint so that it will check to see if Xenforo is already installed, if it is, don't run the installer else Run it. The installer does indeed restart the server so the entrypoint should not just blindly run install.
  • I feel like I could just mount the volumes in production for data and internal data... but Idk
  • I had to add a healthcheck to the database since the installer would launch too quickly in the web container (would complain db not found), working now.
  • I am a bit confused about how it's going to work in a k8s environment.
  • Going to go ahead and install add-ons now, and see how it works with this.

DockerFile:
FROM busybox AS unpack
WORKDIR /unpack
# Copy and Unpack XenForo Zip
COPY xenforo/xenforo.zip /
RUN unzip -o /xenforo.zip
# Use the official PHP 8.1 image with Apache
FROM php:8.1-apache
COPY --from=unpack /unpack/upload /var/www/html
# Install necessary PHP extensions
RUN apt-get update && apt-get install -y \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libonig-dev \
libzip-dev \
zip \
unzip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install gd mysqli pdo pdo_mysql zip exif
# Enable Apache mod_rewrite
RUN a2enmod rewrite
# Copy custom PHP configuration
COPY php.ini /usr/local/etc/php/
COPY config.php /var/www/html/src/config.php
# Set permissions for the application
RUN chown -R www-data:www-data /var/www/html
RUN chmod 644 /var/www/html/src/config.php
# Set working directory
WORKDIR /var/www/html

Entrypoint
#!/bin/bash
set -x # Debugging: Trace commands
INSTALL_LOCK_FILE="/var/www/html/internal_data/install-lock.php"
ls -la /var/www/html # Debug: Check if files exist
if [ -f "$INSTALL_LOCK_FILE" ]; then
echo "XenForo is already installed. Skipping installation."
else
echo "XenForo is not installed. Running installation..."
php /var/www/html/cmd.php -n xf:install --user=admin --password=admin --skip-statistics --clear
fi
apache2-foreground

Docker-compose
version: "3.8"
services:
web:
image: php:8.1-apache
container_name: xenforo_web
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:80"
environment:
DATABASE_HOSTNAME: db
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: xenforo
MYSQL_USER: xenforo_user
MYSQL_PASSWORD: password
MYSQL_PORT: 3306
APACHE_DOCUMENT_ROOT: /var/www/html
entrypoint: /var/www/html/xenforo-entrypoint.sh
depends_on:
db:
condition: service_healthy
volumes:
- ./xenforo/data:/var/www/html/data
- ./xenforo/internal_data:/var/www/html/internal_data
- ./xenforo-entrypoint.sh:/var/www/html/xenforo-entrypoint.sh
restart: always
db:
image: mysql:8.0
container_name: xenforo_db
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: xenforo
MYSQL_USER: xenforo_user
MYSQL_PASSWORD: password
volumes:
- ./.db_volume:/var/lib/mysql
restart: always
healthcheck:
test: ["CMD-SHELL", "mysqladmin status -u$$MYSQL_USER -p$$MYSQL_PASSWORD --protocol=TCP"]
interval: 10s
timeout: 10s
retries: 5
 
Last edited:
Back
Top Bottom