I can't use PHP

1. Caddy version (caddy version):

v2.4.6

2. How I run Caddy:

Via systemd service, I use the apt package.

a. System environment:

Debian 11, systemd 247.

b. Command:

I enabled the systemd service.

c. Service/unit/compose file:

The default systemd service.

d. My complete Caddyfile or JSON config:

cezeri.tech {
	# Set this path to your site's directory.
	root * /var/www/html/cezeriweb
	encode gzip

	# Enable the static file server.
	file_server

	# Another common task is to set up a reverse proxy:
	# reverse_proxy localhost:8080

	# Or serve a PHP site through php-fpm:
	# php_fastcgi
}
sanoksim.cezeri.tech {
	root * /var/www/html/site
	encode gzip
	file_server
}

vipamorfa.cezeri.tech {
	root * /var/www/html/vipamorfa
	encode gzip
	file_server
}

search.cezeri.tech {
	reverse_proxy 127.0.0.1:8888
}

hesap.cezeri.tech {
	encode gzip
	root * /var/www/html/hesap
	php_fastcgi unix//run/php-fpm.sock
	file_server
}
git.cezeri.tech {
	reverse_proxy localhost:3000
}

mail.cezeri.tech {
	reverse_proxy 127.0.0.1:8080
}

cloud.cezeri.tech {
	reverse_proxy 127.0.0.1:8070
}

# Vaultwarden
vault.cezeri.tech:443 {
	reverse_proxy http://localhost:4209 {
		header_up X-Real-IP {remote_host}
	}
}
# PrivateBin
paste.cezeri.tech {
	encode zstd gzip
	root * /var/www/PrivateBin-1.4.0
	php_fastcgi unix//run/php-fpm.sock
	file_server
}


3. The problem I’m having:

<I can’t use PHP, for example I can launch test.php but PrivateBin and PHP-based chat (Turkish language, just pick a random username and try to send a message) doesn’t work. I wanted to paste the fpm www.conf here but it’s too long.

What’s in your logs? You can find the command to run to read Caddy’s logs here:

Are you sure the caddy user has permissions to read these files?

Are you sure this unix socket file exists?

2 Likes

Nothing interesting when I try to reload or open a PHP file.

When I list folders as caddy user with ls -la, it outputs drwxrwxr-x+. So I guess yes.

Yes.

Add the debug global option at the top of your Caddyfile and try again:

{
	debug
}

We need to see logs, otherwise we can’t do much to help.

This is what it outputs when I try to save a pastebin in the PrivateBin:

Apr 25 15:40:37 cezeriserver caddy[793]: {"level":"debug","ts":1650901237.901912,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_addr":"176.88.87.31:28926","proto":"HTTP/2.0","method":"POST","host":"paste.cezeri.tech","uri":"/","headers":{"X-Requested-With":["JSONHttpRequest"],"Origin":["https://paste.cezeri.tech"],"Sec-Fetch-Mode":["cors"],"User-Agent":["Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0"],"Accept-Language":["en-US,en;q=0.5"],"Accept-Encoding":["gzip, deflate, br"],"Sec-Fetch-Dest":["empty"],"Sec-Fetch-Site":["same-origin"],"Te":["trailers"],"Accept":["application/json, text/javascript, */*; q=0.01"],"Content-Type":["application/x-www-form-urlencoded; charset=UTF-8"],"Content-Length":["201"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"paste.cezeri.tech"}},"method":"POST","uri":"/index.php"}
Apr 25 15:40:37 cezeriserver caddy[793]: {"level":"debug","ts":1650901237.902207,"logger":"http.reverse_proxy.transport.fastcgi","msg":"roundtrip","request":{"remote_addr":"176.88.87.31:28926","proto":"HTTP/2.0","method":"POST","host":"paste.cezeri.tech","uri":"/index.php","headers":{"Content-Length":["201"],"Sec-Fetch-Site":["same-origin"],"Te":["trailers"],"User-Agent":["Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0"],"X-Requested-With":["JSONHttpRequest"],"Origin":["https://paste.cezeri.tech"],"Accept":["application/json, text/javascript, */*; q=0.01"],"Content-Type":["application/x-www-form-urlencoded; charset=UTF-8"],"Sec-Fetch-Dest":["empty"],"X-Forwarded-For":["176.88.87.31"],"Accept-Language":["en-US,en;q=0.5"],"Accept-Encoding":["gzip, deflate, br"],"Sec-Fetch-Mode":["cors"],"X-Forwarded-Proto":["https"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"paste.cezeri.tech"}},"dial":"/run/php-fpm.sock","env":{"AUTH_TYPE":"","CONTENT_LENGTH":"201","CONTENT_TYPE":"application/x-www-form-urlencoded; charset=UTF-8","DOCUMENT_ROOT":"/var/www/PrivateBin-1.4.0","DOCUMENT_URI":"/index.php","GATEWAY_INTERFACE":"CGI/1.1","HTTPS":"on","HTTP_ACCEPT":"application/json, text/javascript, */*; q=0.01","HTTP_ACCEPT_ENCODING":"gzip, deflate, br","HTTP_ACCEPT_LANGUAGE":"en-US,en;q=0.5","HTTP_CONTENT_LENGTH":"201","HTTP_CONTENT_TYPE":"application/x-www-form-urlencoded; charset=UTF-8","HTTP_HOST":"paste.cezeri.tech","HTTP_ORIGIN":"https://paste.cezeri.tech","HTTP_SEC_FETCH_DEST":"empty","HTTP_SEC_FETCH_MODE":"cors","HTTP_SEC_FETCH_SITE":"same-origin","HTTP_TE":"trailers","HTTP_USER_AGENT":"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0","HTTP_X_FORWARDED_FOR":"176.88.87.31","HTTP_X_FORWARDED_PROTO":"https","HTTP_X_REQUESTED_WITH":"JSONHttpRequest","PATH_INFO":"","QUERY_STRING":"","REMOTE_ADDR":"176.88.87.31","REMOTE_HOST":"176.88.87.31","REMOTE_IDENT":"","REMOTE_PORT":"28926","REMOTE_USER":"","REQUEST_METHOD":"POST","REQUEST_SCHEME":"https","REQUEST_URI":"/","SCRIPT_FILENAME":"/var/www/PrivateBin-1.4.0/index.php","SCRIPT_NAME":"/index.php","SERVER_NAME":"paste.cezeri.tech","SERVER_PROTOCOL":"HTTP/2.0","SERVER_SOFTWARE":"Caddy/v2.4.6","SSL_CIPHER":"TLS_AES_128_GCM_SHA256","SSL_PROTOCOL":"TLSv1.3"}}
Apr 25 15:40:37 cezeriserver caddy[793]: {"level":"debug","ts":1650901237.9059348,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"unix//run/php-fpm.sock","duration":0.003903917,"request":{"remote_addr":"176.88.87.31:28926","proto":"HTTP/2.0","method":"POST","host":"paste.cezeri.tech","uri":"/index.php","headers":{"Sec-Fetch-Mode":["cors"],"X-Forwarded-Proto":["https"],"Accept-Language":["en-US,en;q=0.5"],"Accept-Encoding":["gzip, deflate, br"],"Te":["trailers"],"Content-Length":["201"],"Sec-Fetch-Site":["same-origin"],"Origin":["https://paste.cezeri.tech"],"User-Agent":["Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0"],"X-Requested-With":["JSONHttpRequest"],"Sec-Fetch-Dest":["empty"],"X-Forwarded-For":["176.88.87.31"],"Accept":["application/json, text/javascript, */*; q=0.01"],"Content-Type":["application/x-www-form-urlencoded; charset=UTF-8"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"paste.cezeri.tech"}},"headers":{"Content-Type":["application/json"],"Access-Control-Allow-Origin":["*"],"Access-Control-Allow-Methods":["GET, POST, PUT, DELETE"],"Access-Control-Allow-Headers":["X-Requested-With, Content-Type"]},"status":200}

Well, that looks good to me. PHP ran, and returned a 200 status response.

You’ll need to be more specific about what’s not working.

This doesn’t look like a Caddy problem to me. If you’re having issues, it’s probably a misconfiguration of your PHP app.

1 Like

Okay, thank you for your help and sorry for inconvenience.

There’s no inconvenience, we’re here to help. I’m just saying there’s not much we can do to help with the currently available information.

2 Likes

Thanks. The problem was the folder permissions. I gave the right permissions to the folder and now it’s working.

2 Likes

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