Project

General

Profile

[Solved] file extensions processed by PHP

Added by frankieandshadow about 8 years ago

I have an api which uses endpoints such as example1.json and example2.zip. Both are (should be) actually run by the PHP interpreter to produce their results, the suffix suggesting the type of the result (though of course this isn't definitive: the Content-type header in the result determines that). Some have query parameters in the URL, others don't.

The json ones work fine, but the zip one produces a 503 error before it even reaches my code. I can't find any error logs which give any more information. If I try an extension like "zipp" instead, it delivers the PHP source code so clearly it isn't being directed to fastcgi-php.

As json works, I'm really puzzled, since I basically do the same for both:

I have (not including zipp):
fastcgi.map-extensions = ( ".zip" => ".php", ".json" => ".php" )
in the lighttpd.config, and the following in confs-available/15--fastcgi-php.conf (which is, of course, enabled; I'm not actually using xml):

fastcgi.server += ( ".php" =>
((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/lighttpd.socket",
"max-procs" => 1,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"bin-copy-environment" => (
"PATH", "SHELL", "USER"
),
"broken-scriptfilename" => "enable"
)),
".html" =>
((
"socket" => "/tmp/lighttpdphp.socket",
)),
".xml" =>
((
"socket" => "/tmp/lighttpdphp.socket",
)),
".json" =>
((
"socket" => "/tmp/lighttpdphp.socket",
)),
".zip" =>
((
"socket" => "/tmp/lighttpdphp.socket",
))
)

This is lighttpd/1.4.35 running on a Raspberry Pi 2 under Raspian Jessie (in effect, Debian).

Any idea what I'm doing wrong? Is there something special about .zip extensions, or some reason it would differ from .json?


Replies (4)

RE: file extensions processed by PHP - Added by gstrauss about 8 years ago

Any reason for the spelling distinction between /tmp/lighttpd.socket and /tmp/lighttpdphp.socket ? You have both in your config. Also, with the map-extensions, specifying fastcgi.server config for ".json" and ".zip" is somewhat confusing. And you have some extra parenthesis. Would you try the following?

fastcgi.map-extensions = (
  ".zip"  => ".php",
  ".json" => ".php",
  ".html" => ".php",
  ".xml"  => ".php" 
)

fastcgi.server += ( 
  ".php" => (
    "bin-path" => "/usr/bin/php-cgi",
    "socket" => "/tmp/lighttpd.socket",
    "max-procs" => 1, 
    "bin-environment" => (
      "PHP_FCGI_CHILDREN" => "4",
      "PHP_FCGI_MAX_REQUESTS" => "10000" 
    ),
    "bin-copy-environment" => (
      "PATH", "SHELL", "USER" 
    ),
    "broken-scriptfilename" => "enable" 
  )
)

RE: file extensions processed by PHP - Added by frankieandshadow about 8 years ago

Thanks for your advice. I had stared at the fastcgi.server for ages without noticing the filenames were different, though it seems they were irrelevant anyway. I can't now recall where I got that recipe from. The double brackets were in the original sample file.

However, it still didn't work, and in the end I decided it simply wasn't taking any notice of changes I was making, so I rebooted the server. After that lighttpd failed to start at all. No error messages, no log files, syntax reported OK, a 255 exit code was the only clue. The only thing that got lighttpd started was disabling fastcgi-php module, which of course defeated the point, though narrowed down where the problem could be. After 4 hours of banging my head against a brick wall, reinstalling everything, adding fastcgi.debug, trying variations on the configuration, and going back to the configuration I know worked at least for all but .zip files, I gave up and went back to Apache which took about 15 minutes to install and configure.

RE: file extensions processed by PHP - Added by gstrauss about 8 years ago

Sorry about your experience. Glad you have a working solution, even if it's not lighttpd.

Mea culpa. The solution I gave you above was broken. :( I had tested it in my lighttpd.conf and started up lighttpd, but hadn't enabled mod_fastcgi. When I did enable mod_fastcgi, and ran lighttpd -f lighttpd.conf -tt (feature on tip of master branch), it reported:
2016-04-11 12:46:55: (mod_fastcgi.c.1296) unexpected type for key: fastcgi.server [bin-path](string)

The config was missing a serverkey, and I'm going to dive into the parser to see if this error can be detected better.
This might work better for you:

fastcgi.map-extensions = (
  ".zip"  => ".php",
  ".json" => ".php",
  ".html" => ".php",
  ".xml"  => ".php" 
)

fastcgi.server += (
  ".php" => ( "missing-server-key-name" => (
    "socket" => "/tmp/lighttpd.socket",
    "bin-path" => "/usr/bin/php-cgi",
    "max-procs" => 1,
    "bin-environment" => (
      "PHP_FCGI_CHILDREN" => "4",
      "PHP_FCGI_MAX_REQUESTS" => "10000" 
    ),
    "bin-copy-environment" => (
      "PATH", "SHELL", "USER" 
    ),
    "broken-scriptfilename" => "enable" 
  ))
)

RE: [Solved] file extensions processed by PHP - Added by gstrauss about 7 years ago

lighttpd 1.4.46 emits improved diagnostics when parenthesis are misplaced in config directives such as fastcgi.server.

    (1-4/4)