Recently, I sought an easy method to deploy phpBB within a Docker container. After a quick search on the phpBB forums, I found many discussions related to Docker, but none of the solutions seemed to work. This presented a great opportunity to document my experience and share a step-by-step guide for successfully running phpBB with Docker.
Prerequisites
Before getting started, ensure you have the following:
- Docker Desktop installed on your machine.
- The latest phpBB package downloaded from phpBB
Setting Up phpBB with Docker
Follow these steps to deploy phpBB with Docker:
1. Create the Project Directory
Start by creating a directory for your local phpBB installation. For example, you can name it testphpbb. Inside this directory, you will create the necessary Docker configuration files.
2. Create the docker-compose.yaml File
Next, create a docker-compose.yaml file in the testphpbb directory. This file will define the PHP, Apache, and MySQL services required to run phpBB.
First, declare a custom network for the services and a volume to persist MySQL data. Here’s the basic structure of the docker-compose.yaml:
version: '3.7'
networks:
phpbb_network:
driver: bridge
volumes:
mysql-data:
services:
database:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: phpbb
MYSQL_DATABASE: phpbb
ports:
- 3306:3306
volumes:
- mysql-data:/var/lib/mysql
container_name: database
networks:
- phpbb_network
php:
build:
context: docker/php
container_name: php
ports:
- 80:80
volumes:
- ./phpbb/:/var/www/html/
depends_on:
database:
condition: service_started
networks:
- phpbb_network3. Define the MySQL Service
We use the official MySQL Docker image from Docker Hub for the database. In the database service:
- MYSQL_ROOT_PASSWORD defines the root password for MySQL.
- MYSQL_DATABASE creates a database named
phpbb. - The volumes directive ensures that MySQL data persists even after the container is stopped or removed.
4. Configure PHP and Apache
For the php service, the php:<version>-apache image is used. This image includes Apache HTTP Server and PHP, with mod_php enabled by default. However, we need to ensure that the php-mysql extension is installed for database connectivity.
To do this, we will create a custom Dockerfile.
5. Create a Custom Dockerfile
Inside the docker directory (create it if it doesn’t exist), add a Dockerfile with the following content:
FROM php:8.2-apache
RUN a2enmod rewrite
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli && docker-php-ext-install pdo_mysql
RUN apt-get update && apt-get upgrade -yThis will install the mysqli extension, allowing PHP to communicate with MySQL.
6. Download and Configure phpBB
Now, you’ll need to download and extract the latest phpBB package. Create a new directory called phpbb inside your project folder and place the extracted phpBB files there.
7. Bringing It All Together
Your directory structure should now look like this:
testphpbb/
├── docker/
│ └── Dockerfile
├── phpbb/
│ └── (phpBB files)
└── docker-compose.yaml8. Start the Containers
Finally, you are ready to bring up the containers. From the testphpbb directory, run the following command:
docker compose upDocker will pull the necessary images, build the PHP container with Apache, and start the MySQL database. After a few moments, your phpBB installation will be accessible at http://localhost.
By following these steps, you’ll have phpBB running in Docker, with PHP, Apache, and MySQL configured and ready for use. Enjoy managing your forum with ease!