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

PHP7 for Linux:
https://downloads.php.net/~ab/

PHP7 for Windows:
http://windows.php.net/qa/

适用环境: 64位Linux:
PHP在 抗战胜利日 发布了PHP7 RC2.
PHP-7.0.0-RC2 2015/09/03(截图) 下载地址(21MB):
http://pan.baidu.com/s/1ntGfWet
md5sum php-7.0.0-20150903.tar.xz
428c36989ee688d8090c54f2e13f9d25
PHP-7.0.0-RC2也打包里Swoole-1.7.19这个扩展,
方便PHPer使用Swoole开发高性能实时的网络应用.

PHP-7.0.0-beta2 2015/07/25(截图) 下载地址(21MB):
http://pan.baidu.com/s/1jG0AaW2
md5sum php-7.0.0-beta-20150725.tar.xz
561939e49d610b481ccd3fa5c438a3fc
Swoole从1.7.18开始,支持PHP7,所以PHP-7.0.0-beta2也打包里Swoole这个扩展.
方便PHPer使用Swoole开发高性能实时的网络应用.

PHP-7.0.0-dev 2015/06/06 下载地址(18MB):
http://pan.baidu.com/s/1jG3U80u
md5sum php-7.0.0-dev-20150606.tar.xz
7ae0fd48d9775535cec631d243a63e34

PHP-7.0.0-dev 2015/05/02 下载地址(18MB):
http://pan.baidu.com/s/1ntsrU8x
md5sum php-7.0.0-dev-20150502.tar.xz
5a4897aedc5ccf02da1f0340ac6013cb

我还打包了HHVM,适用于64位Linux,解压即用,需要的用户也可以下载:
http://my.oschina.net/eechen/blog/371643

创建用户:
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 php7.tar.xz -C /

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

我是在64位Ubuntu14.04上编译打包的PHP7,下面的截图是跑在CentOS7下的PHP7.
解压即用,跨Linux发行版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 \
libreadline6-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 https://downloads.php.net/~ab/php-7.0.0RC2.tar.xz
tar xJf php-7.0.0RC2.tar.xz 假设解压到/png/src/php-7.0.0

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/php.ini-* /png/php/7.0.0/lib/
cp /png/php/7.0.0/lib/php.ini-production /png/php/7.0.0/lib/php.ini
cp /png/php/7.0.0/etc/php-fpm.conf.default /png/php/7.0.0/etc/php-fpm.conf
cp /png/php/7.0.0/etc/php-fpm.d/www.conf.default /png/php/7.0.0/etc/php-fpm.d/www.conf
PHP-FPM服务管理脚本:
cp /png/src/php-7.0.0/sapi/fpm/init.d.php-fpm /png/php/7.0.0/png-fpm
cp /png/src/php-7.0.0/sapi/fpm/php-fpm.service /png/php/7.0.0/
init.d.php-fpm是传统的init服务脚本,php-fpm.service则是systemd的服务脚本.

configure_php.sh
#!/bin/bash
./configure \
--prefix=/png/php/7.0.0 \
--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-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-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
其中--with-apxs2是用来生成Apache的PHP模块libphp7.so的,不需要可以去掉.

事先创建好/png/pack/libs和/png/pack/backup这些目录.
关键: patchelf可以修改依赖库和链接器位置,launchpad提供有patchelf二进制包:
https://launchpad.net/ubuntu/+source/patchelf
http://launchpadlibrarian.net/173906612/patchelf_0.8-2_amd64.deb
要使PHP跨Linux发行版,那就需要找出PHP依赖的共享库随PHP打包,脚本pack.sh如下:

pack.sh

#!/bin/bash
#运行 cd /png/pack && ./pack.sh
PHP=/png/php/7.0.0

#备份原有文件
tar czf /png/pack/backup/php7.tar.gz $PHP
cp -R $PHP ${PHP}.backup

#找出二进制和共享库
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/php7.tar.xz /png/pack/libs $PHP

你可能感兴趣的:(PHP,linux,ubuntu,php7,PHPNG,patchelf,便携式)