Skip to content

Commit 478e98d

Browse files
committed
Add Caddy section
1 parent a10d717 commit 478e98d

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

setup/web_server_configuration.rst

+43-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The preferred way to develop your Symfony application is to use
66

77
However, when running the application in the production environment, you'll need
88
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.
1010

1111
.. sidebar:: The public directory
1212

@@ -182,7 +182,49 @@ The **minimum configuration** to get your application running under Nginx is:
182182

183183
For advanced Nginx configuration options, read the official `Nginx documentation`_.
184184

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+
185226
.. _`Apache documentation`: https://httpd.apache.org/docs/
186227
.. _`FastCgiExternalServer`: https://docs.oracle.com/cd/B31017_01/web.1013/q20204/mod_fastcgi.html#FastCgiExternalServer
187228
.. _`Nginx documentation`: https://www.nginx.com/resources/wiki/start/topics/recipes/symfony/
188229
.. _`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

Comments
 (0)