Skip to content

Commit a15e804

Browse files
committed
Add Caddy section
1 parent c0d04fa commit a15e804

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

setup/web_server_configuration.rst

+37-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The preferred way to develop your Symfony application is to use
99

1010
However, when running the application in the production environment, you'll need
1111
to use a fully-featured web server. This article describes how to use Symfony
12-
with Apache or Nginx.
12+
with Apache, Nginx or Caddy.
1313

1414
.. sidebar:: The public directory
1515

@@ -185,7 +185,43 @@ The **minimum configuration** to get your application running under Nginx is:
185185

186186
For advanced Nginx configuration options, read the official `Nginx documentation`_.
187187

188+
Caddy
189+
-----
190+
191+
When using Caddy on the server, you can use a configuration like this:
192+
193+
.. code-block:: raw
194+
195+
# /etc/caddy/Caddyfile
196+
domain.tld, www.domain.tld {
197+
root * /var/www/project/public
198+
199+
# serve files directly if they can be found (e.g. CSS or JS files in public/)
200+
encode zstd gzip
201+
file_server
202+
203+
204+
# otherwise, use PHP-FPM (replace "unix//var/..." with "127.0.0.1:9000" when using TCP)
205+
php_fastcgi unix//var/run/php/php7.4-fpm.sock {
206+
# optionally set the value of the environment variables used in the application
207+
# env APP_ENV "prod"
208+
# env APP_SECRET "<app-secret-id>"
209+
# env DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"
210+
}
211+
212+
# return 404 for all other php files not matching the front controller
213+
# this prevents access to other php files you don't want to be accessible.
214+
@phpFile {
215+
path *.php*
216+
}
217+
error @phpFile "Not found" 404
218+
}
219+
220+
See the `official Caddy documentation`_ for more examples, such as using
221+
Caddy in a container infrastructure,
222+
188223
.. _`Apache documentation`: https://httpd.apache.org/docs/
189224
.. _`FastCgiExternalServer`: https://docs.oracle.com/cd/B31017_01/web.1013/q20204/mod_fastcgi.html#FastCgiExternalServer
190225
.. _`Nginx documentation`: https://www.nginx.com/resources/wiki/start/topics/recipes/symfony/
191226
.. _`How to run Symfony applications using NGINX Unit`: https://unit.nginx.org/howto/symfony/
227+
.. _`official Caddy documentation`: https://caddyserver.com/docs/

0 commit comments

Comments
 (0)