安装环境:
系统:CentOS release 6.3
hhvm版本:HipHop VM 3.1.0-dev (rel)
nginx版本:nginx/1.2.9
php版本:PHP 5.3.10
hhvm的安装步骤见: https://github.com/facebook/hhvm/wiki/Building-and-installing-HHVM-on-CentOS-6.3
下面主要介绍下hhvm与nginx的整合:
1. 启动hhvm fastcgi
hhvm –mode server -u nobody -vServer.Type=fastcgi -vServer.Port=9001 -vAdminServer.Port=9999
2. 修改nginx配置文件:server
{
listen 8080;
server_name www.test.com;
keepalive_timeout 60;
location / {
root /home/work/data/www;
index index.php;
}
location ~ \.(hh|php)$ {
root /home/work/data/www;
#fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~.*\.(js|css|png|ttf|woff|svg|eot|json)$ {
root /home/work/data/www;
break;
}
}
3. 重启nginx服务
service nginx restart
最后,通过curl 访问
curl http://127.0.0.1:8080/index.phpHipHop
curl -I http://127.0.0.1:8080
HTTP/1.1 200 OK
Server: NGINX
Date: Mon, 19 May 2014 08:41:07 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
X-Powered-By: HHVM/3.1.0-dev
碰到的问题:
问题1:运行hhvm的时候,报错:could not allocate 216006655 bytes for translation cache
解决:google了一下,大意是需要1.2G的剩余内存空间。由于我用的是配置很低的测试机,内存不到1G,换大内存机器后问题解决。
问题2:Warning: It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Asia/Chongqing’ for ‘CST/8.0/no DST’ instead in /home/work/data/xx.php on line 230
解决: 运行hhvm的时候,手动指定php.ini的路径。
hhvm –mode server -u nobody -vServer.Type=fastcgi -vServer.Port=9001 -vAdminServer.Port=9999 -c /etc/php.ini