Skip to content

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

Merged
merged 3 commits into from
Aug 9, 2023

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Dec 20, 2022

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.

@wouterj wouterj changed the title Modernize Web Server Configuration article Modernize Web Server Configuration article (remove obsolete Apache examples, add Caddy) Dec 20, 2022
@wouterj wouterj changed the base branch from 6.2 to 5.4 December 20, 2022 22:03
Comment on lines 193 to 221
.. 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
}
Copy link
Member

@dunglas dunglas Dec 21, 2022

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:

Suggested change
.. 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
}

Copy link
Member Author

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.

@javiereguiluz
Copy link
Member

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!

@javiereguiluz javiereguiluz added this to the 5.4 milestone May 22, 2023
@javiereguiluz
Copy link
Member

Thank you Wouter and thanks to reviewers too!

@javiereguiluz javiereguiluz merged commit 8bf8b11 into symfony:5.4 Aug 9, 2023
@alexander-schranz
Copy link
Contributor

alexander-schranz commented Aug 9, 2023

That is awesome to have this in symfony doc now. Thx all 👍

@wouterj wouterj deleted the pull-16104 branch August 9, 2023 16:25
@freecastle
Copy link
Contributor

What's the reason you removed the FallbackResource disabled directive for Apache here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing Caddy Webserver Documentation
9 participants