Lighttpd 1.4.32 + PHP 5.4.14(cgi-fcgi) + Mysql 5.5.30 howto

Even MBL does not have mysql installed by default,  there is config folder at /etc/mysql.

This leftover seems come with the firmware, it’s not perfectly clean. 

If you compile a new mysql source code by default it’s installed to /opt, for my example /opt/mysql-5.5.30

mysqld will search config files in the order /etc/my.cnf /etc/mysql/my.cnf /opt/mysql-5.5.30/etc/my.cnf ~/.my.cnf

It will pick up the wrong config if you put your config as /opt/mysql-5.5.30/my.cnf or /opt/mysql-5.5.30/etc/my.cnf 

In such case, the original config should be removed or renamed.

mybook:/opt/mysql-5.5.30# mv /etc/mysql /etc/mysql_org


After the latest update that you did, did you reset the device?

Please note that is always recommended to reset the device to make sure that you dont keep any information from the previews firmware.

Thank you for the reply.

I didn’t try the latest update yet but still with MyBookLive 02.41.05-034, because I have done a lot customization on it.

Currently I’m running a custom php web application on it 7x24 I can access from both my office and home.

The web is supported by a customized combination of lighttpd 1.4.32 + PHP 5.4.14(cgi-fcgi) + Mysql Ver 14.14 Distrib 5.5.30.

All works perfectly.

Hmm that would make for an interesting guide :wink:

nfo, I may not be able to create a nice guide.  It took me a whole weekend(two days) to complete it and there are many steps and a bunch of tweaks,  I can’t realy remember exactly all of them. but I do have most of the major things recorded in text file, I can post it when I am at home.

Just took some time to tidy up my notes and try including as much as I can remember, hopefully it helps a bit

============================================================Versions installed
----compile tools.
gcc --version gcc (Debian 4.6.3-14) 4.6.3
g++ --version g++ (Debian 4.6.3-14) 4.6.3
autoconf --version autoconf (GNU Autoconf) 2.6
automake --version automake (GNU automake) 1.11.6
make --version GNU Make 3.81
libtool --version libtool (GNU libtool) 2.4.2
re2c --version re2c 0.13.5
flex --version flex 2.5.35
m4 --version m4 (GNU M4) 1.4.16
bison --version bison (GNU Bison) 2.5
------------------------------------------------------------after installation
/usr/local/sbin/lighttpd -v lighttpd/1.4.32
/usr/local/bin/php-cgi -v PHP 5.4.14(cgi-fcgi) Zend Engine v2.4.0
/opt/mysql-5.5.30/bin/mysql -V Ver 14.14 Distrib 5.5.30, for Linux (ppc) using EditLine wrapper

============================================================All steps in sequence

WD My Book Live 3TB Personal Cloud Storage - NAS - WDBACG0030HCH-NESN
Linux mybook #1 Thu May 17 13:32:51 PDT 2012 ppc GNU/Linux
CPU APM82181 800Mhz RAM 256M Harddriver 3TB
firmware: MyBookLive 02.41.05-034
bash -version 3.2.39

name of my mbl: mybook; ip fixed as:
============================================================aptitude/apt-get update
mybook:~# more /etc/apt/sources.list
deb squeeze main
deb wheezy main
#deb-src wheezy main
#deb sid main

mybook:~# aptitude update
mybook:~# apt-get update
Reading package lists… Done
W: GPG error: squeeze Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY AED4B06F473041FA
W: GPG error: wheezy Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY AED4B06F473041FA
W: You may want to run apt-get update to correct these problems

----fix, note to replace AED4B06F473041FA with your key
mybook:~# gpg --keyserver --recv-key AED4B06F473041FA
mybook:~# gpg -a --export AED4B06F473041FA | sudo apt-key add -

----this time it’s ok.
mybook:~# aptitude update

============================================================telnetd setup as a backup channel incase ssh dead
mybook:/# aptitude install telnetd
mybook:/# /usr/sbin/in.telnetd -debug 1111 &

============================================================GCC 4.6.3 (Debian 4.6.3-14)
mybook:~# aptitude install gcc
dpkg: error processing /var/cache/apt/archives/libc-bin_2.13-38_powerpc.deb (–unpack):
trying to overwrite ‘/etc/’, which is also in package wd-lib 01.04.01-81092

mybook:~# dpkg -i --force-overwrite /var/cache/apt/archives/libc-bin_2.13-38_powerpc.deb
Setting up libc-bin (2.13-38)
… OK

mybook:~# aptitude -f install
dpkg: error processing /var/cache/apt/archives/libc6_2.13-38_powerpc.deb (–unpack):
trying to overwrite ‘/etc/’, which is also in package wd-lib 01.04.01-81092

mybook:~# dpkg -i --force-overwrite /var/cache/apt/archives/libc6_2.13-38_powerpc.deb
Restarting services possibly affected by the upgrade:
samba: restarting…done.
cron: restarting…done.
apache2: restarting…done.

Services restarted successfully.

mybook:~# gcc --version
gcc (Debian 4.6.3-14) 4.6.3
Copyright © 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

------------------------------------------------------------autoconf 2.6
mybook:~# aptitude install autoconf
mybook:~# autoconf --version
autoconf (GNU Autoconf) 2.6
------------------------------------------------------------automake 1.11.6
mybook:~# automake --version
automake (GNU automake) 1.11.6
------------------------------------------------------------make 3.81
mybook:~# aptitude install make
mybook:~# make --version
GNU Make 3.81
Copyright © 2006 Free Software Foundation, Inc.
------------------------------------------------------------libtool 2.4.2
mybook:~# aptitude install libtool
mybook:~# libtool --version
libtool (GNU libtool) 2.4.2
Written by Gordon Matzigkeit, 1996
------------------------------------------------------------re2c 0.13.5
mybook:~# aptitude install re2c
mybook:~# re2c --version
re2c 0.13.5
------------------------------------------------------------flex 2.5.35
flex - A fast lexical analyzer generator.
mybook:~# aptitude install flex
mybook:~# flex --version
flex 2.5.35
------------------------------------------------------------m4 (GNU M4) 1.4.16
mybook:~# aptitude install m4
mybook:~# m4 --version
m4 (GNU M4) 1.4.16
------------------------------------------------------------bison 2.5
mybook:~# apt-cache search bison
mybook:~# aptitude install bison
mybook:~# bison --version
bison (GNU Bison) 2.5
Written by Robert Corbett and Richard Stallman

apt-cache search g++ | grep g++

aptitude install g++

g++ --version

g++ (Debian 4.6.3-14) 4.6.3

============================================================compile/install mysql
------------------------------------------------------------1. prepare dependencies
mybook:~# aptitude install ncurses
mybook:~# ls /lib/libnc*
/lib/ /lib/
------------------------------------------------------------2. install cmake
mkdir -p /DataVolume/shares/dev/mysql

cd /DataVolume/shares/dev/mysql


tar zfx cmake-

cd cmake-

mybook:/DataVolume/shares/dev/mysql/cmake- ./configure --prefix=/opt/cmake
mybook:/DataVolume/shares/dev/mysql/cmake- make
mybook:/DataVolume/shares/dev/mysql/cmake- make install
mybook:/DataVolume/shares/dev/mysql/cmake- /opt/cmake/bin/cmake -version
cmake version

------------------------------------------------------------3. get mysql source
mkdir -p /DataVolume/shares/dev/mysql
cd /DataVolume/shares/dev/mysql
mybook:/DataVolume/shares/dev/mysql# mv ~/mysql-5.5.30.tar.gz ./
mybook:/DataVolume/shares/dev/mysql# tar zfx mysql-5.5.30.tar.gz
mybook:/DataVolume/shares/dev/mysql# cd mysql-5.5.30

------------------------------------------------------------4. make
----my working options
cd /DataVolume/shares/dev/mysql/mysql-5.5.30


– Build files have been written to: /DataVolume/shares/dev/mysql/mysql-5.5.30
------------------------------------------------------------5. make/make install
mybook:/DataVolume/shares/dev/mysql/mysql-5.5.30# make
[100%] Built target my_safe_process

mybook:/DataVolume/shares/dev/mysql/mysql-5.5.30# make install
– Installing: /opt/mysql-5.5.30

------------------------------------------------------------6. mysql config,
groupadd mysql
useradd -r -g mysql mysql

add path: /opt/mysql-5.5.30/bin

vi ~/.bashrc

export PATH=/opt/mysql-5.5.30/bin:$PATH

----config file
cd /opt/mysql-5.5.30
cp ./support-files/my-medium.cnf ./my.cnf
vi my.cnf
character-set-server = utf8
collation-server = utf8_unicode_ci
init-connect=‘SET NAMES utf8’
character-set-server = utf8

----fix !
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /opt/mysql-5.5.30/etc/my.cnf ~/.my.cnf
! remove old config(coming with build.)
mybook:/opt/mysql-5.5.30# mv /etc/mysql /etc/mysql_org

----init db
mybook:/opt/mysql-5.5.30# scripts/mysql_install_db --character-set-server=utf8
mybook:/opt/mysql-5.5.30# ls data/mysql/
… will have many system tables created.

!! chown -R mysql:mysql data
mybook:/opt/mysql-5.5.30# chown -R mysql:mysql data
mybook:/opt/mysql-5.5.30# chmod -R 777 data
mybook:/opt/mysql-5.5.30# chown -R mysql:mysql data

----config: adding the following
root@mybook:/opt/mysql-5.5.30$ vi my.cnf
#password = your_password
port = 3306
socket = /tmp/mysql.sock

bind-address= <— your mbl ip
character-set-server = utf8
collation-server = utf8_unicode_ci
init-connect=‘SET NAMES utf8’
character-set-server = utf8

port = 3306
socket = /tmp/mysql.sock
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

------------------------------------------------------------7 startup/down/test connection
----test start
! change owner
mybook:/opt/mysql-5.5.30# chown -R mysql:mysql ./
—test run ok
mybook:/opt/mysql-5.5.30# bin/mysqld_safe --user=mysql &
[1] 21121
mysqld_safe Logging to ‘/opt/mysql-5.5.30/data/mybook.err’.
mysqld_safe Starting mysqld daemon with databases from /opt/mysql-5.5.30/data
mybook:/opt/mysql-5.5.30# ps -ef | grep mysql
root pts/0 /bin/sh bin/mysqld_safe --user=mysql
mysql pts/0 /opt/mysql-5.5.30/bin/mysqld --basedir=/opt/mysql-5.5.30 --datadir=/opt/mysql-5.5.30/data --plugin-dir=/opt/mysql-5.5.30/lib/plugin --user=mysql --log-error=/opt/mysql-5.5.30/data/mybook.err --pid-file=/opt/mysql-5.5.30/data/ --socket=/tmp/mysql.sock --port=3306
root pts/0 grep mysql
mybook:/opt/mysql-5.5.30# netstat -tunlp | grep 3306
tcp 0 0* LISTEN 21471/mysqld
mybook:/opt/mysql-5.5.30# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.30-log Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> show databases;
| Database |
| information_schema |
| mysql |
| performance_schema |
| test |
4 rows in set (0.00 sec)

mysql> quit
----create a table
mybook:/opt/mysql-5.5.30# mysql -u root --password=xxx --database=yourdb
mysql> create table X ( a integer primary key, b varchar(32) );
mysql> insert into X (a, b) values (1, ‘tt’ );
mysql> insert into X (a, b) values (2, ‘bb’ );
mysql> select * from X;

------------------------------------------------------------11. share mysql client lib to public.
! because the libs under /opt/mysql-5.5.30/lib/ are just owned by user mysql, and the folder is not in lib path
this caused php-cgi loading error when starting lighttpd.
$ sudo ls -l /opt/mysql-5.5.30/lib/
-rwxr-xr-- 1 mysql mysql 4282454 2013-04-13 20:14 /opt/mysql-5.5.30/lib/ <—owner: mysql:mysql

----copy mysql lib to /usr/lib and create links
cp /opt/mysql-5.5.30/lib/ /usr/lib
ln -s /usr/lib/ /usr/lib/
ln -s /usr/lib/ /usr/lib/
ln -s /usr/lib/ /usr/lib/
ln -s /usr/lib/ /usr/lib/
ln -s /usr/lib/ /usr/lib/

----mysql installation complete

============================================================Compile/install PHP

since the firmware php is just a apache2 module, this php installation will be the default php of the system.

----download source code to /DataVolume/shares/Public/php-5.4.14.tar.gz
mkdir -p /DataVolume/shares/dev/php
mybook:/DataVolume/shares/dev/php# mv …/…/Public/php-5.4.14.tar.gz ./
mybook:/DataVolume/shares/dev/php# tar -xzf php-5.4.14.tar.gz

----compile tools needed. just install and confirm one by one.
autoconf: 2.13+ (for PHP < 5.4.0), 2.59+ (for PHP >= 5.4.0)
automake: 1.4+
libtool: 1.4.x+ (except 1.4.2)
re2c: Version 0.13.4 or newer
flex: Version 2.5.4 (for PHP <= 5.2)
bison: Version 1.28 (preferred), 1.35, or 1.75

aptitude install autoconf

----dev components needed by php.
mybook:/DataVolume/shares/dev/php/php-5.4.14# aptitude install libssl-dev
mybook:/DataVolume/shares/dev/php/php-5.4.14# aptitude install lbzip2 bzip2 libzip-dev
aptitude install libdb5.1-dev
aptitude install libpng+±dev

----1. config para I am using
./configure --enable-debug --without-pear --enable-fpm --enable-sysvsem --enable-sysvshm --with-mhash --with-pcre-regex --enable-calendar --enable-dba --with-db4 --disable-pdo --without-pdo_sqlite --without-sqlite3 --with-mysql=/opt/mysql-5.5.30 --with-gettext --enable-mbstring --enable-mbregex --with-openssl --enable-ftp --enable-zip --with-zlib --with-gd=shared --with-png-dir=/usr

----2. make install
mybook:/DataVolume/shares/dev/php/php-5.4.14# make
mybook:/DataVolume/shares/dev/php/php-5.4.14# make install
Installing shared extensions: /usr/local/lib/php/extensions/debug-non-zts-20100525/
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/php/man/man1/
Installing PHP FPM binary: /usr/local/sbin/
Installing PHP FPM config: /usr/local/etc/
Installing PHP FPM man page: /usr/local/php/man/man8/
Installing PHP FPM status page: /usr/local/php/fpm/
Installing PHP CGI binary: /usr/local/bin/
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/man/man1/
page: phpize.1
page: php-config.1
/DataVolume/shares/dev/php/php-5.4.14/build/shtool install -c ext/phar/phar.phar /usr/local/bin
ln -s -f /usr/local/bin/phar.phar /usr/local/bin/phar

----3. test to get php info.
mybook:/DataVolume/shares/dev/php# php -r “phpinfo();” | more
----something like following
PHP Version => 5.4.14

System => Linux mybook #1 Thu May 17 13:32:51 PDT 2012 ppc
Configure Command => ‘./configure’ ‘–enable-debug’ ‘–without-pear’ ‘–enable-fpm’ ‘–enable-sysvsem’ ‘–enable-sysvshm’ ‘–with-mhash’ ‘–with-pcre-regex’ ‘–enable -calendar’ ‘–enable-dba’ ‘–with-db4’ ‘–disable-pdo’ ‘–without-pdo_sqlite’ ‘–without-sqlite3’ ‘–with-mysql=/opt/mysql-5.5.30’ ‘–with-gettext’ ‘–enable-mbstring’ ‘–enable-mbregex’ ‘–with-openssl’ ‘–enable-ftp’ ‘–enable-zip’ ‘–with-zlib’ ‘–with-gd=shared’ ‘–with-png-dir=/usr’
Server API => Command Line Interface
Virtual Directory Support => disabled

Configuration File (php.ini) Path => /usr/local/lib

Registered PHP Streams => https, ftps, compress.zlib, php, file, glob, data, http, ftp, phar, zip
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, sslv3, tls

extension_dir => /usr/local/lib/php/extensions/debug-non-zts-20100525
Default timezone => America/Toronto

DBA support => enabled
Supported handlers => cdb cdb_make db4 inifile flatfile

DOM/XML => enabled
DOM/XML API Version => 20031129
libxml Version => 2.8.0
HTML Support => enabled
XPath Support => enabled
XPointer Support => enabled
Schema Support => enabled
RelaxNG Support => enabled
Simplexml support => enabled

Regex Library => Bundled library enabled
fileinfo support => enabled
version => 1.0.5

FTP support => enabled
GetText Support => enabled
Hashing Engines => md2 md4 md5 sha1 sha224 sha256 sha384 sha512 ripemd128 ripemd160 ripemd256 ripemd320 whirlpool tiger128,3 tiger160,3 tiger192,3 tiger128,4 tiger160,4 tiger192,4 snefru snefru256 gost adler32 crc32 crc32b fnv132 fnv164 joaat haval128,3 haval160,3 haval192,3 haval224,3 haval256,3 haval128,4 haval160,4 haval192,4 haval 224,4 haval256,4 haval128,5 haval160,5 haval192,5 haval224,5 haval256,5

iconv implementation => glibc
json support => enabled
json version => 1.2.1
libXML Compiled Version => 2.8.0

Multibyte string engine => libmbfl

MySQL Support => enabled
Client API version => 5.5.30
MYSQL_SOCKET => /tmp/mysql.sock
MYSQL_INCLUDE => -I/opt/mysql-5.5.30/include
MYSQL_LIBS => -L/opt/mysql-5.5.30/lib -lmysqlclient

OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.0.1e 11 Feb 2013

PCRE (Perl Compatible Regular Expressions) Support => enabled
PCRE Library Version => 8.32 2012-11-30

Phar-based phar archives => enabled
Tar-based phar archives => enabled
ZIP-based phar archives => enabled
gzip compression => enabled
bzip2 compression => disabled (install pecl/bz2)
Native OpenSSL support => enabled

Tokenizer Support => enabled
libxml2 Version => 2.8.0
XMLReader => enabled
XMLWriter => enabled

Zip version => 1.11.0

--------now PHP compiled and installed.

============================================================test php connect to mysql.
mybook:/DataVolume/shares/dev/php# more ./testmysql.php

<? $host=""; $user="root"; $pass="xxx"; $db="yourdb"; $connect = mysql\_connect ( $host, $user, $pass ) ; if (! $connect ){ echo "ERROR connecting to $host
"; trigger\_error ( mysql\_error(), E\_USER\_ERROR ); return; } echo "connected.\r\n"; mysql\_select\_db($db) or die( "Unable to select database $db"); $sql="select \* from X"; $result = mysql\_query($sql); $num=mysql\_numrows($result); mysql\_close(); // echo "Got rows num=".$num."

\r\n"; $i=0; while ($i < $num) { $a=mysql\_result($result,$i,"a"); $b=mysql\_result($result,$i,"b"); echo " a=$a, b=$b
\r\n"; $i++; } echo "-------done."; ?>

mybook:/DataVolume/shares/dev/php# php ./testmysql.php
Got rows num=2

a=1, b=tt

a=2, b=bb


============================================================Install lighttpd and use fastcgi/php
--------download lighttpd
mybook:/DataVolume/shares/dev# mkdir /DataVolume/shares/dev/lighttpd/lighttpd
mybook:/DataVolume/shares/dev# cd /DataVolume/shares/dev/lighttpd/lighttpd/
mybook:/DataVolume/shares/dev/lighttpd# wget
mybook:/DataVolume/shares/dev/lighttpd# tar -xzf lighttpd-1.4.32.tar.gz
mybook:/DataVolume/shares/dev/lighttpd# cd lighttpd-1.4.32

aptitude install libpcre3-dev
aptitude install libghc-bzlib-dev
aptitude install libbz2-ocaml-dev
mybook:/DataVolume/shares/dev/lighttpd/lighttpd-1.4.32# ./configure
mybook:/DataVolume/shares/dev/lighttpd/lighttpd-1.4.32# make
mybook:/DataVolume/shares/dev/lighttpd/lighttpd-1.4.32# make install
Libraries have been installed in:
.libs/ ==> /usr/local/lib/
lighttpd ==> /usr/local/sbin/lighttpd

----check version
mybook:/DataVolume/shares/dev/lighttpd/lighttpd-1.4.32# /usr/local/sbin/lighttpd -v
lighttpd/1.4.32 - a light and fast webserver

mybook:~# cd /DataVolume/shares/dev/lighttpd

----1. create start/stop script /etc/init.d/lighttpd
mybook:/DataVolume/shares/dev/lighttpd# cp lighttpd-1.4.32/doc/initscripts/rc.lighttpd.redhat /etc/init.d/lighttpd
mybook:/DataVolume/shares/dev/lighttpd# sudo chmod a+rx /etc/init.d/lighttpd

----2. create system config /etc/sysconfig/lighttpd
mybook:/DataVolume/shares/dev/lighttpd# mkdir /etc/lighttpd
mybook:/DataVolume/shares/dev/lighttpd# cp -p lighttpd-1.4.32/doc/initscripts/sysconfig.lighttpd /etc/lighttpd/lighttpd
mybook:/DataVolume/shares/dev/lighttpd# chown root:root /etc/lighttpd/lighttpd
mybook:/DataVolume/shares/dev/lighttpd# more /etc/lighttpd/lighttpd

----3. create real config folder and config files
mybook:/DataVolume/shares/dev/lighttpd# cp -R lighttpd-1.4.32/doc/config/conf.d/ lighttpd-1.4.32/doc/config/*.conf lighttpd-1.4.32/doc/config/vhosts.d/ /etc/lighttpd/

----4. enable at system start , /etc/init.d/lighttpd
! not yet, seems I don’t need

----5. runtime folders and web root
mybook:/DataVolume/shares/dev/lighttpd# mkdir /DataVolume/shares/lighttpdweb
mybook:/DataVolume/shares/dev/lighttpd# cd /DataVolume/shares/lighttpdweb
mybook:/DataVolume/shares/lighttpdweb# mkdir webroot webroot/htdocs home home/sockets cache tmp
root@mybook:~$ mkdir /var/log/lighttpd
root@mybook:~$ chown lighttpd:lighttpd /var/log/lighttpd

mybook:/DataVolume/shares/lighttpdweb# vi webroot/htdocs/index.html

My First Heading

My first paragraph.

----6. modify config file to use folders just created.

----6.1. /etc/lighttpd/lighttpd.conf
vi /etc/lighttpd/lighttpd.conf
server.port = 6666
server.use-ipv6 = “disable”
server.bind = “” <— your ip

server.username = “lighttpd”
server.groupname = “lighttpd”

server.max-fds = 2048 <== max of system support – should be 4096 or 8192, 
server.max-connections = 256 <== max connections org=1024
static-file.exclude-extensions = ( “.php”, “.pl”, “.fcgi”, “.scgi”, “~”, “.inc” )

----6.2. /etc/init.d/lighttpd
vi /etc/init.d/lighttpd

config: /etc/lighttpd/lighttpd 
pidfile: /var/run/

mybook:/etc/lighttpd# mkdir -p /var/lock/subsys
mybook:/etc/lighttpd# touch /var/lock/subsys/lighttpd

----7. create user/group
–add user
mybook:/etc/lighttpd# /usr/sbin/groupadd lighttpd
mybook:/etc/lighttpd# /usr/sbin/adduser --system --no-create-home --disabled-login --disabled-password lighttpd 
–add group, since webroot is on share folder and group
root@mybook:~$ usermod -G lighttpd,share lighttpd
----pid, no need?
mybook:/etc/lighttpd# touch /var/run/
mybook:/etc/lighttpd# chown lighttpd:lighttpd /var/run/

----8. test without php
mybook:/etc/lighttpd# /usr/local/sbin/lighttpd -t -f /etc/lighttpd/lighttpd.conf
Syntax OK
----start the server for testing
/usr/local/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
----check logs

tail -f /var/log/lighttpd/error.log

tail -f /var/log/lighttpd/access.log

visit OK.:

============================================================script to start/stop
/etc/init.d/lighttpd [start|stop]

----------------I wraped up this script by myself, start/stop are tested to work fine, just modify and use it.
root@mybook:/DataVolume/shares/lighttpdweb/webroot/htdocs$ more /etc/init.d/lighttpd 

lighttpd Startup script for the lighttpd server

description: Lightning fast webserver with light system requirements

processname: lighttpd

config: /etc/lighttpd/lighttpd.conf

config: /etc/lighttpd/lighttpd

pidfile: /var/run/

Note: pidfile is assumed to be created

by lighttpd (config:

If not, uncomment ‘pidof’ line.

DESC=“Startup script for the lighttpd server”


Source function library

#. /etc/rc.d/init.d/functions

if [-f /etc/lighttpd/lighttpd]; then
. /etc/lighttpd/lighttpd
if [-z “$LIGHTTPD_CONF_PATH”]; then

Exit if the package is not installed

if [! -x “$DAEMON”]; then
echo “Main program not exists or no execute permission: $DAEMON”
exit 0

Define LSB log_* functions.

Depend on lsb-base (>= 3.0-6) to ensure that this file is present.

. /lib/lsb/init-functions

Function that starts the daemon/service

do_start() {


0 if daemon has been started OK

1 if daemon was already running

2 if daemon could not be started

echo -n $"Starting $NAME: "
#start-stop-daemon --start --exec /my/exec/prog --pidfile /my/pid/file --background
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON – $DAEMON_ARGS || return 2
#daemon $lighttpd -f $LIGHTTPD_CONF_PATH
[$RETVAL -eq 0] && touch /var/lock/subsys/$NAME
return $RETVAL

Function that stops the daemon/service

do_stop() {


0 if daemon has been stopped

1 if daemon was already stopped

2 if daemon could not be stopped

other if a failure occurred

echo -n $“Stopping $NAME: "
#start-stop-daemon --stop --pidfile /my/pid/file
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
#killproc $lighttpd
[”$RETVAL" = 2] && return 2

start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
["$?" = 2] && return 2

[$RETVAL -eq 0] && rm -f /var/lock/subsys/$NAME
rm -f $PIDFILE

return $RETVAL

do_reload() {
echo -n $"Reloading $prog: "
#killproc $lighttpd -HUP
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return $RETVAL

case “$1” in
case “$?” in
0|1) ["$VERBOSE" != no] && log_end_msg 0 ;;
2) ["$VERBOSE" != no] && log_end_msg 1 ;;
case “$?” in
0|1) ["$VERBOSE" != no] && log_end_msg 0 ;;
2) ["$VERBOSE" != no] && log_end_msg 1 ;;
if [-f /var/lock/subsys/$prog]; then
#status $DAEMON
echo “not implemented yet. - hanshan”
echo $“Usage: $0 {start|stop|restart|condrestart|reload|status}”

exit $RETVAL

============================================================add php-cgi to fastcgi tested OK 

vi /etc/lighttpd/conf.d/fastcgi.conf

server.modules += ( “mod_fastcgi” )
fastcgi.server = ( “.php” =>
( “php-5-procs” =>
“socket” => socket_dir + “/php-fastcgi.socket”,
“bin-path” => “/usr/local/bin/php-cgi”,
“bin-environment” => (
“max-procs” => 5,
“broken-scriptfilename” => “enable”,

/etc/init.d/lighttpd stop
/etc/init.d/lighttpd start

----test script
cd /DataVolume/shares/lighttpdweb/webroot/htdocs
root@mybook:/DataVolume/shares/lighttpdweb/webroot/htdocs$ cp /DataVolume/shares/dev/php/testmysql.php ./
root@mybook:/DataVolume/shares/lighttpdweb/webroot/htdocs$ ls
index.html testmysql.php


============================================================backup system
mybook:~# dd if=/dev/md1 of=/DataVolume/shares/Public/mysql_custom_rootfs.img
dd: opening `/dev/md1’: No such file or directory
mybook:~# dd if=/dev/md0 of=/DataVolume/shares/Public/mysql_custom_rootfs.img

============================================================Now all is done.