Skip to content

Commit 189a221

Browse files
feat: Add FrankenPHP support with docker configuration and Caddyserver setup. (#105)
1 parent da6c355 commit 189a221

File tree

9 files changed

+207
-0
lines changed

9 files changed

+207
-0
lines changed

.github/workflows/docker.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,31 @@ jobs:
3838
- name: Run codeception tests.
3939
run: docker exec yii2-apache vendor/bin/codecept run
4040

41+
test-frankenphp:
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- name: Checkout.
46+
uses: actions/checkout@v4
47+
48+
- name: Install docker compose.
49+
run: |
50+
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
51+
sudo chmod +x /usr/local/bin/docker-compose
52+
docker-compose --version
53+
54+
- name: Build and start containers.
55+
run: docker-compose -f docker-compose.frankenphp.yml build --no-cache && docker-compose -f docker-compose.frankenphp.yml up -d
56+
57+
- name: Update vendor packages.
58+
run: docker exec yii2-frankenphp composer update --prefer-dist -vvv
59+
60+
- name: Codeception build.
61+
run: docker exec yii2-frankenphp vendor/bin/codecept build
62+
63+
- name: Run codeception build and tests.
64+
run: docker exec yii2-frankenphp vendor/bin/codecept run
65+
4166
test-nginx:
4267
runs-on: ubuntu-latest
4368

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ A modern, Bootstrap 5-powered Yii2 application template designed for rapid web-a
4343
## Environment support
4444

4545
[![Apache](https://img.shields.io/badge/apache-%23D42029.svg?style=for-the-badge&label=docker&logo=apache&logoColor=white)](docker-compose.yml)
46+
[![FrankenPHP](https://img.shields.io/badge/frankenphp-%23FF6B35.svg?style=for-the-badge&label=docker&logo=php&logoColor=white)](docker-compose.frankenphp.yml)
4647
[![Nginx](https://img.shields.io/badge/nginx-%23009639.svg?style=for-the-badge&label=docker&logo=nginx&logoColor=white)](docker-compose.nginx.yml)
4748

4849
## Quick start
@@ -100,6 +101,9 @@ php -S localhost:8080 -t public
100101
# For Apache
101102
docker-compose up -d
102103

104+
# For FrankenPHP
105+
docker-compose -f docker-compose.frankenphp.yml up -d
106+
103107
# For Nginx
104108
docker-compose -f docker-compose.nginx.yml up -d
105109
```
@@ -115,6 +119,9 @@ http://localhost:8080/
115119
# For Apache
116120
http://localhost:8080/
117121

122+
# For FrankenPHP
123+
http://localhost:8082/
124+
118125
# For Nginx
119126
http://localhost:8081/
120127
```
@@ -132,6 +139,7 @@ root/
132139
│ └── messages.php Translation config
133140
├── docker/ Docker configuration files
134141
│ ├── apache/ Apache configuration
142+
│ ├── frankenphp/ FrankenPHP configuration
135143
│ ├── nginx/ Nginx configuration
136144
│ └── php/ PHP configuration
137145
├── src/

docker-compose.frankenphp.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
services:
3+
yii2-frankenphp:
4+
build:
5+
dockerfile: docker/frankenphp/Dockerfile
6+
container_name: yii2-frankenphp
7+
restart: always
8+
working_dir: /app
9+
volumes:
10+
- ./:/app
11+
- ~/.composer-docker/cache:/root/.composer/cache:delegated
12+
- caddy_data:/data
13+
- caddy_config:/config
14+
ports:
15+
- '8082:80'
16+
- '8443:443'
17+
- '8443:443/udp'
18+
environment:
19+
TZ: "UTC"
20+
tty: true
21+
22+
# Volumes needed for Caddy certificates and configuration
23+
volumes:
24+
caddy_data:
25+
caddy_config:

docker/frankenphp/Caddyfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
# Global options
3+
auto_https off
4+
}
5+
6+
# Main server block
7+
:80 {
8+
# Document root
9+
root * /app/public
10+
11+
# Enable PHP processing with FrankenPHP
12+
php_server
13+
14+
# Security headers
15+
header {
16+
X-Frame-Options "SAMEORIGIN"
17+
X-XSS-Protection "1; mode=block"
18+
X-Content-Type-Options "nosniff"
19+
-Server
20+
}
21+
22+
# Logging
23+
log {
24+
output stdout
25+
format console
26+
}
27+
28+
# Handle static files
29+
@static {
30+
file
31+
path *.css *.js *.png *.jpg *.jpeg *.gif *.ico *.svg *.woff *.woff2 *.ttf *.eot
32+
}
33+
handle @static {
34+
header Cache-Control "public, max-age=31536000"
35+
file_server
36+
}
37+
38+
# Block access to sensitive directories
39+
@forbidden {
40+
path /.git/* /vendor/* /runtime/* /.env*
41+
}
42+
respond @forbidden 404
43+
44+
# Deny PHP execution in assets directory (Yii2 security)
45+
@assets_php {
46+
path /assets/*.php
47+
}
48+
respond @assets_php 403
49+
50+
# Try files for Yii2 URL rewriting
51+
try_files {path} {path}/ /index.php?{query}
52+
}

docker/frankenphp/Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM dunglas/frankenphp:1.8-php8.4
2+
3+
# change web server config
4+
COPY docker/frankenphp/Caddyfile /etc/caddy/Caddyfile
5+
6+
# set document root to /app/public (Yii2 structure)
7+
WORKDIR /app
8+
9+
# install required system packages for PHP extensions for Yii 2.0 Framework
10+
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
11+
RUN install-php-extensions \
12+
bcmath \
13+
@composer \
14+
exif \
15+
gd \
16+
imagick \
17+
intl \
18+
opcache \
19+
pdo_mysql \
20+
pdo_pgsql \
21+
soap \
22+
xdebug \
23+
zip
24+
25+
# set composer environment
26+
ENV COMPOSER_ALLOW_SUPERUSER=1
27+
28+
# change PHP config
29+
COPY docker/php/php.ini /usr/local/etc/php/conf.d/base.ini
30+
31+
# install supervisord and Node.js (includes npm)
32+
RUN apt-get update && apt-get install -y \
33+
supervisor \
34+
curl \
35+
--no-install-recommends \
36+
&& curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
37+
&& apt-get install -y nodejs \
38+
&& apt-get clean \
39+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
40+
41+
# copy supervisord config
42+
COPY docker/frankenphp/supervisord/supervisord.conf /etc/supervisor/supervisord.conf
43+
44+
# copy supervisord program configs
45+
COPY docker/frankenphp/supervisord/conf.d/frankenphp.conf /etc/supervisor/conf.d/frankenphp.conf
46+
47+
# copy queue worker config uncommented for use with yii2-queue
48+
#COPY docker/frankenphp/supervisord/conf.d/queue.conf /etc/supervisor/conf.d/queue.conf
49+
50+
RUN mkdir -p /var/run && chown -R www-data:www-data /var/run
51+
52+
# Run supervisord
53+
CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[program:frankenphp]
2+
command=/usr/local/bin/frankenphp run --config /etc/caddy/Caddyfile
3+
autostart=true
4+
autorestart=true
5+
priority=10
6+
killasgroup=true
7+
stopasgroup=true
8+
stopsignal=QUIT
9+
stdout_logfile=/dev/stdout
10+
stdout_logfile_maxbytes=0
11+
stderr_logfile=/dev/stderr
12+
stderr_logfile_maxbytes=0
13+
user=www-data
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[program:yii-queue-worker]
2+
process_name=%(program_name)s_%(process_num)02d
3+
command=/usr/local/bin/php /app/yii queue/listen --verbose=1 --color=0
4+
autorestart=true
5+
autostart=true
6+
killasgroup=true
7+
numprocs=4
8+
redirect_stderr=true
9+
stderr_logfile=/dev/stderr
10+
stderr_logfile_maxbytes=0
11+
stdout_logfile=/dev/stdout
12+
stdout_logfile_maxbytes=0
13+
stopasgroup=true
14+
user=www-data
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[supervisord]
2+
nodaemon=true
3+
logfile=/dev/stdout
4+
logfile_maxbytes=0
5+
pidfile=/var/run/supervisord.pid
6+
7+
[include]
8+
files = /etc/supervisor/conf.d/*.conf
9+
10+
[supervisorctl]
11+
serverurl=unix:///var/run/supervisor.sock
12+
13+
[unix_http_server]
14+
file=/var/run/supervisor.sock
15+
chmod=0700

0 commit comments

Comments
 (0)