lighttpd forum lighty > Lighttpd + FastCGI PHP issues with bin-path

Posted by D. Suchter
on 14.10.2008 07:22
I'm having a hard time getting FastCGI to execute using the right 
version of PHP. I've got a few installs of PHP on my machine, and I need 
to keep it that way, unfortunately. With that said, all my vhosts should 
all be using the same PHP copy via FastCGI.

The weird thing is that my FastCGI config seems happy, and if I run 
lighty by hand with '-D' I can clearly see the FastCGI process start up 
as expected. The odd part is that the 'bin-path' setting seems to be 
ignored!!

Let's clarify. Here's some relevant code from my lighttpd.conf:
[code]
      1 # lighttpd configuration file
      2 #
      3 # use it as a base for lighttpd 1.0.0 and above
      4 #
      5 # $Id: lighttpd.conf,v 1.7 2004/11/03 22:26:05 weigon Exp $
      6
      7 ############ Options you really have to take care of 
####################
      8
      9 ## modules to load
     10 # at least mod_access and mod_accesslog should be loaded
     11 # all other module should only be loaded if really neccesary
     12 # - saves some time
     13 # - saves memory
     14 server.modules              = (
     15                                 "mod_rewrite",
     16                                 "mod_redirect",
     17                                 "mod_alias",
     18                                 "mod_access",
     19 #                               "mod_cml",
     20 #                               "mod_trigger_b4_dl",
     21                                 "mod_auth",
     22                                 "mod_status",
     23                                 "mod_setenv",
     24                                 "mod_fastcgi",
     25 #                               "mod_proxy",
     26                                 "mod_simple_vhost",
     27 #                               "mod_evhost",
     28 #                               "mod_userdir",
     29 #                               "mod_cgi",
     30 #                               "mod_compress",
     31 #                               "mod_ssi",
     32 #                               "mod_usertrack",
     33 #                               "mod_expire",
     34 #                               "mod_secdownload",
     35 #                               "mod_rrdtool",
     36                                 "mod_accesslog" )
     37
     38 ## a static document-root, for virtual-hosting take look at the
     39 ## server.virtual-* options
     40 server.document-root        = "/srv/www/htdocs/"
     41
     42 ## where to send error-messages to
     43 server.errorlog             = "/var/log/lighttpd/error.log"
     44
     45 # files to check for if .../ is requested
     46 index-file.names            = ( "index.php", "index.html",
     47                                 "index.htm", "default.htm" )
     48
     49 ## set the event-handler (read the performance section in the 
manual)
     50 # server.event-handler = "freebsd-kqueue" # needed on OS X
     51
     52 # mimetype mapping
     53 mimetype.assign             = (
     54   ".pdf"          =>      "application/pdf",
…
    131 ##
    132 # which extensions should not be handle via static-file transfer
    133 #
    134 # .php, .pl, .fcgi are most often handled by mod_fastcgi or 
mod_cgi
    135 static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
    136
…
    451 simple-vhost.server-root   = "/srv/www/vhosts/"
    452 simple-vhost.default-host  = "www.foo.com"
    453 simple-vhost.document-root = "/htdocs/"
…
    497 ### fastcgi module
    498 # read fastcgi.txt for more info
    499 # for PHP don't forget to set cgi.fix_pathinfo = 1 in the 
php.ini
    500  fastcgi.debug = 1
    501  fastcgi.server             = ( ".php" =>
    502                                 ( "localhost" =>
    503                                   (
    504                                     "socket" => 
"/tmp/php-fastcgi.socket",
    505                                     "bin-path" => 
"/usr/bin/php-cgi"
    506                                   )
    507                                 )
    508                              )
[/code]

My PHP info says I'm using PHP v5.2.5 and /etc/php.ini is my ini file. 
However, changes to my php.ini have no effect whatsoever (that's what 
tipped me off to this problem). I can't even find a version of PHP on my 
system that claims to be 5.2.5, so I'm at a loss for which binary is 
actually getting executed. I've tried changing the bin-path arg and as 
far as I can tell it has to be set to a genuine copy of PHP-CGI (perhaps 
just a file with the proper mode, I'm not sure), but it doesn't actually 
execute the file I specify.

[code]
[user@host lighttpd]$ locate php-cgi
/usr/local/bin/php-cgi
/usr/bin/php-cgi
/opt/php-fcgi/bin/php-cgi
[user@host lighttpd]$ /usr/local/bin/php-cgi --version
PHP 5.2.4 (cgi-fcgi) (built: Oct 12 2007 18:11:38)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
[user@host lighttpd]$ /usr/bin/php-cgi --version
PHP Warning:  [eAccelerator] Can not create shared memory area in 
Unknown on line 0
PHP Fatal error:  Unable to start eAccelerator module in Unknown on line 
0
[user@host lighttpd]$ /opt/php-fcgi/bin/php-cgi --version
PHP 5.2.4 (cgi-fcgi) (built: Nov 28 2007 00:05:30)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
[user@host lighttpd]$ /usr/bin/php --version
PHP 5.2.6 (cli) (built: May  2 2008 11:18:31)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
    with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by 
eAccelerator
    with the ionCube PHP Loader v3.1.32, Copyright (c) 2002-2007, by 
ionCube Ltd., and
    with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend 
Technologies
    with Suhosin v0.9.22, Copyright (c) 2007, by SektionEins GmbH
[/code]

I know that's a lot, but I wanted to do my best to describe this problem 
with a lot of detail since it seems so strange to me. Can someone please 
help me get FastCGI to execute the correct copy of PHP? (which should be 
/usr/bin/php-cgi).
Posted by D. Suchter
on 20.10.2008 18:13
*bump*

Nothing? I'm at the end of my rope here...
Posted by Olaf van der Spek
on 20.10.2008 19:36
D. Suchter wrote:
> *bump*
> 
> Nothing? I'm at the end of my rope here...

You could try strace to see exactly what Lighttpd is starting.
Posted by D. Suchter
on 21.10.2008 02:54
Good idea.

From what I can tell the bin-path arg is being seen by lighttpd, but 
again, not interpreted properly. Below is the strace output of lighty 
with the only config file difference being the bin-path. I grepped the 
output for the string "php." As you can see, lighty understood that I 
changed the bin-path, but both times it executes "php 5.2.5" (see the 
very end of the debug info). What I don't get is that I can't find a 
copy of php with that version on my system: I have 5.2.4, 5.2.6, and one 
copy that won't execute manually from the command line for me to check 
(see the first post for more details).

01_usr_bin_php.txt:219:	proc: /usr/bin/php-cgi
01_usr_bin_php.txt:221:	socket /tmp/php-fastcgi.socket
01_usr_bin_php.txt:227:	socket /tmp/php-fastcgi.socket
01_usr_bin_php.txt:231:connect(4, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-0"}, 27) = 0
01_usr_bin_php.txt:235:	socket /tmp/php-fastcgi.socket
01_usr_bin_php.txt:239:connect(4, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-1"}, 27) = 0
01_usr_bin_php.txt:243:	socket /tmp/php-fastcgi.socket
01_usr_bin_php.txt:247:connect(4, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-2"}, 27) = 0
01_usr_bin_php.txt:251:	socket /tmp/php-fastcgi.socket
01_usr_bin_php.txt:255:connect(4, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-3"}, 27) = 0
01_usr_bin_php.txt:377:read(21, "GET /info.php HTTP/1.1\r\nHost: ww"..., 
447) = 415
01_usr_bin_php.txt:380:stat64("/srv/www/vhosts/www.foo.com/htdocs/info.php", 
{st_mode=S_IFREG|0664, st_size=16, ...}) = 0
01_usr_bin_php.txt:381:open("/srv/www/vhosts/www.foo.com/htdocs/info.php", 
O_RDONLY|O_LARGEFILE) = 22
01_usr_bin_php.txt:386:connect(22, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-3"}, 27) = 0
01_usr_bin_php.txt:394:read(22, "\1\6\0\1\37\370\0\0X-Powered-By: 
PHP/5.2.5\r"..., 1888) = 1888
01_usr_bin_php.txt:452:read(22, "GET /info.php?=PHPE9568F34-D428-"..., 
511) = 471
01_usr_bin_php.txt:456:connect(23, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-3"}, 27) = 0
01_usr_bin_php.txt:463:read(23, "\1\6\0\1\n\20\0\0X-Powered-By: 
PHP/5.2.5\r"..., 1888) = 1888
01_usr_bin_php.txt:493:read(23, "GET /info.php?=PHPE9568F35-D428-"..., 
511) = 471
01_usr_bin_php.txt:497:connect(24, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-3"}, 27) = 0
01_usr_bin_php.txt:505:read(24, "\1\6\0\1\10\226\2\0X-Powered-By: 
PHP/5.2.5\r"..., 1888) = 1888
02_usr_local_bin_php.txt:219:	proc: /usr/local/bin/php-cgi
02_usr_local_bin_php.txt:221:	socket /tmp/php-fastcgi.socket
02_usr_local_bin_php.txt:227:	socket /tmp/php-fastcgi.socket
02_usr_local_bin_php.txt:231:connect(4, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-0"}, 27) = 0
02_usr_local_bin_php.txt:235:	socket /tmp/php-fastcgi.socket
02_usr_local_bin_php.txt:239:connect(4, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-1"}, 27) = 0
02_usr_local_bin_php.txt:243:	socket /tmp/php-fastcgi.socket
02_usr_local_bin_php.txt:247:connect(4, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-2"}, 27) = 0
02_usr_local_bin_php.txt:251:	socket /tmp/php-fastcgi.socket
02_usr_local_bin_php.txt:255:connect(4, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-3"}, 27) = 0
02_usr_local_bin_php.txt:384:read(21, "GET /info.php HTTP/1.1\r\nHost: 
ww"..., 447) = 415
02_usr_local_bin_php.txt:387:stat64("/srv/www/vhosts/www.foo.com/htdocs/info.php", 
{st_mode=S_IFREG|0664, st_size=16, ...}) = 0
02_usr_local_bin_php.txt:388:open("/srv/www/vhosts/www.foo.com/htdocs/info.php", 
O_RDONLY|O_LARGEFILE) = 22
02_usr_local_bin_php.txt:393:connect(22, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-3"}, 27) = 0
02_usr_local_bin_php.txt:402:read(22, "\1\6\0\1\37\370\0\0X-Powered-By: 
PHP/5.2.5\r"..., 1888) = 1888
02_usr_local_bin_php.txt:450:read(22, "GET 
/info.php?=PHPE9568F34-D428-"..., 511) = 471
02_usr_local_bin_php.txt:454:connect(23, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-3"}, 27) = 0
02_usr_local_bin_php.txt:462:read(23, "\1\6\0\1\n\20\0\0X-Powered-By: 
PHP/5.2.5\r"..., 1888) = 1888
02_usr_local_bin_php.txt:497:read(23, "GET 
/info.php?=PHPE9568F35-D428-"..., 511) = 471
02_usr_local_bin_php.txt:501:connect(24, {sa_family=AF_FILE, 
path="/tmp/php-fastcgi.socket-3"}, 27) = 0
02_usr_local_bin_php.txt:508:read(24, "\1\6\0\1\10\226\2\0X-Powered-By: 
PHP/5.2.5\r"..., 1888) = 1888