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

和自甴很熟 提交于 2019-12-04 12:30:36



适用环境 : 64位Linux

HHVM-3.7.1下载地址( 33MB ) :
https://pan.baidu.com/s/1dECvbET
md5sum hhvm-3.7.1.tar.xz
1c921ac67c57d4a23132e1f6f7bb3da6

HHVM-3.5.0下载地址( 30MB ) :
http://pan.baidu.com/s/1mgJuG7Q
md5sum hhvm- 3.5.0 .tar.xz
01d7bce054a938de30fff4f3672cca76

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

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

创建解压目录:
sudo mkdir -p /png/hhvm
sudo chown $USER:$USER /png/hhvm

解压到目录:
xz -d hhvm-3.5.0.tar.xz && tar xf hhvm-3.5.0.tar -C /png/hhvm

设置目录权限:
mkdir -p /png/hhvm/3.5.0/var/run/hhvm
sudo chown png:png -R /png/hhvm/3.5.0/var

启动HHVM:
sudo /png/hhvm/3.5.0/etc/init.d/hhvm start
sudo netstat -antp|grep hhvm

bench.php测试:
cd /png/hhvm/3.5.0/usr/bin/
time ./hhvm bench.php
(完)

附: 跨Linux发行版HHVM打包方法
我的系统是Ubuntu 14.04,trusty是Ubuntu 14.04的代号,所以下载:
http://dl.hhvm.com/ubuntu/pool/main/h/hhvm/hhvm_3.5.0~trusty_amd64.deb
下载后我把它解压到/png/hhvm/3.5.0/.

安装依赖库:
dpkg --info hhvm_3.5.0~trusty_amd64.deb | grep -i depends
用" "替换" ,"可以快速得到依赖的软件包列表,方便安装.
sudo apt-get update
sudo apt-get install \
binutils \
libasn1-8-heimdal \
libboost-filesystem1.48.0 \
libboost-program-options1.48.0 \
libboost-system1.48.0 \
libboost-regex1.48.0 \
libbz2-1.0 \
libc6 \
libcap2 \
libc-client2007e \
libcomerr2 \
libelf1 \
libexpat1 \
libfontconfig1 \
libfreetype6 \
libgcc1 \
libgcrypt11 \
libgd2-xpm \
libgnutls26 \
libgpg-error0 \
libgssapi3-heimdal \
libgssapi-krb5-2 \
libhcrypto4-heimdal \
libheimbase1-heimdal \
libheimntlm0-heimdal \
libhx509-5-heimdal \
libicu48 \
libidn11 \
libjpeg-turbo8 \
libk5crypto3 \
libkeyutils1 \
libkrb5-26-heimdal \
libkrb5-3 \
libkrb5support0 \
libldap-2.4-2 \
libmcrypt4 \
libmemcached6 \
libmysqlclient18 \
libonig2 \
libp11-kit0 \
libpam0g \
libpcre3 \
libpng12-0 \
libroken18-heimdal \
librtmp0 \
libsasl2-2 \
libsqlite3-0 \
libssl1.0.0 \
libstdc++6 \
libtasn1-3 \
libtbb2 \
libtinfo5 \
libwind0-heimdal \
libx11-6 \
libxau6 \
libxcb1 \
libxdmcp6 \
libxml2 \
libxpm4 \
zlib1g \
libedit2 \
libboost-thread1.48.0 \
libunwind7 \
libcurl3 \
libevent-2.0-5

服务管理脚本 /png/hhvm/3.5.0/etc/init.d/hhvm 内容如下:

#! /bin/sh
SSD=/png/hhvm/3.5.0/usr/bin/start-stop-daemon
DAEMON=/png/hhvm/3.5.0/usr/bin/hhvm
PIDFILE=/png/hhvm/3.5.0/var/run/hhvm/pid
CONFIG_FILE="/png/hhvm/3.5.0/etc/hhvm/server.ini"
SYSTEM_CONFIG_FILE="/png/hhvm/3.5.0/etc/hhvm/php.ini"
RUN_AS_USER="png"
RUN_AS_GROUP="png"
ADDITIONAL_ARGS=""

DAEMON_ARGS="\
--config ${SYSTEM_CONFIG_FILE} \
--config ${CONFIG_FILE} \
--user ${RUN_AS_USER} \
--mode daemon \
-vPidFile=${PIDFILE} \
${ADDITIONAL_ARGS}"

test -x $DAEMON || exit 0

case "$1" in
  start)
        $SSD --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
        ;;
  stop)
        $SSD --stop --quiet --oknodo --pidfile $PIDFILE
        ;;

  reload|force-reload|restart|try-restart)
        $0 stop
        $0 start
        ;;

  status)
        echo "No status"
        ;;

  *)
        echo "Usage: /etc/init.d/hhvm {start|stop|restart|status}"
        exit 1
esac

exit 0

配置文件php.ini和server.ini里修改路径:
/png/hhvm/3.5.0/etc/hhvm/php.ini:
; php options
session.save_handler = files
session.save_path = /png/hhvm/3.5.0/var/sessions
session.gc_maxlifetime = 1440
date.timezone = "Asia/Shanghai"

; hhvm specific
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.mysql.typed_results = false

/png/hhvm/3.5.0/etc/hhvm/server.ini:
; php options
pid = /png/hhvm/3.5.0/var/run/hhvm/pid

; hhvm specific
hhvm.server.port = 9000
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.use_log_file = true
hhvm.log.file = /png/hhvm/3.5.0/var/log/hhvm/error.log
hhvm.repo.central.path = /png/hhvm/3.5.0/var/run/hhvm/hhvm.hhbc

设置目录权限:
mkdir -p /png/hhvm/3.5.0/var/run/hhvm
sudo chown png:png -R /png/hhvm/3.5.0/var

打包依赖库到/png/hhvm/libs:
mkdir -p /png/hhvm/libs
list="$(ldd hhvm | egrep -o '/lib.*\.[0-9]')"
for i in $list; do cp -v "$i" /png/hhvm/libs; done

关键: patchelf可以修改依赖库和链接器位置,launchpad提供有patchelf二进制包:
https://launchpad.net/ubuntu/+source/patchelf
http://launchpadlibrarian.net/173906612/patchelf_0.8-2_amd64.deb

cd /png/hhvm/3.5.0/usr/bin/

指定依赖库位置:
patchelf --set-rpath /png/hhvm/libs --force-rpath ./hhvm
patchelf --set-rpath /png/hhvm/libs --force-rpath ./h2tp
patchelf --set-rpath /png/hhvm/libs --force-rpath ./hackificator
patchelf --set-rpath /png/hhvm/libs --force-rpath ./hack_remove_soft_types
patchelf --set-rpath /png/hhvm/libs --force-rpath ./hh_client
patchelf --set-rpath /png/hhvm/libs --force-rpath ./hh_server

指定库链接器:
patchelf --set-interpreter /png/hhvm/libs/ld-linux-x86-64.so.2 ./hhvm
patchelf --set-interpreter /png/hhvm/libs/ld-linux-x86-64.so.2 ./h2tp
patchelf --set-interpreter /png/hhvm/libs/ld-linux-x86-64.so.2 ./hackificator
patchelf --set-interpreter /png/hhvm/libs/ld-linux-x86-64.so.2 ./hack_remove_soft_types
patchelf --set-interpreter /png/hhvm/libs/ld-linux-x86-64.so.2 ./hh_client
patchelf --set-interpreter /png/hhvm/libs/ld-linux-x86-64.so.2 ./hh_server

因为服务管理脚本用到start-stop-daemon,而有些发行版没有,所以也打包进去:
cp /sbin/start-stop-daemon ./
patchelf --set-rpath /png/hhvm/libs --force-rpath ./start-stop-daemon
patchelf --set-interpreter /png/hhvm/libs/ld-linux-x86-64.so.2 ./start-stop-daemon

查看修改后文件的链接库信息:
ldd * > ldd.txt

我在Ubuntu上打包好后即可移植到其他发行版运行,比如CentOS 7:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!