PHP : No input file specified

(b2c) #1

I’m able to setup php 7 with Caddy.

on startup C:\php\php-cgi.exe -b 9999 &
fastcgi / 127.0.0.1:9999 php {
index index.php
}

It’s working perfectly. But when there is no php file, it shows:

No input file specified.

I can solve this by forwarding all 404 to root.

rewrite {
to {path} {path}/ /
}

But It doesn’t work with my proxy configuration. It also treats my proxy url as 404!

proxy /tv localhost:2002 {

}

How to solve it? Thanks in advance.

(Matthew Fay) #2

Hi @b2c,

With the php preset for fastcgi, you shouldn’t get a 404 from PHP. Caddy should only be sending requests to PHP if the request is for a .php file or if it’s an index request with index.php present.

You can remove index index.php, it’s redundant with the php preset.

You can stop rewrite from affecting your proxy by excluding the proxy path from the rewrite.

rewrite {
  if {path} not_starts_with /tv
  to {path} {path}/ /
}
1 Like
(b2c) #3

Thanks @Whitestrake, it’s working now. I fixed the fastcgi redundant part.

About redirecting, how to show 404 status if PHP file is missing? I don’t want to redirect every 404.

(Matthew Fay) #4

Just remove the rewrite if you don’t want to have 404s sent to the web root index.

(b2c) #5

@Whitestrake Okay if I remove the rewrite scope, for missing php file it shows this:

No input file specified

I want to replace this with 404 status.

(Matthew Fay) #6

Based on some previous discussion:

My understanding is that Caddy is sending a 404 status, but the body is coming from upstream (FastCGI), not the default one provided by Caddy (or a custom one if you’ve specified it).

Tagging @abiosoft, did anything come of that? I did a quick search for issues but nothing seemed strictly related.

Assuming there’s no issue currently tracked for this, @b2c, you may wish to open up a new one for the current behaviour to be changed.

(b2c) #7

@Whitestrake You’re right. Status is 404 with this ‘confusing’ body.

I tried this too.

  errors {
	404 404.html
  }

But this doesn’t trigger on missing php file’s 404!