This project is largely inspired from Kévin Dunglas's project Symfony Docker, it aims to provide a ready to use install for a slim project using frankenPHP server and vulcain / mercure technologies for SSE and hot reloading.
- If not already done, install Docker Compose (v2.10+)
- Run
docker compose build --pull --no-cacheto build fresh images
optional. If you have an existing Slim project you want to run place it under the folder src/, such as this:
frankenphp-slim/
├─ frankenphp/
├─ src/
├─ public/
├─ index.php
- Run
docker compose up --waitto set up - Open
https://localhostin your favorite web browser to access you app (accept self signed certificate in local / dev mode) - Run
docker compose down --remove-orphansto stop the Docker containers.
docker cp <container_name>:/data/caddy/pki/authorities/local/root.crt ./caddy-root.crtsudo cp caddy-root.crt /usr/local/share/ca-certificates/caddy-root.crtsudo update-ca-certificatessudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain caddy-root.crt- Production, development and CI ready
- All-in-one Docker container by default
- Super-readable configuration
- Unfortunately the worker mode of FrankenPHP is not up in this version but I'll try to make it available with my next project (frankenphp-slim-enhanced)
- Automatic HTTPS (in dev and prod)
- HTTP/3 ready and HTTP/2 support
- Real-time messaging thanks to a built-in Mercure hub
- Vulcain support
- Hot Reloading
- Rootless, slim production image
- This project should have a native XDebug integration (sole point that I did not test here yet)
Enjoy!
Copy your project on the server using git clone, scp, or any other tool
that may fit your need.
If you use GitHub, you may want to use a deploy key.
Deploy keys are also supported by GitLab.
Example with Git:
git clone git@github.com:<username>/<project-name>.gitGo into the directory containing your project (<project-name>),
and start the app in production mode:
# Build fresh production image
docker compose -f compose.yaml -f compose.prod.yaml build --pull --no-cache
# Start container
SERVER_NAME=your-domain-name.example.com \
APP_SECRET=ChangeMe \
CADDY_MERCURE_JWT_SECRET=ChangeThisMercureHubJWTSecretKey \
docker compose -f compose.yaml -f compose.prod.yaml up --waitBe sure to replace your-domain-name.example.com with your actual domain name
and to set the values of APP_SECRET, CADDY_MERCURE_JWT_SECRET
to cryptographically secure random values.
Your server is up and running, and a HTTPS certificate has been automatically
generated for you.
Go to https://your-domain-name.example.com and enjoy!
Caution
Docker can have a cache layer, make sure you have the right build
for each deployment or rebuild your project with --no-cache option
to avoid cache issues.
Alternatively, if you don't want to expose an HTTPS server but only an HTTP one, run the following command:
SERVER_NAME=:80 \
APP_SECRET=ChangeMe \
CADDY_MERCURE_JWT_SECRET=Key \
docker compose -f compose.yaml -f compose.prod.yaml up --waitBy default, .env.local and .env.*.local files are excluded from production images.
If you want to pass them to your containers, you can use the env_file attribute:
# compose.prod.yaml
services:
php:
env_file:
- .env.prod.local
# ...frankenphp-slim is available under the MIT License.
By Laurent Legaz, largely inspired from Kévin Dunglas's project Symfony Docker.