CentOS 7下hhvm Nginx环境搭建

CentOS 7(hhvm只支持64位)下hhvm Nginx环境搭建,前面有介绍《CentOS 6下hhvm Nginx环境搭建》,到目前为止CentOS 7下还没有hhvm rpm安装包,因此采用源码编译。在安装hhvm前强力建议先利用《lnmp一键安装包》安装完整的lnmp(包括Nginx、PHP、MySQL),通过这种方式我们可以在同一台服务器对每个虚拟主机进行配置,如在同一台服务器上有www.linuxeye.com跑在PHP上、另一个网站linuxeye.com可以选择跑在hhvm,并可以自由切换用php还是hhvm,只需要简单修改虚拟主机配置文件。

安装步骤

1. 安装完整的LNMP,参考《lnmp一键安装包

2. 安装hhvm

  1. rpm Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
  1. yum y install git mariadbdevel curldevel expatdevel libpngdevel psmisc binutilsdevel \
  2. boostdevel libmcryptdevel libmemcacheddevel jemallocdevel libeventdevel sqlitedevel \
  3. libxsltdevel libicudevel tbbdevel libzipdevel bzip2devel openldapdevel readlinedevel \
  4. elfutilslibelfdevel libdwarfdevel libcapdevel libyamldevel libeditdevel lz4devel \
  5. libvpxdevel unixODBCdevel libgmpdevel libpngdevel ImageMagickdevel curldevel expatdevel
  1. cd lnmp/src
  2. wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz
  3. tar xvzf glog0.3.3.tar.gz
  4. cd glog0.3.3
  5. ./configure
  6. make && make install
  7. cd ..
  1. wget http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.5.tar.gz
  2. tar xvzf onig5.9.5.tar.gz
  3. cd onig5.9.5
  4. ./configure
  5. make && make install
  6. cd ..
  1. git clone https://github.com/facebook/hhvm -b master hhvm –recursive
  2. cd hhvm
  3. ./configure
  1. ## use newer ImageMagick from remi
  2. rpm Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
  3. ## remove the obsolete ImageMagick version
  4. yum y remove ImageMagick
  5. yum y install ImageMagicklast* enablerepo=remi
  6. cmake D LIBMAGICKWAND_INCLUDE_DIRS=“/usr/include/ImageMagick-6” \
  7. D LIBODBC_INCLUDE_DIRS=“/usr/lib64” D LIBODBC_LIBRARIES=“/usr/lib64” \
  8. D LIBVPX_INCLUDE_DIRS=“/usr/lib64” D LIBXSLT_INCLUDE_DIR=“/usr/lib64” \
  9. D LIBXSLT_LIBRARIES=“/usr/lib64/libxslt.so” D LIBMAGICKWAND_LIBRARIES=“/usr/lib64/libMagickWand-6.Q16.so” \
  10. D LIBMAGICKCORE_LIBRARIES=“/usr/lib64/libMagickCore-6.Q16.so” .
  1. make j2 #利用cpu多核编译加快速度,2代表核数,单核不用加-j2,查看cpu核数:cat /proc/cpuinfo | grep processor | wc -l

注:编译过程非常消耗系统资源,有可能会报内存不够导致编译中断,如下错误:

  1. [ 30%] Building CXX object thirdparty/thrift/CMakeFiles/hphp_thrift.dir/thrift/lib/cpp/async/TEventTask.cpp.o
  2. c++: internal compiler error: Killed (program cc1plus)
  3. Please submit a full bug report,
  4. with preprocessed source if appropriate

编译通过后,执行如下命令安装:

  1. make install

安装成功后,打印出hhvm版本:

  1. hhvm version
  2. HipHop VM 3.4.0dev (rel)
  3. Compiler: heads/master0g0b46339509ebd9612623d52c296fdcc8e6f93dff
  4. Repo schema: d8dcfe0a4feda06dea7087bd82b55ef19217b170
  5. Extension API: 20140829

3. 配置hhvm

创建并修改hhvm目录权限

  1. mkdir /etc/hhvm /var/run/hhvm /var/log/hhvm
  2. chown R www.www /var/run/hhvm /var/log/hhvm

修改/usr/local/nginx/conf/nginx.conf使其中一段成为如下:

  1. location ~ .*\.(php|php5)?$ {
  2. fastcgi_pass unix:/var/run/hhvm/sock;
  3. fastcgi_index index.php;
  4. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  5. include fastcgi_params;
  6. }
  1. service nginx reload

添加hhvm虚拟主机的方法: 请执行vhost_hhvm.sh

  1. cd lnmp
  2. wget //linuxeye.com/wp-content/uploads/2014/05/vhost_hhvm.sh
  3. chmod +x vhost_hhvm.sh

创建hhvm配置文件/etc/hhvm/config.hdf,保持如下:

  1. ResourceLimit {
  2. CoreFileSize = 0 # in bytes
  3. MaxSocket = 10000 # must be not 0, otherwise HHVM will not start
  4. SocketDefaultTimeout = 5 # in seconds
  5. MaxRSS = 0
  6. MaxRSSPollingCycle = 0 # in seconds, how often to check max memory
  7. DropCacheCycle = 0 # in seconds, how often to drop disk cache
  8. }
  9.  
  10. Log {
  11. Level = Info
  12. AlwaysLogUnhandledExceptions = true
  13. RuntimeErrorReportingLevel = 8191
  14. UseLogFile = true
  15. UseSyslog = false
  16. File = /var/log/hhvm/error.log
  17. Access {
  18. * {
  19. File = /var/log/hhvm/access.log
  20. Format = %h %l %u % t \”%r\” %>s %b
  21. }
  22. }
  23. }
  24.  
  25. MySQL {
  26. ReadOnly = false
  27. ConnectTimeout = 1000 # in ms
  28. ReadTimeout = 1000 # in ms
  29. SlowQueryThreshold = 1000 # in ms, log slow queries as errors
  30. KillOnTimeout = false
  31. }
  32.  
  33. Mail {
  34. SendmailPath = /usr/sbin/sendmail t i
  35. ForceExtraParameters =
  36. }

配置hhvm修改/etc/hhvm/server.ini,保持如下:

  1. ; php options
  2. pid = /var/run/hhvm/pid
  3.  
  4. ; hhvm specific
  5. ;hhvm.server.port = 9001
  6. hhvm.server.file_socket = /var/run/hhvm/sock
  7. hhvm.server.type = fastcgi
  8. hhvm.server.default_document = index.php
  9. hhvm.log.use_log_file = true
  10. hhvm.log.file = /var/log/hhvm/error.log
  11. hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc

修改/etc/hhvm/php.ini指定mysql.sock路径(hhvm默认路径sock路径是/var/lib/mysql/mysql.sock)

  1. hhvm.mysql.socket = /tmp/mysql.sock
  2. expose_php = 0 ;关闭头信息XPoweredBy (和hhvm.server.expose_hphp = false作用一样)
  3. memory_limit = 400M
  4. post_max_size = 50M

添加开机自启动脚本

保证文件/etc/systemd/system/hhvm.service内容如下:

  1. [Unit]
  2. Description=HHVM HipHop Virtual Machine (FCGI)
  3.  
  4. [Service]
  5. ExecStart=/usr/local/bin/hhvm mode daemon user www config /etc/hhvm/server.ini \
  6. config /etc/hhvm/php.ini config /etc/hhvm/config.hdf
  7.  
  8. [Install]
  9. WantedBy=multiuser.target

管理hhvm服务

  1. systemctl enable hhvm #开机自启动
  2. systemctl start hhvm #启动hhvm
  3. systemctl status hhvm #查看hhvm状态

参考:linuxeye.com/396.html

https://github.com/facebook/hhvm/wiki/Building-and-installing-hhvm-on-CentOS-7.x

Sat Nov 1 16:01:27 CST 2014

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注