-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Modernize Web Server Configuration article (remove obsolete Apache examples, add Caddy) #17597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
setup/web_server_configuration.rst
Outdated
.. code-block:: raw | ||
|
||
# /etc/caddy/Caddyfile | ||
domain.tld, www.domain.tld { | ||
root * /var/www/project/public | ||
|
||
# serve files directly if they can be found (e.g. CSS or JS files in public/) | ||
encode zstd gzip | ||
file_server | ||
|
||
|
||
# otherwise, use PHP-FPM (replace "unix//var/..." with "127.0.0.1:9000" when using TCP) | ||
php_fastcgi unix//var/run/php/php7.4-fpm.sock { | ||
# optionally set the value of the environment variables used in the application | ||
# env APP_ENV "prod" | ||
# env APP_SECRET "<app-secret-id>" | ||
# env DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name" | ||
} | ||
|
||
# return 404 for all other php files not matching the front controller | ||
# this prevents access to other php files you don't want to be accessible. | ||
@phpFile { | ||
path *.php* | ||
} | ||
error @phpFile "Not found" 404 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a slightly simpler proposal based on API Platform's Caddyfile
:
.. code-block:: raw | |
# /etc/caddy/Caddyfile | |
domain.tld, www.domain.tld { | |
root * /var/www/project/public | |
# serve files directly if they can be found (e.g. CSS or JS files in public/) | |
encode zstd gzip | |
file_server | |
# otherwise, use PHP-FPM (replace "unix//var/..." with "127.0.0.1:9000" when using TCP) | |
php_fastcgi unix//var/run/php/php7.4-fpm.sock { | |
# optionally set the value of the environment variables used in the application | |
# env APP_ENV "prod" | |
# env APP_SECRET "<app-secret-id>" | |
# env DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name" | |
} | |
# return 404 for all other php files not matching the front controller | |
# this prevents access to other php files you don't want to be accessible. | |
@phpFile { | |
path *.php* | |
} | |
error @phpFile "Not found" 404 | |
} | |
.. code-block:: raw | |
# /etc/caddy/Caddyfile | |
example.com, www.example.com | |
log | |
route { | |
root * /var/www/project/public | |
php_fastcgi unix//var/run/php/php8.2-fpm.sock | |
encode zstd gzip | |
file_server | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep consistency with the Apache and Nginx examples, I've decided to keep the longer format.
Wouter, will you find some time to finish this? If you can't, I can try to merge this "as is", but including the fixes suggested by Kévin. Thanks! |
Thank you Wouter and thanks to reviewers too! |
That is awesome to have this in symfony doc now. Thx all 👍 |
What's the reason you removed the |
This continues #16104 (which removed old Apache information that advocates bad practices) and fixes #17471 by adding a working Caddy config example.
I've removed most of the Apache 2 version information, we were talking about 2.4 and 2.10, but even Debian oldoldstable (the really long LTS version of Debian) comes with 2.25 already.
I've kept using PHP 7.4 - something that we might want to change when merging up to 6.0. This is done to make the example in the article truely copy-pastable, PHP 7.4 is the current PHP version on the latest Debian version.