Showing posts with label LightTPD. Show all posts
Showing posts with label LightTPD. Show all posts

Wednesday, May 21, 2008

ruby script/server lighttpd

在一个jruby on rails目录下面运行以下命令时报错:
$> ruby script/server lighttpd
.....
Couldn't find any pid file in '/Users/yu/Sites/RubyOnRails/tmp/pids' matching 'dispatch.[0-9]*.pid'
(also looked for processes matching "/Users/yu/Sites/RubyOnRails/public/dispatch.fcgi")
在lighttpd的log中看到如下信息:
2008-05-21 00:23:33: (log.c.75) server started
2008-05-21 00:23:33: (mod_fastcgi.c.1029) the fastcgi-backend /Users/yu/Sites/RubyOnRails/public/dispatch.fcgi failed to start:
2008-05-21 00:23:33: (mod_fastcgi.c.1033) child exited with status 9 /Users/yu/Sites/RubyOnRails/public/dispatch.fcgi
2008-05-21 00:23:33: (mod_fastcgi.c.1036) If you're trying to run PHP as a FastCGI backend, make sure you're using the FastCGI-enabled version.
You can find out if it is the right one by executing 'php -v' and it should display '(cgi-fcgi)' in the output, NOT '(cgi)' NOR '(cli)'.
For more information, check http://trac.lighttpd.net/trac/wiki/Docs%3AModFastCGI#preparing-php-as-a-fastcgi-programIf this is PHP on Gentoo, add 'fastcgi' to the USE flags.
2008-05-21 00:23:33: (mod_fastcgi.c.1340) [ERROR]: spawning fcgi failed.
2008-05-21 00:23:33: (server.c.908) Configuration of plugins failed. Going down.

经google后才发觉script/server lighttpd只能用于ruby on rails的项目上,通过以下命令:
$> /usr/local/lighttpd/bin/spawn-fcgi -f /Users/yu/Sites/RubyOnRails/public/dispatch.fcgi -p 12000 -s /tmp/rails-fcgi.socket
会得到成功的结果如下:
spawn-fcgi.c.197: child spawned successfully: PID: 2275
而在jruby的项目下调用spawn-fcgi则会报脚本错误。

另附dispatch.sh[reference: http://www.javaeye.com/topic/168989]


#!/bin/sh

DISPATCH_PATH=/Users/yu/Sites/cv2/public/dispatch.fcgi
SOCKET_PATH=//Users/yu/Sites/cv2/tmp/sockets
RAILS_ENV=developement
export RAILS_ENV

case "$1" in

start)
for num in 0 1 2
do
/Users/yu/Programs/lighttpd/bin/spawn-fcgi -f $DISPATCH_PATH -s $SOCKET_PATH/rails.socket-$num
done
;;

stop)
killall -9 dispatch.fcgi
;;

restart)
$0 stop
$0 start
;;

*)
echo "Usage: dispatch.sh {start|stop|restart}"
;;

esac

exit 0

Thursday, April 24, 2008

rails2.0.2 fastcgi sqlite3 setup

# add below line to /etc/hosts
127.0.0.1 www.test.com

# add below green lines at the end of lighttpd.conf file


$HTTP["host"] == "www.test.com" {
server.document-root = "/Users/test/Sites/RubyOnRails/public"
server.errorlog = "/Users/test/Sites/lighttpd/logs/rails.lighttpd.error.log"
server.indexfiles = ( "dispatch.fcgi", "index.html" )
accesslog.filename = "/Users/test/Sites/lighttpd/logs/rails.access.log"
server.error-handler-404 = "/dispatch.fcgi"
fastcgi.server = ( ".fcgi" =>
( "localhost" =>
(
"socket" => "/tmp/rails-fastcgi.socket",
"bin-path" => "/Users/test/Sites/RubyOnRails/public/dispatch.fcgi",
"bin-environment" => ("RAILS_ENV" => "development"),
"max-procs" => 3,
"min-procs" => 1
)
)
)
}

wget http://www.sqlite.org/sqlite-3.5.8.tar.gz
tar zxvf sqlite-3.5.8.tar.gz
cd sqlite-3.5.8
./configure --prefix=/usr/local/sqlite358
make
sudo make install

# create db files under rails app db folder
cd /Users/test/Sites/RubyOnRails/db
/usr/local/sqlite358/bin/sqlite3 development.sqlite3
/usr/local/sqlite358/bin/sqlite3 test.sqlite3
/usr/local/sqlite358/bin/sqlite3 production.sqlite3

sudo gem install sqlite3-ruby

# restart lighttpd, and request url: http://www.test.com

Wednesday, April 23, 2008

lighttpd php fastcgi and 500 internal error

当访问php页面时,得到一个500服务器内部错误(500 internal error ),服务器端错误日志如下:


2008-04-23 23:20:50: (mod_fastcgi.c.1743) connect failed: Connection refused on unix:/tmp/php-fastcgi.socket-3
2008-04-23 23:20:50: (mod_fastcgi.c.2912) backend died; we'll disable it for 5 seconds and send the request to another backend instead: reconnects: 0 load: 1
2008-04-23 23:20:50: (mod_fastcgi.c.2471) unexpected end-of-file (perhaps the fastcgi process died): pid: 350 socket: unix:/tmp/php-fastcgi.socket-3
2008-04-23 23:20:50: (mod_fastcgi.c.3281) response not received, request sent: 872 on socket: unix:/tmp/php-fastcgi.socket-3 for /php/phpinfo.php , closing connection

用lighttpd fastcgi模式调用php时报以上错误,在lighttpd官方网站上查到,是因为php在编译时未指定--enable-fastcgi, 于是重新编译了最新版的php5.2.5:

./configure --prefix=/usr/local/php5 --with-zlib --enable-fastcgi --with-mysql=/usr/local/mysql --enable-mbstring --enable-sockets --enable-gd-native-ttf --with-snmp --enable-soap
make
sudo make install

重启lighttpd之后即可正确访问php文件。

lighttpd install and configure

# install libevent
curl -O http://www.monkey.org/~provos/libevent-1.4.3-stable.tar.gz
tar xzvf libevent-1.4.3-stable.tar.gz
cd libevent-1.4.3-stable
./configure --prefix=/usr/local/libevent143
make
sudo make install

# install memcached
curl -O http://www.danga.com/memcached/dist/memcached-1.2.5.tar.gz
tar xzvf memcached-1.2.5.tar.gz
cd memcached-1.2.5
./configure --prefix=/usr/local/memcached125 --with-libevent=/usr/local/libevent143
make
sudo make install

#install pcre in order to install lighttpd
curl -O ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-6.6.tar.gz
tar zxvf pcre-6.6.tar.gz
cd pcre-6.6
./configure --prefix=/usr/local/pcre66
make
sudo make install

#modify PATH include /usr/local/pcre66/bin, add below command to .bashrc or .profile or .bash_profile etc.
$> export PATH="/usr/local/pcre66/bin:$PATH"

# install lighttpd
curl -O http://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz
tar zxvf lighttpd-1.4.19.tar.gz
cd lighttpd-1.4.19
./configure --prefix=/usr/local/lighttpd1419 --with-zlib --with-pcre --with-openssl
make
sudo make install

# lighttpd.conf example


server.modules = (
"mod_rewrite",
"mod_redirect",
"mod_fastcgi",
"mod_proxy",
"mod_userdir",
"mod_cgi",
"mod_usertrack",
"mod_accesslog"
)

server.name = "localhost"
server.document-root = "/Users/test/Sites/Public"
server.errorlog = "/Users/test/Sites/lighttpd/logs/lighttpd.error.log"
accesslog.filename = "/Users/test/Sites/lighttpd/logs/access.log"

server.port = 80

server.username = "test"
server.groupname = "admin"

mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".jpg" => "image/jpeg",
".png" => "image/png"
)

static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" )
index-file.names = ( "index.html" )

$HTTP["host"] == "www.test.com" {
server.document-root = "/Users/test/Sites/CakePHP/"
}

### for PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/php5/bin/php-cgi"
)
)
)

### CGI module
cgi.assign = ( ".pl" => "/usr/bin/perl",
".cgi" => "/usr/bin/perl",
".py" => "/usr/bin/python",
".rb" => "/usr/local/ruby186/bin/ruby"
)

# lighttpd server start
$> /usr/local/lighttpd1419/sbin/lighttpd -f lighttpd.conf

Monday, April 21, 2008

install fastcgi and ruby-fastcgi

curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar xzvf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure --prefix=/usr/local/fcgi240
make
sudo make install
cd ..

# install Ruby-FastCGI gem

curl -O http://rubyforge.iasi.roedu.net/files/fcgi/ruby-fcgi-0.8.7.tar.gz
tar xzvf ruby-fcgi-0.8.7.tar.gz
cd ruby-fcgi-0.8.7
/usr/local/bin/ruby install.rb config -- --with-fcgi-dir=/usr/local/fcgi240
/usr/local/bin/ruby install.rb setup
sudo /usr/local/bin/ruby install.rb install
cd ..

# or install Ruby-FastCGI gem using:
$> sudo gem install fcgi -- --with-fcgi-dir=/usr/local/fcgi240

# Building native extensions. This could take a while...
# Successfully installed fcgi-0.8.7
# 1 gem installed