How to build a php 5.4 chroot env. with most useful extensions and php-fpm?
-. Extensions we hope to include:
1. Caching related
redis
memcache
2. opcode caching and performance
APC
php-fpm
3. utilities
imageick
igbinary
pecl_http
pdf support
4. application
solr
sphinx
5. Database
mongo
6. internationalization
Tanslit
intl
-. We decided to leave the following for later
solr
sphinx
pecl_http
pdf support
imageick
redis
-. eventually our initial build configure as below, pls refer to our common php compile errors for any issues you may encouter
./configure --prefix=/opt/php-5.4.42 --with-config-file-path=/opt/php-5.4.42/etc --with-config-file-scan-dir=/opt/php-5.4.42/etc/php.d --with-libdir=lib64 --with-pic --disable-rpath --with-mysql=shared,/usr --with-gd=shared --enable-gd-native-ttf --with-gettext --with-freetype-dir=/usr --with-gmp --with-iconv --with-iconv-dir=/usr --with-jpeg-dir=/usr --with-openssl --with-png-dir=/usr --with-xpm-dir=/usr --with-pspell=shared --with-xmlrpc=shared --with-tidy=shared,/usr --with-pcre-regex=/usr --with-zlib --with-zlib-dir=/usr --with-libxml-dir=/usr --enable-xml --with-layout=GNU --enable-exif --enable-ftp --enable-pcntl --enable-magic-quotes --enable-sockets --enable-sysvsem=shared --enable-sysvshm=shared --enable-sysvmsg=shared --enable-wddx=shared --enable-mbstring=shared --enable-mbregex --enable-dba=shared --without-oci8 --with-kerberos=/usr --with-ldap=shared --with-ldap-sasl --enable-bcmath=shared --enable-shmop --enable-calendar --enable-soap=shared --enable-pdo=shared --with-pdo-sqlite=shared,/usr --with-sqlite=shared,/usr --with-sqlite3=shared,/usr --with-pdo-pgsql=shared,/usr --with-bz2 --with-curl=shared,/usr --with-mhash=/usr --with-mysqli=shared,/usr/bin/mysql_config --with-pdo-mysql=shared,/usr/bin/mysql_config --enable-intl=shared --with-icu-dir=/usr --with-xsl=shared,/usr --with-mcrypt=shared,/usr --with-imap=shared,/usr --with-imap-ssl --enable-zip=shared --with-enchant=shared,/usr --enable-posix=shared --with-pgsql=shared,/usr --with-snmp=shared,/usr --enable-apc=shared --enable-memcache=shared --enable-igbinary=shared --enable-fpm --enable-translit=shared --enable-mongo=shared --enable-gender=shared --enable-redis=shared
-. build now any additional ext that is not compiled in the above cmd
e.g. pecl_http
-. strip all the executable binaries and shared libs to reduce file size (significantly)
Before stripping, file sizes
[root@dev php-5.4.37]# find -type f -executable -exec file -i ‘{}’ \; | grep ‘application/x-sharedlib; charset=binary’ | cut -d : -f 1 | perl -e ‘while(<>){print `du -hs $_`}’
164K ./lib/php/20100525/ldap.so
64K ./lib/php/20100525/sysvmsg.so
72K ./lib/php/20100525/enchant.so
420K ./lib/php/20100525/bcmath.so
1.4M ./lib/php/20100525/intl.so
140K ./lib/php/20100525/sqlite3.so
344K ./lib/php/20100525/pgsql.so
144K ./lib/php/20100525/tidy.so
140K ./lib/php/20100525/xsl.so
152K ./lib/php/20100525/snmp.so
148K ./lib/php/20100525/mysql.so
136K ./lib/php/20100525/pdo_sqlite.so
700K ./lib/php/20100525/translit.so
412K ./lib/php/20100525/dba.so
272K ./lib/php/20100525/imap.so
340K ./lib/php/20100525/pdo.so
136K ./lib/php/20100525/wddx.so
584K ./lib/php/20100525/mysqli.so
176K ./lib/php/20100525/igbinary.so
252K ./lib/php/20100525/memcache.so
1.1M ./lib/php/20100525/gd.so
144K ./lib/php/20100525/mcrypt.so
784K ./lib/php/20100525/apc.so
340K ./lib/php/20100525/xmlrpc.so
40K ./lib/php/20100525/sysvsem.so
1.4M ./lib/php/20100525/zip.so
2.5M ./lib/php/20100525/mbstring.so
88K ./lib/php/20100525/posix.so
168K ./lib/php/20100525/pdo_pgsql.so
52K ./lib/php/20100525/sysvshm.so
1.1M ./lib/php/20100525/soap.so
68K ./lib/php/20100525/pspell.so
236K ./lib/php/20100525/curl.so
184K ./lib/php/20100525/pdo_mysql.so
1.8M ./lib/php/20100525/mongo.so
Strip all executables and shared libs
[root@dev php-5.4.37]# find -type f -executable -exec file -i ‘{}’ \; | grep ‘application/x-sharedlib; charset=binary’ | cut -d : -f 1 | perl -e ‘while(<>){print `strip $_`}’
After stripping, file sizes
[root@dev php-5.4.37]# find -type f -executable -exec file -i ‘{}’ \; | grep ‘application/x-sharedlib; charset=binary’ | cut -d : -f 1 | perl -e ‘while(<>){print `du -hs $_`}’
60K ./lib/php/20100525/ldap.so
20K ./lib/php/20100525/sysvmsg.so
24K ./lib/php/20100525/enchant.so
32K ./lib/php/20100525/bcmath.so
196K ./lib/php/20100525/intl.so
48K ./lib/php/20100525/sqlite3.so
124K ./lib/php/20100525/pgsql.so
52K ./lib/php/20100525/tidy.so
36K ./lib/php/20100525/xsl.so
56K ./lib/php/20100525/snmp.so
56K ./lib/php/20100525/mysql.so
28K ./lib/php/20100525/pdo_sqlite.so
564K ./lib/php/20100525/translit.so
48K ./lib/php/20100525/dba.so
100K ./lib/php/20100525/imap.so
100K ./lib/php/20100525/pdo.so
36K ./lib/php/20100525/wddx.so
140K ./lib/php/20100525/mysqli.so
40K ./lib/php/20100525/igbinary.so
56K ./lib/php/20100525/memcache.so
320K ./lib/php/20100525/gd.so
44K ./lib/php/20100525/mcrypt.so
144K ./lib/php/20100525/apc.so
76K ./lib/php/20100525/xmlrpc.so
12K ./lib/php/20100525/sysvsem.so
96K ./lib/php/20100525/zip.so
1.3M ./lib/php/20100525/mbstring.so
28K ./lib/php/20100525/posix.so
40K ./lib/php/20100525/pdo_pgsql.so
12K ./lib/php/20100525/sysvshm.so
332K ./lib/php/20100525/soap.so
24K ./lib/php/20100525/pspell.so
68K ./lib/php/20100525/curl.so
36K ./lib/php/20100525/pdo_mysql.so
344K ./lib/php/20100525/mongo.so
-. copy over needed dynamic libs into chroot env. /opt/php-5.4.36 using our chroot_dir.pl
pls refer to this post
Setup Chroot env. and other dependencies:
-. link /opt/php to /opt/php-5.4.36
$ ln -s /opt/php-5.4.36 /opt/php
-. set up file system links in chroot, e.g. when chroot to /opt/php-5.4.36, we want to /opt/php-5.4.36 (seen in chroot) still works, meaning pointing to /opt/php-5.4.36 (seen outside of chroot), so we want /opt/php-5.4.36/opt/php-5.4.36 points to /opt/php-5.4.36
$ mkdir /opt/php-5.4.37/opt
$ cd /opt/php-5.4.37/opt
$ ln -s ../ php-5.4.37
$ ln -s php-5.4.37 php
-. set up /dev in the chroot
$ mkdir /opt/php-5.4.36/dev
$ mknod -m 0666 /opt/php-5.4.36/dev/null c 1 3
$ mknod -m 0666 /opt/php-5.4.36/dev/random c 1 8
$ mknod -m 0666 /opt/php-5.4.36/dev/urandom c 1 9
-. other things:
There are still some possible missing libs that are only needed durng runtime on demand, we will fix as we encounter it.