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

Hello,

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 2.6.32.11-svn70860 #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: 192.168.0.80
============================================================aptitude/apt-get update
mybook:~# more /etc/apt/sources.list
deb http://ftp.us.debian.org/debian/ squeeze main
deb http://ftp.us.debian.org/debian/ wheezy main
#deb-src http://ftp.us.debian.org/debian/ wheezy main
#deb http://ftp.us.debian.org/debian/ sid main


mybook:~# aptitude update
mybook:~# apt-get update
Reading package lists… Done
W: GPG error: http://ftp.us.debian.org squeeze Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY AED4B06F473041FA
W: GPG error: http://ftp.us.debian.org 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 pgpkeys.mit.edu --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/ld.so.conf.d/libc.conf’, which is also in package wd-lib 01.04.01-81092

----fix
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/ld.so.conf.d/powerpc-linux-gnu.conf’, which is also in package wd-lib 01.04.01-81092

----fix
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 (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

------------------------------------------------------------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 (C) 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 gord@gnu.ai.mit.edu, 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/libncursesw.so.5 /lib/libncursesw.so.5.7
------------------------------------------------------------2. install cmake
mkdir -p /DataVolume/shares/dev/mysql

cd /DataVolume/shares/dev/mysql

wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz

tar zfx cmake-2.8.10.2.tar.gz

cd cmake-2.8.10.2


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

------------------------------------------------------------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

mybook:/DataVolume/shares/dev/mysql/mysql-5.5.30# /opt/cmake/bin/cmake . -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/opt/mysql-5.5.30/data/ -DCMAKE_INSTALL_PREFIX=/opt/mysql-5.5.30 -DCURSES_LIBRARY=/lib/libncursesw.so.5 -DCURSES_INCLUDE_PATH=/usr/include/ -DINSTALL_LAYOUT=STANDALONE -DENABLED_PROFILING=ON -DMYSQL_MAINTAINER_MODE=OFF -DWITH_DEBUG=OFF -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=TRUE -DWITH_ZLIB=bundled

– 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

----path
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
adding
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
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
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
default-character-set=utf8

[mysqld]
bind-address=192.168.0.80 <— your mbl ip
datadir=/opt/mysql-5.5.30/data
character-set-server = utf8
collation-server = utf8_unicode_ci
init-connect=‘SET NAMES utf8’
character-set-server = utf8

port = 3306
socket = /tmp/mysql.sock
skip-external-locking
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
----check
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/mybook.pid --socket=/tmp/mysql.sock --port=3306
root pts/0 grep mysql
----check
mybook:/opt/mysql-5.5.30# netstat -tunlp | grep 3306
tcp 0 0 192.168.0.80:3306 0.0.0.0:* LISTEN 21471/mysqld
----test
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
Bye
----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/libmysqlclient.so.18.0.0
-rwxr-xr-- 1 mysql mysql 4282454 2013-04-13 20:14 /opt/mysql-5.5.30/lib/libmysqlclient.so.18.0.0 <—owner: mysql:mysql

----copy mysql lib to /usr/lib and create links
cp /opt/mysql-5.5.30/lib/libmysqlclient.so.18.0.0 /usr/lib
ln -s /usr/lib/libmysqlclient.so.18.0.0 /usr/lib/libmysqlclient.so.18
ln -s /usr/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so
ln -s /usr/lib/libmysqlclient.so /usr/lib/libmysqlclient_r.so
ln -s /usr/lib/libmysqlclient.so /usr/lib/libmysqlclient_r.so.18
ln -s /usr/lib/libmysqlclient.so /usr/lib/libmysqlclient_r.so.18.0.0

----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 2.6.32.11-svn70860 #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_MODULE_TYPE => external
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="192.168.0.80"; $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
connected.
Got rows num=2


a=1, b=tt

a=2, b=bb

-------done.
mybook:/DataVolume/shares/dev/php#

============================================================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 http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.32.tar.gz
mybook:/DataVolume/shares/dev/lighttpd# tar -xzf lighttpd-1.4.32.tar.gz
mybook:/DataVolume/shares/dev/lighttpd# cd lighttpd-1.4.32

----pcore
aptitude install libpcre3-dev
----bzip2
aptitude install libghc-bzlib-dev
aptitude install libbz2-ocaml-dev
----compile
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:
/usr/local/lib
.libs/mod_fastcgi.so ==> /usr/local/lib/mod_fastcgi.so
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

------------------------------------------------------------config
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
LIGHTTPD_CONF_PATH=/etc/lighttpd/lighttpd.conf

----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

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

My First Heading

My first paragraph.

----6. modify config file to use folders just created.
REF:
/var/log/lighttpd/error.log 
/DataVolume/shares/lighttpdweb/webroot
/DataVolume/shares/lighttpdweb/webroot/htdocs
/var/run/lighttpd.pid 
/DataVolume/shares/lighttpdweb/home
/DataVolume/shares/lighttpdweb/home/sockets
/DataVolume/shares/lighttpdweb/cache
/DataVolume/shares/lighttpdweb/tmp

----6.1. /etc/lighttpd/lighttpd.conf
vi /etc/lighttpd/lighttpd.conf
server.port = 6666
server.use-ipv6 = “disable”
server.bind = “192.168.0.80” <— 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 
LIGHTTPD_CONF_PATH=“/etc/lighttpd/lighttpd.conf
pidfile: /var/run/lighttpd.pid
lighttpd=”/usr/local/sbin/lighttpd"

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/lighttpd.pid
mybook:/etc/lighttpd# chown lighttpd:lighttpd /var/run/lighttpd.pid

----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.: http://192.168.0.80:6666/

============================================================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 
#!/bin/sh

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/lighttpd.pid

Note: pidfile is assumed to be created

by lighttpd (config: server.pid-file).

If not, uncomment ‘pidof’ line.

DESC=“Startup script for the lighttpd server”
NAME=“lighttpd”
DAEMON=/usr/local/sbin/lighttpd
CFGFILE=/etc/lighttpd/lighttpd.conf
DAEMON_ARGS=“-f $CFGFILE”
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

RETVAL=0

Source function library

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

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

Exit if the package is not installed

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

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() {

Return

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=$?
[$RETVAL -eq 0] && touch /var/lock/subsys/$NAME
return $RETVAL
}

Function that stops the daemon/service

do_stop() {

Return

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=$?
[”$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
RETVAL=$?
#echo
return $RETVAL
}

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

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” => (
“PHP_FCGI_CHILDREN” => “16”,
“PHP_FCGI_MAX_REQUESTS” => “10000”,
),
“max-procs” => 5,
“broken-scriptfilename” => “enable”,
)
),
)

----restart
/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

----TESTED OK
http://192.168.0.80:6666/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.