Running Caddy on Windows with PHP successfully

1. Caddy version (caddy version):

v2

2. How I run Caddy:

caddy2 adapt --adapter=caddyfile --config=caddy2.caddyfile > caddyfile.json

caddy2 start --config=caddyfile.json

# seperate file

  start /b C:\BCSDEV\php81\php-cgi.exe -b 21445

a. System environment:

Windows Server

b. Command:

caddy2 adapt --adapter=caddyfile --config=caddy2.caddyfile > caddyfile.json

caddy2 start --config=caddyfile.json

d. My complete Caddyfile or JSON config:

https://backoffice.cookingisfun.ie  api.cookingisfun.ie    {

        root * "C:\BCSDEV\www\PROD\bcsstudents.laravel\public"
        file_server

      php_fastcgi  127.0.0.1:21445 

      
    # Logging
   log {
    output file c:\bcsdev\logs2\backoffice.caddy2.access.log {
        roll_size 10mb
        roll_keep 15
        
    }



 }
}

3. The problem I’m having:

Very slow performance sometimes. I’m wondering if the way I have php set up is causing it to run a single request at a time so if i have a slow running page load it affects other users. I only have about 10 users so usually not ab problem just wondering if I can change my setup

4. Error messages and/or full log output:

none

5. What I already tried:

Wondering if using TS (thread safe) php woudl help though its not necessary recommended on windows.

Could I set up several php cgi servers and load balance among them.

How have other people achiveved production level php on windows with caddy?

1 Like

I know, I know I shouldnt be running PHP on Windows, but I am.

For anyone else having this issue, the PHP_FCGI_CHILDREN value is now used on windows. So running this before starting the fast-cgi servers has made a big differnce.

set PHP_FCGI_CHILDREN=8
set PHP_FCGI_MAX_REQUESTS=0

2 Likes

FYI, you don’t need to do this step. Name your Caddyfile literally Caddyfile, then you can just do caddy start --config Caddyfile. No need to adapt ahead of time, that’s built-in.

Also, I strongly recommend running Caddy as a service, not with caddy start. Keep Caddy Running — Caddy Documentation

And use caddy fmt to clean up your Caddyfile’s formatting (fix indentation).

1 Like

If Caddyfile is adjacent to the EXE, then you don’t even need the --config Caddyfile, right?

1 Like

That’s right, if the file is specifically named Caddyfile.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.