Skip to content

Commit 0e0d32d

Browse files
committed
Add docker
1 parent 5ab5926 commit 0e0d32d

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

.dockerignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Docker build context exclusions
2+
.git
3+
.gitignore
4+
.github
5+
.idea
6+
.vscode
7+
node_modules
8+
npm-debug.log
9+
yarn.lock
10+
composer.phar
11+
var/cache
12+
var/logs
13+
var/sessions
14+
.env
15+
Dockerfile*
16+
docker-compose*.yml
17+
**/.DS_Store
18+
**/Thumbs.db
19+
vendor/

Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Build a production image for phpList base-distribution (Symfony-based)
4+
FROM php:8.1-apache-bullseye
5+
6+
# Set workdir
7+
WORKDIR /var/www/html
8+
9+
# Install system dependencies and PHP extensions
10+
RUN apt-get update \
11+
&& apt-get install -y --no-install-recommends \
12+
git unzip libzip-dev libicu-dev libpng-dev libonig-dev libxml2-dev \
13+
libc-client2007e-dev libkrb5-dev libssl-dev \
14+
&& docker-php-ext-configure intl \
15+
&& docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
16+
&& docker-php-ext-install -j"$(nproc)" \
17+
pdo pdo_mysql zip intl imap \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# Enable Apache modules and set DocumentRoot to /public
21+
RUN a2enmod rewrite headers \
22+
&& sed -ri 's!/var/www/html!/var/www/html/public!g' /etc/apache2/sites-available/000-default.conf \
23+
&& sed -ri 's!/var/www/!/var/www/html/public!g' /etc/apache2/apache2.conf \
24+
&& echo "<Directory /var/www/html/public>\n AllowOverride All\n Require all granted\n</Directory>" > /etc/apache2/conf-available/phplist.conf \
25+
&& a2enconf phplist
26+
27+
# Copy composer definition first and install dependencies
28+
COPY composer.json composer.lock ./
29+
30+
# Install Composer
31+
ENV COMPOSER_ALLOW_SUPERUSER=1 \
32+
PATH="/usr/local/bin:${PATH}"
33+
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
34+
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
35+
&& rm composer-setup.php
36+
37+
# Ensure config directory exists for Composer scripts that write into it
38+
COPY config ./config
39+
40+
# Install PHP dependencies (include scripts so phpList creates config structure)
41+
RUN composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
42+
43+
# Copy the rest of the application (except files ignored by .dockerignore)
44+
COPY . .
45+
46+
# Ensure correct permissions for cache/logs
47+
RUN chown -R www-data:www-data var public \
48+
&& find var -type d -exec chmod 775 {} \; \
49+
&& find var -type f -exec chmod 664 {} \;
50+
51+
# Expose port and run Apache
52+
EXPOSE 80
53+
CMD ["apache2-foreground"]

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,31 @@ contribute and how to run the unit tests and style checks locally.
176176
This project adheres to a [Contributor Code of Conduct](CODE_OF_CONDUCT.md).
177177
By participating in this project and its community, you are expected to uphold
178178
this code.
179+
180+
181+
## Docker deployment
182+
183+
The project includes a Docker setup to run phpList with Apache and MySQL.
184+
185+
Quick start (development/test):
186+
187+
- Build and start the stack: `docker compose up --build`
188+
- Open http://localhost:8080
189+
190+
The app container is configured to read database settings from environment variables that match config/parameters.yml defaults. The provided docker-compose.yml sets:
191+
192+
- PHPLIST_DATABASE_HOST=db
193+
- PHPLIST_DATABASE_PORT=3306
194+
- PHPLIST_DATABASE_NAME=phplistdb
195+
- PHPLIST_DATABASE_USER=phplist
196+
- PHPLIST_DATABASE_PASSWORD=phplist
197+
198+
Notes:
199+
200+
- For production deployments, build and push the image, then run it behind a reverse proxy or load balancer. Example:
201+
- `docker build -t your-registry/phplist-base:latest .`
202+
- `docker run -p 8080:80 --env PHPLIST_DATABASE_HOST=... --env PHPLIST_DATABASE_NAME=... --env PHPLIST_DATABASE_USER=... --env PHPLIST_DATABASE_PASSWORD=... your-registry/phplist-base:latest`
203+
- Persist the MySQL data using the db_data volume defined in docker-compose.yml, or bind mount your own volume.
204+
- You can also mount ./var to persist logs/cache between restarts. See commented volume in docker-compose.yml.
205+
- The container uses Apache with DocumentRoot set to /var/www/html/public and mod_rewrite enabled.
206+
- The base image uses PHP 8.1 (php:8.1-apache-bullseye) to match the Composer constraint (^8.1) and to ensure the IMAP build dependencies are available. You can bump to a newer 8.x tag (e.g., 8.3) if your deployment prefers it, but ensure IMAP build deps are present for that base.

docker-compose.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: "3.9"
2+
3+
services:
4+
app:
5+
build: .
6+
image: phplist/base-distribution:latest
7+
ports:
8+
- "8080:80"
9+
environment:
10+
# Database connection (mirrors config/parameters.yml expectations)
11+
PHPLIST_DATABASE_DRIVER: pdo_mysql
12+
PHPLIST_DATABASE_HOST: db
13+
PHPLIST_DATABASE_PORT: 3306
14+
PHPLIST_DATABASE_NAME: phplistdb
15+
PHPLIST_DATABASE_USER: phplist
16+
PHPLIST_DATABASE_PASSWORD: phplist
17+
# Symfony environment
18+
APP_ENV: prod
19+
APP_DEBUG: "0"
20+
depends_on:
21+
- db
22+
# Uncomment to persist logs/cache outside container
23+
# volumes:
24+
# - ./var:/var/www/html/var
25+
26+
db:
27+
image: mysql:8.0
28+
environment:
29+
MYSQL_DATABASE: phplistdb
30+
MYSQL_USER: phplist
31+
MYSQL_PASSWORD: phplist
32+
MYSQL_ROOT_PASSWORD: root
33+
command: ["--default-authentication-plugin=mysql_native_password", "--innodb-buffer-pool-size=64M"]
34+
volumes:
35+
- db_data:/var/lib/mysql
36+
healthcheck:
37+
test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -u$$MYSQL_USER -p$$MYSQL_PASSWORD || exit 1"]
38+
interval: 10s
39+
timeout: 5s
40+
retries: 10
41+
42+
volumes:
43+
db_data:

0 commit comments

Comments
 (0)