Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ jobs:
- name: Run codeception tests.
run: docker exec yii2-apache vendor/bin/codecept run

test-frankenphp:
runs-on: ubuntu-latest

steps:
- name: Checkout.
uses: actions/checkout@v4

- name: Install docker compose.
run: |
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

- name: Build and start containers.
run: docker-compose -f docker-compose.frankenphp.yml build --no-cache && docker-compose -f docker-compose.frankenphp.yml up -d

- name: Update vendor packages.
run: docker exec yii2-frankenphp composer update --prefer-dist -vvv

- name: Codeception build.
run: docker exec yii2-frankenphp vendor/bin/codecept build

- name: Run codeception build and tests.
run: docker exec yii2-frankenphp vendor/bin/codecept run

test-nginx:
runs-on: ubuntu-latest

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ A modern, Bootstrap 5-powered Yii2 application template designed for rapid web-a
## Environment support

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

## Quick start
Expand Down Expand Up @@ -100,6 +101,9 @@ php -S localhost:8080 -t public
# For Apache
docker-compose up -d

# For FrankenPHP
docker-compose -f docker-compose.frankenphp.yml up -d

# For Nginx
docker-compose -f docker-compose.nginx.yml up -d
```
Expand All @@ -115,6 +119,9 @@ http://localhost:8080/
# For Apache
http://localhost:8080/

# For FrankenPHP
http://localhost:8082/

# For Nginx
http://localhost:8081/
```
Expand All @@ -132,6 +139,7 @@ root/
│ └── messages.php Translation config
├── docker/ Docker configuration files
│ ├── apache/ Apache configuration
│ ├── frankenphp/ FrankenPHP configuration
│ ├── nginx/ Nginx configuration
│ └── php/ PHP configuration
├── src/
Expand Down
25 changes: 25 additions & 0 deletions docker-compose.frankenphp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

services:
yii2-frankenphp:
build:
dockerfile: docker/frankenphp/Dockerfile
container_name: yii2-frankenphp
restart: always
working_dir: /app
volumes:
- ./:/app
- ~/.composer-docker/cache:/root/.composer/cache:delegated
- caddy_data:/data
- caddy_config:/config
ports:
- '8082:80'
- '8443:443'
- '8443:443/udp'
environment:
TZ: "UTC"
tty: true

# Volumes needed for Caddy certificates and configuration
volumes:
caddy_data:
caddy_config:
52 changes: 52 additions & 0 deletions docker/frankenphp/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
# Global options
auto_https off
}

# Main server block
:80 {
# Document root
root * /app/public

# Enable PHP processing with FrankenPHP
php_server

# Security headers
header {
X-Frame-Options "SAMEORIGIN"
X-XSS-Protection "1; mode=block"
X-Content-Type-Options "nosniff"
-Server
}

# Logging
log {
output stdout
format console
}

# Handle static files
@static {
file
path *.css *.js *.png *.jpg *.jpeg *.gif *.ico *.svg *.woff *.woff2 *.ttf *.eot
}
handle @static {
header Cache-Control "public, max-age=31536000"
file_server
}

# Block access to sensitive directories
@forbidden {
path /.git/* /vendor/* /runtime/* /.env*
}
respond @forbidden 404

# Deny PHP execution in assets directory (Yii2 security)
@assets_php {
path /assets/*.php
}
respond @assets_php 403

# Try files for Yii2 URL rewriting
try_files {path} {path}/ /index.php?{query}
}
53 changes: 53 additions & 0 deletions docker/frankenphp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM dunglas/frankenphp:1.8-php8.4

# change web server config
COPY docker/frankenphp/Caddyfile /etc/caddy/Caddyfile

# set document root to /app/public (Yii2 structure)
WORKDIR /app

# install required system packages for PHP extensions for Yii 2.0 Framework
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions \
bcmath \
@composer \
exif \
gd \
imagick \
intl \
opcache \
pdo_mysql \
pdo_pgsql \
soap \
xdebug \
zip

# set composer environment
ENV COMPOSER_ALLOW_SUPERUSER=1

# change PHP config
COPY docker/php/php.ini /usr/local/etc/php/conf.d/base.ini

# install supervisord and Node.js (includes npm)
RUN apt-get update && apt-get install -y \
supervisor \
curl \
--no-install-recommends \
&& curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
&& apt-get install -y nodejs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# copy supervisord config
COPY docker/frankenphp/supervisord/supervisord.conf /etc/supervisor/supervisord.conf

# copy supervisord program configs
COPY docker/frankenphp/supervisord/conf.d/frankenphp.conf /etc/supervisor/conf.d/frankenphp.conf

# copy queue worker config uncommented for use with yii2-queue
#COPY docker/frankenphp/supervisord/conf.d/queue.conf /etc/supervisor/conf.d/queue.conf

RUN mkdir -p /var/run && chown -R www-data:www-data /var/run

# Run supervisord
CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
13 changes: 13 additions & 0 deletions docker/frankenphp/supervisord/conf.d/frankenphp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[program:frankenphp]
command=/usr/local/bin/frankenphp run --config /etc/caddy/Caddyfile
autostart=true
autorestart=true
priority=10
killasgroup=true
stopasgroup=true
stopsignal=QUIT
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
user=www-data
14 changes: 14 additions & 0 deletions docker/frankenphp/supervisord/conf.d/queue.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[program:yii-queue-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/bin/php /app/yii queue/listen --verbose=1 --color=0
autorestart=true
autostart=true
killasgroup=true
numprocs=4
redirect_stderr=true
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stopasgroup=true
user=www-data
2 changes: 2 additions & 0 deletions docker/frankenphp/supervisord/log/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
15 changes: 15 additions & 0 deletions docker/frankenphp/supervisord/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[supervisord]
nodaemon=true
logfile=/dev/stdout
logfile_maxbytes=0
pidfile=/var/run/supervisord.pid

[include]
files = /etc/supervisor/conf.d/*.conf

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock

[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700