码迷,mamicode.com
首页 > Web开发 > 详细

解压即用,跨Linux发行版PHP7打包

时间:2015-05-06 23:10:20      阅读:533      评论:0      收藏:0      [点我收藏+]

标签:

适用环境: 64位Linux
下载地址(18MB): http://pan.baidu.com/s/1ntsrU8x
md5sum php-7.0.0-dev-20150502.tar.xz
5a4897aedc5ccf02da1f0340ac6013cb
PHP版本是7.0.0开发版,2015年5月2日从Github下载的代码.
https://github.com/php/php-src/archive/master.zip

创建用户:
sudo groupadd -r png
sudo useradd -r -g png -s /usr/sbin/nologin -d /png/nonexistent -c "png user" png

创建目录设置权限并解压:
sudo mkdir /png && sudo chown $USER:$USER /png
tar xJf php-7.0.0-dev-20150502.tar.xz -C /

测试:
/png/php/7.0.0-dev/bin/php -v
/png/php/7.0.0-dev/bin/php-cgi -v
/png/php/7.0.0-dev/sbin/php-fpm -v

我是在64位Ubuntu14.04上编译打包的PHP7,下面的截图是跑在CentOS7下的PHP7.
技术分享

附: 跨Linux发行版PHP打包方法
环境: 64位Ubuntu14.04

安装编译PHP依赖的开发工具和库:
sudo apt-get install
build-essential
autoconf
libtool
re2c
libxml2-dev
openssl
libcurl4-openssl-dev
libbz2-dev
libjpeg-dev
libpng12-dev
libfreetype6-dev
libldap2-dev
libmcrypt-dev
libmysqlclient-dev
libxslt1-dev
libxt-dev
libpcre3-dev
libxpm-dev
libt1-dev
libgmp-dev
libpspell-dev
librecode-dev

sudo ln -s /usr/lib/`arch`-linux-gnu/libldap.so /usr/lib/
sudo ln -s /usr/lib/`arch`-linux-gnu/liblber.so /usr/lib/
sudo ln -s /usr/include/`arch`-linux-gnu/gmp.h /usr/include/gmp.h

wget -O php-7.0.0-dev.zip https://github.com/php/php-src/archive/master.zip

./buildconf 生成configure文件.
export CFLAGS="-O3" 开启O3编译优化,生成的可执行文件更小,性能更高.
./configure_php.sh 执行configure,脚本内容在下方.
sudo mkdir /png && sudo chown $USER:$USER /png
make && make install 编译和安装PHP.

配置文件:
cp /png/src/php-7.0.0-dev-20150502/php.ini-* /png/php/7.0.0-dev/lib/
cp /png/php/7.0.0-dev/lib/php.ini-production /png/php/7.0.0-dev/lib/php.ini
cp /png/php/7.0.0-dev/etc/php-fpm.conf.default /png/php/7.0.0-dev/etc/php-fpm.conf
cp /png/php/7.0.0-dev/etc/php-fpm.d/www.conf.default /png/php/7.0.0-dev/etc/php-fpm.d/www.conf
PHP-FPM服务管理脚本:
cp /png/src/php-7.0.0-dev-20150502/sapi/fpm/init.d.php-fpm /png/php/7.0.0-dev/png-fpm
cp /png/src/php-7.0.0-dev-20150502/sapi/fpm/php-fpm.service /png/php/7.0.0-dev/
init.d.php-fpm是传统的init服务脚本,php-fpm.service则是systemd的服务脚本.

configure_php.sh
#!/bin/bash
./configure
--prefix=/png/php/7.0.0-dev
--enable-opcache
--enable-fpm
--enable-pdo
--enable-sockets
--enable-exif
--enable-soap
--enable-ftp
--enable-wddx
--enable-pcntl
--enable-soap
--enable-bcmath
--enable-mbstring
--enable-dba
--enable-gd-native-ttf
--enable-gd-jis-conv
--enable-zip
--enable-calendar
--enable-shmop
--enable-sysvmsg
--enable-sysvsem
--enable-sysvshm
--with-mysqli
--with-pdo-mysql
--with-pdo-sqlite
--with-iconv
--with-gmp
--with-pspell
--with-gettext
--with-xmlrpc
--with-openssl
--with-mhash
--with-mcrypt
--with-xsl
--with-curl
--with-pcre-regex
--with-gd
--with-jpeg-dir=/usr
--with-png-dir=/usr
--with-zlib-dir=/usr
--with-xpm-dir=/usr
--with-freetype-dir=/usr
--with-t1lib=/usr
--with-gettext=/usr
--with-zlib=/usr
--with-bz2=/usr
--with-recode=/usr
--with-ldap
--with-pear
--with-readline
--with-fpm-user=png
--with-fpm-group=png
--with-apxs2=/png/httpd/2.4.12P/bin/apxs

要使PHP跨Linux发行版,那就需要找出PHP依赖的共享库随PHP打包,脚本pack.sh如下:
事先创建好/png/pack/libs和/png/pack/backup这些目录.
pack.sh
#!/bin/bash
#运行 cd /png/pack && ./pack.sh
PHP=/png/php/7.0.0-dev

#备份原有文件
tar czf /png/pack/backup/php.tgz $PHP

#找出二进制和共享库
PHP_BIN_LIB="$(find $PHP -type f -exec file -i ‘{}‘ \; | egrep ‘x-executable; charset=binary|x-sharedlib; charset=binary‘ | awk -F ": " ‘{print $1}‘)"
echo "$PHP_BIN_LIB" > bin_lib.txt

#复制库链接器
cp /lib64/ld-linux-x86-64.so.2 /png/pack/libs

#复制依赖库.
for i in `cat bin_lib.txt`; do
    for j in $i; do
        list="$(ldd $j | awk -F " " ‘{print $3}‘|grep ‘.so‘)"
        for k in $list; do
            cp -n "$k" /png/pack/libs
        done
    done
done

#设置二进制和共享库的rpath和interpreter
for i in `cat bin_lib.txt`; do
    /png/pack/patchelf --set-rpath /png/pack/libs --force-rpath $i
    /png/pack/patchelf --set-interpreter /png/pack/libs/ld-linux-x86-64.so.2 $i
done

#打包库和修改后的程序
tar cJf /png/pack/png.tar.xz /png/pack/libs $PHP

解压即用,跨Linux发行版PHP7打包

标签:

原文地址:http://my.oschina.net/eechen/blog/411534

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!