benchen72 2015-12-20 21:53
在 Centos6 下安裝 HHVM 3.x + PHP + Nginx
HHVM(HipHop Virtual Machine),Facebook的開源項目之一,用于代替php環境,執行速度宣稱比 PHP 官方版本快上 9 倍, 以下是在 CentOS 6.5 安裝 HHVM 的方法:
安裝所需的epel,remi和hhvm yum源
# rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/6/remi/x86_64/remi-release-6.6-2.el6.remi.noarch.rpm
# wget -O /etc/yum.repos.d/hop5.repo http://www.hop5.in/yum/el6/hop5.repo
安裝hhvm所需依賴包
# yum -y install libmcrypt-devel glog-devel jemalloc-devel tbb-devel libdwarf-devel mysql-devel \ libxml2-devel libicu-devel pcre-devel gd-devel boost-devel sqlite-devel pam-devel \ bzip2-devel oniguruma-devel openldap-devel readline-devel libc-client-devel libcap-devel \ libevent-devel libcurl-devel libmemcached-devel
# yum install hhvm
# wget -O /etc/init.d/hhvm https://cdn.zntec.cn/store/tools/vhost_hhvm/hhvm --no-check-certificate
# chmod +x /etc/init.d/hhvm
hhvm 預設是 Listen 9001,不需要其他web容器就能直接訪問,可以根据自己需求前面加apache或nginx(老版本的hhvm会有config.hdf 和hhvm.hdf,新版本是php.ini 和server.ini)
但我们這邊修改下配置,將 hhvm 運行模式由端口改為 socket 方式
# vi /etc/hhvm/php.ini
[quote]
; php options
session.save_handler = files
session.save_path = /var/lib/hhvm/sessions
session.gc_maxlifetime = 1440
; 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
[/quote]
# vi /etc/hhvm/server.ini
[quote]
; php options
pid = /var/run/hhvm/pid
; hhvm specific
;hhvm.server.port = 9001
hhvm.server.file_socket = /var/run/hhvm/sock
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc
[/quote]
然後在 nginx 底下新增一個 conf 檔
# vi /etc/nginx/hhvm.conf
[quote]
location ~ \.(hh|php)$ {
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[/quote]
接著在 Virtualhost 上載入 hhvm.conf 讓網站可以使用 HHVM虛擬機
[quote]
Server {
.
.
.
include /etc/nginx/hhvm.conf;
.
}
[/quote]
加入到開機啟動
# chkconfig hhvm on
開起 hhvm 服務
# service hhvm start
查看版本号
# hhvm --version
[quote]
HipHop VM 3.2.0 (rel)
Compiler: tags/HHVM-3.2.0-0-g01228273b8cf709aacbd3df1c51b1e690ecebac8
Repo schema: c52ba40f4a246d35a88f1dfc1daf959851ced8aa
[/quote]
參考資料:
http://54im.com/hhvm-2/centos6-install-hhvm-mariad.html