@@ -6,7 +6,7 @@ The preferred way to develop your Symfony application is to use
6
6
7
7
However, when running the application in the production environment, you'll need
8
8
to use a fully-featured web server. This article describes how to use Symfony
9
- with Apache or Nginx .
9
+ with Apache, Nginx or Caddy .
10
10
11
11
.. sidebar :: The public directory
12
12
@@ -182,7 +182,49 @@ The **minimum configuration** to get your application running under Nginx is:
182
182
183
183
For advanced Nginx configuration options, read the official `Nginx documentation `_.
184
184
185
+ Caddy
186
+ -----
187
+
188
+ When using Caddy on the server, you can use a configuration like this:
189
+
190
+ .. code-block :: raw
191
+
192
+ # /etc/caddy/Caddyfile
193
+ example.com, www.example.com {
194
+ root * /var/www/project/public
195
+
196
+ # serve files directly if they can be found (e.g. CSS or JS files in public/)
197
+ encode zstd gzip
198
+ file_server
199
+
200
+
201
+ # otherwise, use PHP-FPM (replace "unix//var/..." with "127.0.0.1:9000" when using TCP)
202
+ php_fastcgi unix//var/run/php/php7.4-fpm.sock {
203
+ # optionally set the value of the environment variables used in the application
204
+ # env APP_ENV "prod"
205
+ # env APP_SECRET "<app-secret-id>"
206
+ # env DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"
207
+
208
+ # Configure the FastCGI to resolve any symlinks in the root path.
209
+ # This ensures that OpCache is using the destination filenames,
210
+ # instead of the symlinks, to cache opcodes and php files see
211
+ # https://caddy.community/t/root-symlink-folder-updates-and-caddy-reload-not-working/10557
212
+ resolve_root_symlink
213
+ }
214
+
215
+ # return 404 for all other php files not matching the front controller
216
+ # this prevents access to other php files you don't want to be accessible.
217
+ @phpFile {
218
+ path *.php*
219
+ }
220
+ error @phpFile "Not found" 404
221
+ }
222
+
223
+ See the `official Caddy documentation `_ for more examples, such as using
224
+ Caddy in a container infrastructure.
225
+
185
226
.. _`Apache documentation` : https://httpd.apache.org/docs/
186
227
.. _`FastCgiExternalServer` : https://docs.oracle.com/cd/B31017_01/web.1013/q20204/mod_fastcgi.html#FastCgiExternalServer
187
228
.. _`Nginx documentation` : https://www.nginx.com/resources/wiki/start/topics/recipes/symfony/
188
229
.. _`How to run Symfony applications using NGINX Unit` : https://unit.nginx.org/howto/symfony/
230
+ .. _`official Caddy documentation` : https://caddyserver.com/docs/
0 commit comments