PHP : No input file specified

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.

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

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.

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

@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.

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.

@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!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.