From 89c44b7e50190b4a05b4ce5e60ca546f851d457f Mon Sep 17 00:00:00 2001 From: Neel Chauhan Date: Tue, 16 Jan 2024 11:20:49 -0800 Subject: [PATCH 1/2] Add PHP FastCGI guide for Caddy --- docs/guides/web/caddy.md | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/docs/guides/web/caddy.md b/docs/guides/web/caddy.md index b6de0ae899..21cb67a5ba 100644 --- a/docs/guides/web/caddy.md +++ b/docs/guides/web/caddy.md @@ -148,6 +148,89 @@ Within a minute, Caddy will obtain SSL certificates from Let's Encrypt. Then, yo It should have an SSL padlock that should work in every modern browser, and not just that, but also an A+ rating at [Qualys SSL Server Test](https://www.ssllabs.com/ssltest/). +## Optional: PHP FastCGI + +Like mentioned earlier, Caddy supports FastCGI support for PHP. The good news is that unlike Apache and Nginx, Caddy automatically takes care of handling PHP file extensions. + +To install PHP, first add the Remi repository (note: if you are running Rocky Linux 8.x, substitute in 8 next to the "release-" below): + +```bash +dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm +``` + +Next, we need to install PHP (note: if you are using another version of PHP, substitute your desired version for php81): + +```bash +dnf install -y php81-php-fpm +``` + +If you require additional PHP modules (e.g. GD), add them to the above command. + +Then, we need to configure PHP to listen on a TCP socket: + +```bash +vim /etc/opt/remi/php81/php-fpm.d/www.conf +``` + +Next, find the line: + +```bash +listen = /var/opt/remi/php81/run/php-fpm/www.sock +``` + +Replace it with this: + +```bash +listen = 127.0.0.1:9000 +```` + +Then save and exit the www.conf file, and open the Caddyfile: + +```bash +vim /etc/caddy/Caddyfile +``` + +Navigate to the server block we created earlier: + +```bash +example.com + root * /usr/share/caddy/example.com + file_server +} +``` + +Add the following line after the "file\_server" line: + +```bash + php_fastcgi 127.0.0.1:9000 +``` + +Your PHP-enabled server block will look like this: + +```bash +example.com + root * /usr/share/caddy/example.com + file_server + php_fastcgi 127.0.0.1:9000 +} +``` + +Then save and exit the Caddyfile, and restart Caddy: + +```bash +systemctl restart caddy +``` + +To test if PHP works, let's add a simple PHP file: + +```bash +echo "" >> /usr/share/caddy/rockyexample.duckdns.org/phpinfo.php +``` + +Open your browser to the file you created, and you should be presented with PHP information: + +![Caddy serving our PHP file](../images/caddy_php.png) + ## Conclusion The basic installation and configuration of Caddy is incredibly easy. Gone are the days where you spent hours configuring Apache. Yes, Nginx is certainly an improvement, but it still lacks modern but essential features such as Let's Encrypt and Kubernetes ingress support that Caddy builds in, whereas on Nginx (and Apache) you must add them separately. From 07c3c5b6e08ae7bdc2e1e158435892d97f9b9f8d Mon Sep 17 00:00:00 2001 From: Neel Chauhan Date: Tue, 16 Jan 2024 11:22:49 -0800 Subject: [PATCH 2/2] Add braces --- docs/guides/web/caddy.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guides/web/caddy.md b/docs/guides/web/caddy.md index 21cb67a5ba..78d553bd0a 100644 --- a/docs/guides/web/caddy.md +++ b/docs/guides/web/caddy.md @@ -193,7 +193,7 @@ vim /etc/caddy/Caddyfile Navigate to the server block we created earlier: ```bash -example.com +example.com { root * /usr/share/caddy/example.com file_server } @@ -208,7 +208,7 @@ Add the following line after the "file\_server" line: Your PHP-enabled server block will look like this: ```bash -example.com +example.com { root * /usr/share/caddy/example.com file_server php_fastcgi 127.0.0.1:9000