커뮤니티 정보

제목 lighttpd + php by mod_proxy_backend_fastcgi Linux
등록자 admin 등록일 2008.01.28 16:59:40 접속 63690
lighttpd + php by mod_proxy_backend_fastcgi Linux
2008/01/06 00:31

http://blog.naver.com/whcarrot/46039483


apache 서버를 lighttpd로 변환하면서 php의 실행을 일반적으로 lighttpd에서 하는 방식인 fastcgi방식이 아닌 mod_proxy_backend_fastcgi으로 구현하였다.



이유는 다른웹서버가 이미 그렇게 세팅되어있기 때문이었는데 이것때문에 일주일이나 지체하였다 -_-



fastcgi는 영어로나마 여기저기 설치 방법이 존재했지만 mod_proxy_backend_fastcgi는 거의 존재하지 않아서 중국어로 된 페이지와 lighttpd 설치 폴더의 doc/fastcgi.txt를 뒤진끝에 방법을 찾아내게되었다.



[a] Make sure you have Lighttpd v1.5.xx installed

[b] spawn-fcgi binary (part of lighttpd software) to spawns fastcgi processes. It is used to spawn remote/local FastCGI processes such as PHP or ruby.

[c] PHP compiled / installed as fastcgi. Type the following command to verify that php is installed as fastcgi binary (look for cgi-fcgi word):
$ php-cgi -v
OR
$ php -v
Output:

PHP 5.1.6 (cgi-fcgi) (built: Mar 9 2007 07:25:36)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
mod_proxy_backend_fastcgi configuration
Open configuration file /etc/lighttpd/lighttpd.conf
# vi /etc/lighttpd/lighttpd.conf
Make sure following modules are loaded:
server.modules += ( "mod_proxy_core", "mod_proxy_backend_fastcgi" )

Configure fastcgi PGP module by appending following configuration directives:

$HTTP["url"] =~ ".php$" {
proxy-core.balancer = "round-robin"
proxy-core.allow-x-sendfile = "enable"
proxy-core.check-local = "enable"
proxy-core.protocol = "fastcgi"
proxy-core.backends = ( "unix:/tmp/php-fastcgi.sock" )
proxy-core.max-pool-size = 16
}
/usr/bin/spawn-fcgi -s /tmp/php-fastcgi.sock -f /usr/bin/php-cgi -u lighttpd -g lighttpd -C 5 -P /var/run/spawn-fcgi.pid
그런데 여기서 [b]부분이 문제였다. 방금 이 글 쓰면서 뒷부분에 b에 대한 언급이 있다는걸 알았지만 -_- 어쨋든 찾아낸 방법에 의하면



#!/bin/bash
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/usr/local/lighttpd/bin/spawn-fcgi" #<===修改这个,找到你的lighttpd相应目录中的spawn-fcgi
## ABSOLUTE path to the PHP binary
FCGIPROGRAM="/usr/php/bin/php" #<===修改为你的PHP路径,注意并非目录
## TCP port to which to bind on localhost
FCGIPORT="1026" #<===端口,一会多backends需要修改
## number of PHP children to spawn
PHP_FCGI_CHILDREN=10
## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=1000
## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1" #<===如果前台httpd非本机,请填写前台服务器相应IP
# allowed environment variables, separated by spaces
ALLOWED_ENV="ORACLE_HOME PATH USER"
## if this script is run as root, switch to the following user
USERID=lighttpd #<===运行用户
GROUPID=lighttpd

################## no config below this line
if test x$PHP_FCGI_CHILDREN = x; then
PHP_FCGI_CHILDREN=5
fi
export PHP_FCGI_MAX_REQUESTS
export FCGI_WEB_SERVER_ADDRS
ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
if test x$UID = x0; then
EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -u $USERID -g $GROUPID -C $PHP_FCGI_CHILDREN"
else
EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -C $PHP_FCGI_CHILDREN"
fi
# copy the allowed environment variables
E=
for i in $ALLOWED_ENV; do
E="$E $i=${!i}"
done

# clean the environment and set up a new one
env - $E $EX



빨간 부분이나 중국어 사이트에서 찾아낸 방법이나 결국 동일한 것이다. 그러나 그걸 모르고 중국어 사이트에서 찾아댔으니 -_-



어쨋든 결론은

1. lighttpd 설치

2. php 설치

3. lighttpd 설정 변경

4. spawn-cgi 실행
... 자료없음 ...