Skip to content

Commit 2c8c26f

Browse files
committed
docs: add Symfony-specific page
1 parent c12841b commit 2c8c26f

4 files changed

Lines changed: 275 additions & 60 deletions

File tree

CONTRIBUTING.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -90,60 +90,60 @@ curl -v http://127.0.0.1:8080/phpinfo.php
9090

9191
1. Configure Git to always use `lf` line endings
9292

93-
```powershell
94-
git config --global core.autocrlf false
95-
git config --global core.eol lf
96-
```
93+
```powershell
94+
git config --global core.autocrlf false
95+
git config --global core.eol lf
96+
```
9797

9898
2. Install Visual Studio, Git, and Go:
9999

100-
```powershell
101-
winget install -e --id Microsoft.VisualStudio.2022.Community --override "--passive --wait --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --includeRecommended"
102-
winget install -e --id GoLang.Go
103-
winget install -e --id Git.Git
104-
```
100+
```powershell
101+
winget install -e --id Microsoft.VisualStudio.2022.Community --override "--passive --wait --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --includeRecommended"
102+
winget install -e --id GoLang.Go
103+
winget install -e --id Git.Git
104+
```
105105

106106
3. Install vcpkg:
107107

108-
```powershell
109-
cd C:\
110-
git clone https://github.com/microsoft/vcpkg
111-
.\vcpkg\bootstrap-vcpkg.bat
112-
```
108+
```powershell
109+
cd C:\
110+
git clone https://github.com/microsoft/vcpkg
111+
.\vcpkg\bootstrap-vcpkg.bat
112+
```
113113

114114
4. [Download the latest version of the watcher library for Windows](https://github.com/e-dant/watcher/releases) and extract it to a directory named `C:\watcher`
115115
5. [Download the latest **Thread Safe** version of PHP and of the PHP SDK for Windows](https://windows.php.net/download/), extract them in directories named `C:\php` and `C:\php-devel`
116116
6. Clone the FrankenPHP Git repository:
117117

118-
```powershell
119-
git clone https://github.com/php/frankenphp C:\frankenphp
120-
cd C:\frankenphp
121-
```
118+
```powershell
119+
git clone https://github.com/php/frankenphp C:\frankenphp
120+
cd C:\frankenphp
121+
```
122122

123123
7. Install the dependencies:
124124

125-
```powershell
126-
C:\vcpkg\vcpkg.exe install
127-
```
125+
```powershell
126+
C:\vcpkg\vcpkg.exe install
127+
```
128128

129129
8. Configure the needed environment variables (PowerShell):
130130

131-
```powershell
132-
$env:PATH += ';C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\bin'
133-
$env:CC = 'clang'
134-
$env:CXX = 'clang++'
135-
$env:CGO_CFLAGS = "-O0 -g -IC:\frankenphp\vcpkg_installed\x64-windows\include -IC:\watcher -IC:\php-devel\include -IC:\php-devel\include\main -IC:\php-devel\include\TSRM -IC:\php-devel\include\Zend -IC:\php-devel\include\ext"
136-
$env:CGO_LDFLAGS = '-LC:\frankenphp\vcpkg_installed\x64-windows\lib -lbrotlienc -LC:\watcher -llibwatcher-c -LC:\php -LC:\php-devel\lib -lphp8ts -lphp8embed'
137-
```
131+
```powershell
132+
$env:PATH += ';C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\bin'
133+
$env:CC = 'clang'
134+
$env:CXX = 'clang++'
135+
$env:CGO_CFLAGS = "-O0 -g -IC:\frankenphp\vcpkg_installed\x64-windows\include -IC:\watcher -IC:\php-devel\include -IC:\php-devel\include\main -IC:\php-devel\include\TSRM -IC:\php-devel\include\Zend -IC:\php-devel\include\ext"
136+
$env:CGO_LDFLAGS = '-LC:\frankenphp\vcpkg_installed\x64-windows\lib -lbrotlienc -LC:\watcher -llibwatcher-c -LC:\php -LC:\php-devel\lib -lphp8ts -lphp8embed'
137+
```
138138

139139
9. Run the tests:
140140

141-
```powershell
142-
go test -race -ldflags '-extldflags="-fuse-ld=lld"' ./...
143-
cd caddy
144-
go test -race -ldflags '-extldflags="-fuse-ld=lld"' -tags nobadger,nomysql,nopgx ./...
145-
cd ..
146-
```
141+
```powershell
142+
go test -race -ldflags '-extldflags="-fuse-ld=lld"' ./...
143+
cd caddy
144+
go test -race -ldflags '-extldflags="-fuse-ld=lld"' -tags nobadger,nomysql,nopgx ./...
145+
cd ..
146+
```
147147

148148
10. Build the binary:
149149

@@ -299,7 +299,7 @@ The steps assume the following environment:
299299

300300
4. Debug Go files from CLion
301301

302-
- Right click on a *.go file in the Project view on the left
302+
- Right click on a \*.go file in the Project view on the left
303303
- Override file type → C/C++
304304

305305
Now you can place breakpoints in C, C++ and Go files.
@@ -348,7 +348,7 @@ Use GoLand for primary Go development, but the debugger cannot debug C code.
348348

349349
To debug C files from GoLand
350350

351-
- Right click on a *.c file in the Project view on the left
351+
- Right click on a \*.c file in the Project view on the left
352352
- Override file type → Go
353353

354354
Now you can place breakpoints in C, C++ and Go files.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ Our maintainers offer apk packages for all systems using `apk`. To install, run:
9090
VERSION=85 # 82-85 available
9191
echo "https://pkg.henderkes.com/api/packages/${VERSION}/alpine/main/php-zts" | sudo tee -a /etc/apk/repositories
9292
KEYFILE=$(curl -sJOw '%{filename_effective}' https://pkg.henderkes.com/api/packages/${VERSION}/alpine/key)
93-
sudo mv ${KEYFILE} /etc/apk/keys/ &&
94-
sudo apk update &&
93+
sudo mv ${KEYFILE} /etc/apk/keys/ &&
94+
sudo apk update &&
9595
sudo apk add frankenphp
9696
```
9797

@@ -170,6 +170,7 @@ Go to `https://localhost`, and enjoy!
170170
- [Compile from sources](https://frankenphp.dev/docs/compile/)
171171
- [Monitoring FrankenPHP](https://frankenphp.dev/docs/metrics/)
172172
- [WordPress integration](https://frankenphp.dev/docs/wordpress/)
173+
- [Symfony integration](https://frankenphp.dev/docs/symfony/)
173174
- [Laravel integration](https://frankenphp.dev/docs/laravel/)
174175
- [Known issues](https://frankenphp.dev/docs/known-issues/)
175176
- [Demo app (Symfony) and benchmarks](https://github.com/dunglas/frankenphp-demo)
@@ -178,7 +179,7 @@ Go to `https://localhost`, and enjoy!
178179

179180
## Examples and Skeletons
180181

181-
- [Symfony](https://github.com/dunglas/symfony-docker)
182+
- [Symfony](https://frankenphp.dev/docs/symfony/)
182183
- [API Platform](https://api-platform.com/docs/symfony)
183184
- [Laravel](https://frankenphp.dev/docs/laravel/)
184185
- [Sulu](https://sulu.io/blog/running-sulu-with-frankenphp)

docs/symfony.md

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
# Symfony
2+
3+
## Docker
4+
5+
For [Symfony](https://symfony.com) projects, we recommend using [Symfony Docker](https://github.com/dunglas/symfony-docker), the official Symfony Docker setup maintained by FrankenPHP's author. It provides a complete Docker-based environment with FrankenPHP, automatic HTTPS, HTTP/2, HTTP/3, and worker mode support out of the box.
6+
7+
## Local Installation
8+
9+
Alternatively, you can run your Symfony projects with FrankenPHP from your local machine:
10+
11+
1. [Download the binary corresponding to your system](../README.md#standalone-binary)
12+
2. Add the following configuration to a file named `Caddyfile` in the root directory of your Symfony project:
13+
14+
```caddyfile
15+
# The domain name of your server
16+
localhost {
17+
# Set the webroot to the public/ directory
18+
root public/
19+
# Enable compression (optional)
20+
encode zstd br gzip
21+
22+
23+
# Rewrite requests to non-existing files to the front controller
24+
@phpRoute {
25+
not file {path}
26+
}
27+
rewrite @phpRoute index.php
28+
29+
@frontController path index.php
30+
php @frontController {
31+
# Optional: Enable worker mode for better performance
32+
worker {
33+
file ./public/index.php
34+
}
35+
}
36+
37+
file_server {
38+
hide *.php
39+
}
40+
}
41+
```
42+
43+
See the [performance documentation](performance.md) for further optimizations.
44+
45+
3. Start FrankenPHP from the root directory of your Symfony project: `frankenphp run`
46+
47+
## Worker Mode
48+
49+
Since Symfony 7.4, FrankenPHP worker mode is natively supported.
50+
51+
For older versions, install the FrankenPHP package of [PHP Runtime](https://github.com/php-runtime/runtime):
52+
53+
```console
54+
composer require runtime/frankenphp-symfony
55+
```
56+
57+
Start your app server by defining the `APP_RUNTIME` environment variable to use the FrankenPHP Symfony Runtime:
58+
59+
```console
60+
docker run \
61+
-e FRANKENPHP_CONFIG="worker ./public/index.php" \
62+
-e APP_RUNTIME=Runtime\\FrankenPhpSymfony\\Runtime \
63+
-v $PWD:/app \
64+
-p 80:80 -p 443:443 -p 443:443/udp \
65+
dunglas/frankenphp
66+
```
67+
68+
Learn more about [the worker mode](worker.md).
69+
70+
## Hot Reload
71+
72+
Hot reloading is enabled by default in [Symfony Docker](https://github.com/dunglas/symfony-docker).
73+
74+
To use the [hot reload](hot-reload.md) feature without Symfony Docker, enable [Mercure](mercure.md) and add the `hot_reload` sub-directive to the `php` directive in your `Caddyfile`:
75+
76+
```caddyfile
77+
localhost
78+
79+
mercure {
80+
anonymous
81+
}
82+
83+
root public/
84+
85+
@phpRoute {
86+
not path /.well-known/mercure*
87+
not file {path}
88+
}
89+
rewrite @phpRoute index.php
90+
91+
@frontController path index.php
92+
php @frontController {
93+
hot_reload
94+
# Optional: enable worker in watch mode for better performance
95+
worker {
96+
file ./public/index.php
97+
watch
98+
}
99+
}
100+
101+
file_server {
102+
hide *.php
103+
}
104+
```
105+
106+
Then, add the following code to your `templates/base.html.twig` file:
107+
108+
```twig
109+
{% if app.request.server.has('FRANKENPHP_HOT_RELOAD') %}
110+
<meta name="frankenphp-hot-reload:url" content="{{ app.request.server.get('FRANKENPHP_HOT_RELOAD') }}">
111+
<script src="https://cdn.jsdelivr.net/npm/idiomorph"></script>
112+
<script src="https://cdn.jsdelivr.net/npm/frankenphp-hot-reload/+esm" type="module"></script>
113+
{% endif %}
114+
```
115+
116+
Finally, run `frankenphp run` from the root directory of your Symfony project.
117+
118+
## Pre-Compressing Assets
119+
120+
Symfony's [AssetMapper component](https://symfony.com/doc/current/frontend/asset_mapper.html) can pre-compress assets with Brotli and Zstandard during deployment. FrankenPHP (through Caddy's `file_server`) can serve these pre-compressed files directly, avoiding on-the-fly compression overhead.
121+
122+
1. Compile and compress your assets:
123+
124+
```console
125+
php bin/console asset-map:compile
126+
```
127+
128+
2. Update your `Caddyfile` to serve pre-compressed assets:
129+
130+
```caddyfile
131+
{
132+
frankenphp
133+
}
134+
135+
localhost {
136+
root public/
137+
138+
@phpRoute {
139+
not file {path}
140+
}
141+
rewrite @phpRoute index.php
142+
143+
@frontController path index.php
144+
php @frontController {
145+
# Optional: Enable worker mode for better performance
146+
worker {
147+
file ./public/index.php
148+
}
149+
}
150+
151+
@assets path /assets/*
152+
file_server @assets {
153+
precompressed zstd br gzip
154+
}
155+
156+
file_server {
157+
hide *.php
158+
}
159+
}
160+
```
161+
162+
The `precompressed` directive tells Caddy to look for pre-compressed versions of the requested file (e.g., `app.css.zst`, `app.css.br`) and serve them directly if the client supports it.
163+
164+
## Symfony Apps As Standalone Binaries
165+
166+
Using [FrankenPHP's application embedding feature](embed.md), it's possible to distribute Symfony
167+
apps as standalone binaries.
168+
169+
Follow these steps to prepare and package your Symfony app:
170+
171+
1. Prepare your app:
172+
173+
```console
174+
# Export the project to get rid of .git/, etc
175+
mkdir $TMPDIR/my-prepared-app
176+
git archive HEAD | tar -x -C $TMPDIR/my-prepared-app
177+
cd $TMPDIR/my-prepared-app
178+
179+
# Set proper environment variables
180+
echo APP_ENV=prod > .env.local
181+
echo APP_DEBUG=0 >> .env.local
182+
183+
# Remove the tests and other unneeded files to save space
184+
# Alternatively, add these files with the export-ignore attribute in your .gitattributes file
185+
rm -Rf tests/
186+
187+
# Install the dependencies
188+
composer install --ignore-platform-reqs --no-dev -a
189+
190+
# Optimize .env
191+
composer dump-env prod
192+
```
193+
194+
2. Create a file named `static-build.Dockerfile` in the repository of your app:
195+
196+
```dockerfile
197+
FROM --platform=linux/amd64 dunglas/frankenphp:static-builder-gnu
198+
# If you intend to run the binary on musl-libc systems, use static-builder-musl instead
199+
200+
# Copy your app
201+
WORKDIR /go/src/app/dist/app
202+
COPY . .
203+
204+
# Build the static binary
205+
WORKDIR /go/src/app/
206+
RUN EMBED=dist/app/ ./build-static.sh
207+
```
208+
209+
> [!CAUTION]
210+
>
211+
> Some `.dockerignore` files (e.g. default [Symfony Docker `.dockerignore`](https://github.com/dunglas/symfony-docker/blob/main/.dockerignore))
212+
> will ignore the `vendor/` directory and `.env` files. Be sure to adjust or remove the `.dockerignore` file before the build.
213+
214+
3. Build:
215+
216+
```console
217+
docker build -t static-symfony-app -f static-build.Dockerfile .
218+
```
219+
220+
4. Extract the binary:
221+
222+
```console
223+
docker cp $(docker create --name static-symfony-app-tmp static-symfony-app):/go/src/app/dist/frankenphp-linux-x86_64 my-app ; docker rm static-symfony-app-tmp
224+
```
225+
226+
5. Start the server:
227+
228+
```console
229+
./my-app php-server
230+
```
231+
232+
Learn more about the options available and how to build binaries for other OSes in the [applications embedding](embed.md)
233+
documentation.

0 commit comments

Comments
 (0)