Caddy and PHP8 on Windows 10

1. Caddy version (caddy version):

v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=

2. How I run Caddy:

from command prompt, ‘caddy run’

a. System environment:

Windows 10 x64

b. Command:

caddy run

c. Service/unit/compose file:

n/a

d. My complete Caddyfile or JSON config:

:3020 {
	root * C:/caddywebs
	encode gzip
	php_fastcgi localhost:3030
	file_server
	log {
		output file access.log
	}
}

3. The problem I’m having:

Finding modern relevant docs on this setup has been a huge pain! Not much out there for this. Both php_fastcgi and caddy start up just fine. When I hit the localhost:3020 it loads html pages fine, but it will not load PHP pages.

Here is my bat file I use to run php_fastcgi:

@ECHO OFF
ECHO Starting PHP FastCGI... (Press CTRL+C to Stop)
set path=C:/web/PHP8;C:/web/caddy;%PATH%
C:\web\PHP8\php-cgi.exe -b localhost:3030 -c C:\web\PHP8\php.ini

Also I manually added those 2 folders to the path and rebooted my PC.

4. Error messages and/or full log output:

5. What I already tried:

Tried tinkering with the CaddyFile moving stuff around, etc.

6. Links to relevant resources:

Looks like it is trying to load the PHP file as regular HTML. This is what i see in the inspector:
image

Does anyone know how to test just php-fastcgi without incorporating the Caddy part of it?

What do you mean by “will not load”? Please be specific. What do you see in Caddy’s logs?

Turn on the debug global option to see more details in the logs.

Also, try using curl -v to make test requests, and report what you see.

1 Like

By not loading, I mean it displays nothing on the page, completely white. I am attempting to output the phpinfo script to show all the PHP details.

I turned on debug and this is what is see in the logs:

2021/11/15 01:55:28.167	error	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:62895", "proto": "HTTP/1.1", "method": "GET", "host": "localhost:3020", "uri": "/favicon.ico", "headers": {"User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0"], "Accept": ["image/avif,image/webp,*/*"], "Sec-Fetch-Site": ["same-origin"], "Sec-Fetch-Mode": ["no-cors"], "Accept-Language": ["en-US,en;q=0.5"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "Referer": ["http://localhost:3020/"], "Cookie": ["reg-portal-cid=s%3A2IbwI-gwDETkFfrOWGT_EMEZe5MxnyzB.4uEZmjszqzS8VDNqIwrlUX%2B%2B3GOKXNh2oLVeEPk%2BckE"], "Sec-Fetch-Dest": ["image"]}}, "common_log": "127.0.0.1 - - [14/Nov/2021:19:55:28 -0600] \"GET /favicon.ico HTTP/1.1\" 499 0", "user_id": "", "duration": 0.0022448, "size": 0, "status": 499, "resp_headers": {"Server": ["Caddy"]}}
2021/11/15 05:52:15.649	error	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:63692", "proto": "HTTP/1.1", "method": "GET", "host": "localhost:3020", "uri": "/", "headers": {"Accept-Language": ["en-US,en;q=0.5"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "Cookie": ["reg-portal-cid=s%3A2IbwI-gwDETkFfrOWGT_EMEZe5MxnyzB.4uEZmjszqzS8VDNqIwrlUX%2B%2B3GOKXNh2oLVeEPk%2BckE"], "Sec-Fetch-Mode": ["navigate"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"], "Sec-Fetch-Dest": ["document"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-User": ["?1"], "Upgrade-Insecure-Requests": ["1"]}}, "common_log": "127.0.0.1 - - [14/Nov/2021:23:52:15 -0600] \"GET / HTTP/1.1\" 499 0", "user_id": "", "duration": 33.3361145, "size": 0, "status": 499, "resp_headers": {"Server": ["Caddy"]}}
2021/11/15 05:52:58.877	info	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:63699", "proto": "HTTP/1.1", "method": "GET", "host": "localhost:3020", "uri": "/", "headers": {"User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0"], "Accept-Language": ["en-US,en;q=0.5"], "Cookie": ["reg-portal-cid=s%3A2IbwI-gwDETkFfrOWGT_EMEZe5MxnyzB.4uEZmjszqzS8VDNqIwrlUX%2B%2B3GOKXNh2oLVeEPk%2BckE"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-User": ["?1"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "Upgrade-Insecure-Requests": ["1"], "Sec-Fetch-Dest": ["document"], "Sec-Fetch-Mode": ["navigate"]}}, "common_log": "127.0.0.1 - - [14/Nov/2021:23:52:58 -0600] \"GET / HTTP/1.1\" 200 21", "user_id": "", "duration": 0.316219, "size": 21, "status": 200, "resp_headers": {"Server": ["Caddy"], "X-Powered-By": ["PHP/8.0.12"], "Content-Type": ["text/html; charset=UTF-8"]}}
2021/11/15 05:52:59.005	error	http.log.access.log0	handled request	{"request": {"remote_addr": "127.0.0.1:63699", "proto": "HTTP/1.1", "method": "GET", "host": "localhost:3020", "uri": "/favicon.ico", "headers": {"Referer": ["http://localhost:3020/"], "Sec-Fetch-Dest": ["image"], "Sec-Fetch-Mode": ["no-cors"], "Accept-Language": ["en-US,en;q=0.5"], "Connection": ["keep-alive"], "Accept": ["image/avif,image/webp,*/*"], "Accept-Encoding": ["gzip, deflate"], "Cookie": ["reg-portal-cid=s%3A2IbwI-gwDETkFfrOWGT_EMEZe5MxnyzB.4uEZmjszqzS8VDNqIwrlUX%2B%2B3GOKXNh2oLVeEPk%2BckE"], "Sec-Fetch-Site": ["same-origin"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0"]}}, "common_log": "127.0.0.1 - - [14/Nov/2021:23:52:59 -0600] \"GET /favicon.ico HTTP/1.1\" 499 0", "user_id": "", "duration": 0.0026902, "size": 0, "status": 499, "resp_headers": {"Server": ["Caddy"]}}
2021/11/15 05:55:10.437	info	http.log.access.log0	handled request	{"request": {"remote_addr": "[::1]:63726", "proto": "HTTP/1.1", "method": "GET", "host": "localhost:3020", "uri": "/", "headers": {"User-Agent": ["curl/7.55.1"], "Accept": ["*/*"]}}, "common_log": "::1 - - [14/Nov/2021:23:55:10 -0600] \"GET / HTTP/1.1\" 200 21", "user_id": "", "duration": 0.3085603, "size": 21, "status": 200, "resp_headers": {"Content-Type": ["text/html; charset=UTF-8"], "Server": ["Caddy"], "X-Powered-By": ["PHP/8.0.12"]}}

And then the results of curl -v http://localhost:3020

 Rebuilt URL to: http://localhost:3020/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 3020 (#0)
> GET / HTTP/1.1
> Host: localhost:3020
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=UTF-8
< Server: Caddy
< X-Powered-By: PHP/8.0.12
< Date: Mon, 15 Nov 2021 05:55:10 GMT
< Content-Length: 21
<
<? echo phpinfo(); ?>* Connection #0 to host localhost left intact

That’s just the access logs. The rest of Caddy’s logs (and the debug stuff) get output in stderr by default.

Status 499 looks suspicious. Caddy responds with that status code when the client closed the connection before Caddy could respond.

Oh. That would explain it. PHP short-open-tags (i.e. <?) are disabled by default. You should instead use <?php.

Using <? is actually a problem, because XML uses <?xml, so valid XML would be attempted to be executed as a PHP script. That’s bad.

And also, <? is not portable, because there’s no guarantee that another server will have it enabled (and they shouldn’t, it’s bad).

1 Like

Wow, that was it! Thank you so much! Been quite a while since I touched PHP so forgot about that short-open-tag deal.

1 Like

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