I noticed this has been asked a few times, so here it goes.
First, do a clean install of flarum/flarum
in a directory where you start developing. Create a workbench if you want to build your own extensions (see https://discuss.flarum.org/d/1608-extension-development-using-composer-repositories-path).
Now create a directory build/docker/config
with directories apache
and php
.
build/docker/config/apache/000-default.conf
# Remove apache version strings from response headers
ServerSignature Off
ServerTokens Prod
<VirtualHost *:8080>
#ServerName www.example.com
#ServerAdmin webmaster@localhost
DocumentRoot /var/www/public
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log enhanced
RewriteMap lowercase int:tolower
RewriteEngine on
</VirtualHost>
build/docker/config/php/startup-apache-dev.sh
#!/bin/bash
# Workaround for permissions issues running the docker images on Ubuntu
usermod -u 1000 www-data
cd /var/www
if [[ -f "config.php" ]]; then
php flarum migrate
php flarum cache:clear
php flarum assets:publish
else
php flarum install -f install.yml
fi
# Reset permissions
chown -R www-data:www-data /var/www/storage/ && chmod -R g+w /var/www/storage/ && chmod -R 755 /var/www/storage/
# Start apache
apache2-foreground
Create an install.yml
in your flarum root:
baseUrl: http://localhost:8001
debug: true
databaseConfiguration:
host: flarumdb
username: flarum
password: flarum
database: flarum
adminUser:
username: admin
password: password
email: admin@flarum.local
Now also add a Dockerfile
in the root of your install:
FROM islamicnetwork/php:8.1-apache-dev
RUN rm /usr/local/etc/php/conf.d/docker-php-ext-memcached.ini
RUN rm /usr/local/etc/php/conf.d/docker-php-ext-rdkafka.ini
RUN rm /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
RUN rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
COPY ./build/docker/config/php/startup-apache-dev.sh /usr/local/bin/startup
COPY ./build/docker/config/apache/000-default.conf /etc/apache2/sites-available/000-default.conf
WORKDIR /var/www
RUN rm -rf /var/www/html
COPY . /var/www/
RUN chown -R www-data:www-data /var/www \
&& chmod -R ug+rwX /var/www
RUN chmod 775 /usr/local/bin/startup
CMD ["startup"]
Please note I am using the islamicnetwork image because it has been very reliable for me.
Now also create a docker-compose.yml
in your root:
version: '3.9'
services:
#######################################
# PHP Apache Docker container
#######################################
flarum.test:
build:
context: .
dockerfile: Dockerfile
ports:
- "80:8080"
- "6001:6001"
deploy:
replicas: 1
resources:
limits:
memory: 2G
reservations:
memory: 200M
volumes:
- ${PWD}/config.php:/var/www/config.php:delegated
- ${PWD}/extend.php:/var/www/extend.php:delegated
- ${PWD}/install.yml:/var/www/install.yml:delegated
- ${PWD}/site.php:/var/www/site.php:delegated
# uncomment if you have some local code that you want to be able to run/modify
# - ${PWD}/app:/var/www/app:delegated
- ${PWD}/public:/var/www/public:delegated
- ${PWD}/resources:/var/www/resources:delegated
- ${PWD}/storage/xdebug:/var/www/storage/xdebug:delegated
- ${PWD}/vendor:/var/www/vendor:delegated
# uncomment the following line if you develop on Flarum
# - ${PWD}/framework:/var/www/framework:delegated
# uncomment the following line if you develop on extensions in workbench
# - ${PWD}/workbench:/var/www/workbench:delegated
privileged: true
environment:
APP_ENV: "local"
URL: http://flarum.test
DB_HOST: flarumdb
DB_DATABASE: flarum
DB_USERNAME: flarum
DB_PASSWORD: flarum
DB_SSLMODE: "false"
DEBUG: "true"
REDIS_HOST: redis
REDIS_PASSWORD: test_pass
REDIS_CACHE_HOST: redis
REDIS_CACHE_PASSWORD: test_pass
#######################################
# MySQL server
#######################################
flarum-db:
image: mariadb:10
command: --default-authentication-plugin=mysql_native_password
environment:
MARIADB_USER: flarum
MARIADB_PASSWORD: flarum
MARIADB_DATABASE: flarum
MARIADB_ROOT_PASSWORD: root
volumes:
- database:/var/lib/mysql:delegated
ports:
- "127.0.0.1:3306:3306"
container_name: flarumdb
#######################################
# PHPMyAdmin
#######################################
flarum-pma:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOSTS: "flarumdb"
PMA_VERBOSES: "Flarum Database"
ports:
- "127.0.0.1:8002:80"
depends_on:
- flarum-db
restart: on-failure
container_name: flarumpma
#######################################
# Redis
#######################################
redis:
image: bitnami/redis:6.2
container_name: redis
environment:
- REDIS_PASSWORD=test_pass
ports:
- '127.0.0.1:6379:6379'
#######################################
# Redis admin
#######################################
redisadmin:
image: erikdubbelboer/phpredisadmin
container_name: redis-admin
ports:
- "127.0.0.1:8003:80"
depends_on:
- redis
environment:
REDIS_1_HOST: redis
REDIS_1_AUTH: test_pass
REDIS_1_NAME: LocalRedis
volumes:
database:
redis:
This is quite a lot, you will now have a database, phpmyadmin, redis and redis administration panel. You can boot up your flarum install using:
docker-compose up -d
Read the docker-compose documentation for further help.