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

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