EM đã tiến hành cài đăt lighttpd vào trong chroot như sau
Code:
/configure --prefix=/webroot --disable-ipv6 --enable-sendfile64 --with-linux-aio --with-pcre-regex && make && make install
Sau đó em rpm để càin đặt php và mysql như sau:
Code:
rpm -ivh –relocate=/=/webroot –force \
php-5.1.6-15.Suhosin.i686.rpm \
php-cli-5.1.6-15.Suhosin.i686.rpm \
php-mbstring-5.1.6-15.Suhosin.i686.rpm \
php-common-5.1.6-15.Suhosin.i686.rpm \
php-mysql-5.1.6-15.Suhosin.i686.rpm \
php-pdo-5.1.6-15.Suhosin.i686.rpm \
Tương tự cho mysql.
Sau đó thực hiện các thao tác sau
Code:
mkdir /webroot/var/www/html/www
mkdir /webroot/tmp/
chmod 1777 /webroot/tmp/
mkdir /webroot/etc
mkdir -p /webroot/var/log/lighttpd
chown nobody.nobody /webroot/var/log/lighttpd
mkdir -p /webroot/var/tmp/lighttpd/cache/compress/
chown nobody.nobody /webroot/var/tmp/lighttpd/cache/compress/
cp /etc/hosts /webroot/etc/
cp /etc/nsswitch.conf /webroot/etc/
cp /etc/resolv.conf /webroot/etc/
cp /etc/services /webroot/etc/
cp /etc/localtime /webroot/etc/
mkdir /webroot/var/run
mkdir /webroot/var/run/lighttpd
chown nobody.nobody /webroot/var/run/lighttpd
mkdir -p /webroot/var/www/html
Tạo một script để copy các libary có nội dung
Code:
1: #!/bin/bash
2: BASE="/webroot"
3:
4: if [ $# -eq 0 ]; then
5: echo "Syntax : $0 /path/to/executable"
6: echo "Example: $0 /usr/bin/php5-cgi"
7: exit 1
8: fi
9:
10: mkdir -p $BASE$(dirname $1)
11: cp $1 $BASE$(dirname $1)
12:
13: [ ! $BASE ] && mkdir -p $BASE || :
14:
15: # iggy ld-linux* file as it is not shared one
16: FILES="$(ldd $1 | awk '{ print $3 }' |egrep -v ^'\(')"
17:
18: echo "Copying shared files/libs to $BASE..."
19: for i in $FILES
20: do
21: d="$(dirname $i)"
22: [ ! -d $BASE$d ] && mkdir -p $BASE$d || :
23: /bin/cp $i $BASE$d
24: done
25:
26: # copy /lib/ld-linux* or /lib64/ld-linux* to $BASE/$sldlsubdir
27: # get ld-linux full file location
28: sldl="$(ldd $1 | grep 'ld-linux' | awk '{ print $1}')"
29: # now get sub-dir
30: sldlsubdir="$(dirname $sldl)"
31:
32: if [ ! -f $BASE$sldl ];
33: then
34: echo "Copying $sldl $BASE$sldlsubdir..."
35: /bin/cp $sldl $BASE$sldlsubdir
36: else
37: :
38: fi
Sau đó em thực hiện
Code:
/bin2chroot.sh /webroot/usr/bin/php-cgi
Tạo thêm 1 script để lấy các library của các module php có nội dung
Code:
#!/bin/bash
2: BASE="/webroot"
3:
4: if [ $# -eq 0 ]; then
5: echo "Syntax : $0 rpm-package"
6: echo "Example: $0 php-mysql"
7: exit 1
8: fi
9:
10: FILES="$(rpm -ql $1)"
11:
12: echo "Copying shared files/libs to $BASE..."
13: for i in $FILES
14: do
15: d="$(dirname $i)"
16: [ ! -d $BASE$d ] && mkdir -p $BASE$d || :
17: /bin/cp $i $BASE$d
18:
19: LDFILES="$(ldd $i | awk '{ print $3 }' |egrep -v ^'\(')"
20: for x in $LDFILES
21: do
22: echo "Copying $x files/libs to $BASE..."
23: y="$(dirname $x)"
24: [ ! -d $BASE$y ] && mkdir -p $BASE$y || :
25: /bin/cp $x $BASE$y
26: done
27: done
Và thưc hiện ví dụ:
Code:
Tiến hành thêm một số dòng config cho lighttpd
Code:
server.chroot = "/webroot"
astcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/bin/php-cgi", "min-procs" => 1, "max-procs" => 1,
"bin-environment"=>("PHP_FCGI_CHILDREN"=>"256","PHP_FCGI_MAX_REQUESTS"=>"256")
)
)
)
Kết quả: Chạy các file php rất ok, tuy nhiên khi chạy phpmyadmin thì báo lỗi
Code:
Cannot load mysql extension. Please check your PHP configuration. - Documentation
Mặc dù đã có các thư viện mà php-mysql cần
Code:
/webroot/webroot/etc/php.d/mysql.ini
/webroot/webroot/etc/php.d/mysqli.ini
/webroot/webroot/etc/php.d/pdo_mysql.ini
/webroot/webroot/usr/bin/mysql
/webroot/webroot/usr/bin/mysqladmin
/webroot/webroot/usr/lib/php/modules/mysql.so
/webroot/webroot/usr/lib/php/modules/mysqli.so
/webroot/webroot/usr/lib/php/modules/pdo_mysql.so