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
- rpm –Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
- yum –y install git mariadb–devel curl–devel expat–devel libpng–devel psmisc binutils–devel \
- boost–devel libmcrypt–devel libmemcached–devel jemalloc–devel libevent–devel sqlite–devel \
- libxslt–devel libicu–devel tbb–devel libzip–devel bzip2–devel openldap–devel readline–devel \
- elfutils–libelf–devel libdwarf–devel libcap–devel libyaml–devel libedit–devel lz4–devel \
- libvpx–devel unixODBC–devel libgmp–devel libpng–devel ImageMagick–devel curl–devel expat–devel
- cd lnmp/src
- wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz
- tar xvzf glog–0.3.3.tar.gz
- cd glog–0.3.3
- ./configure
- make && make install
- cd ..
- wget http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.5.tar.gz
- tar xvzf onig–5.9.5.tar.gz
- cd onig–5.9.5
- ./configure
- make && make install
- cd ..
- git clone https://github.com/facebook/hhvm -b master hhvm –recursive
- cd hhvm
- ./configure
- ## use newer ImageMagick from remi
- rpm –Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
- ## remove the obsolete ImageMagick version
- yum –y remove ImageMagick
- yum –y install ImageMagick–last* —enablerepo=remi
- cmake –D LIBMAGICKWAND_INCLUDE_DIRS=“/usr/include/ImageMagick-6” \
- –D LIBODBC_INCLUDE_DIRS=“/usr/lib64” –D LIBODBC_LIBRARIES=“/usr/lib64” \
- –D LIBVPX_INCLUDE_DIRS=“/usr/lib64” –D LIBXSLT_INCLUDE_DIR=“/usr/lib64” \
- –D LIBXSLT_LIBRARIES=“/usr/lib64/libxslt.so” –D LIBMAGICKWAND_LIBRARIES=“/usr/lib64/libMagickWand-6.Q16.so” \
- –D LIBMAGICKCORE_LIBRARIES=“/usr/lib64/libMagickCore-6.Q16.so” .
- make –j2 #利用cpu多核编译加快速度,2代表核数,单核不用加-j2,查看cpu核数:cat /proc/cpuinfo | grep processor | wc -l
注:编译过程非常消耗系统资源,有可能会报内存不够导致编译中断,如下错误:
- [ 30%] Building CXX object third–party/thrift/CMakeFiles/hphp_thrift.dir/thrift/lib/cpp/async/TEventTask.cpp.o
- c++: internal compiler error: Killed (program cc1plus)
- Please submit a full bug report,
- with preprocessed source if appropriate
编译通过后,执行如下命令安装:
- make install
安装成功后,打印出hhvm版本:
- hhvm —version
- HipHop VM 3.4.0–dev (rel)
- Compiler: heads/master–0–g0b46339509ebd9612623d52c296fdcc8e6f93dff
- Repo schema: d8dcfe0a4feda06dea7087bd82b55ef19217b170
- Extension API: 20140829
3. 配置hhvm
创建并修改hhvm目录权限
- mkdir /etc/hhvm /var/run/hhvm /var/log/hhvm
- chown –R www.www /var/run/hhvm /var/log/hhvm
修改/usr/local/nginx/conf/nginx.conf使其中一段成为如下:
- location ~ .*\.(php|php5)?$ {
- fastcgi_pass unix:/var/run/hhvm/sock;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
- service nginx reload
添加hhvm虚拟主机的方法: 请执行vhost_hhvm.sh
- cd lnmp
- wget //linuxeye.com/wp-content/uploads/2014/05/vhost_hhvm.sh
- chmod +x vhost_hhvm.sh
创建hhvm配置文件/etc/hhvm/config.hdf,保持如下:
- ResourceLimit {
- CoreFileSize = 0 # in bytes
- MaxSocket = 10000 # must be not 0, otherwise HHVM will not start
- SocketDefaultTimeout = 5 # in seconds
- MaxRSS = 0
- MaxRSSPollingCycle = 0 # in seconds, how often to check max memory
- DropCacheCycle = 0 # in seconds, how often to drop disk cache
- }
- Log {
- Level = Info
- AlwaysLogUnhandledExceptions = true
- RuntimeErrorReportingLevel = 8191
- UseLogFile = true
- UseSyslog = false
- File = /var/log/hhvm/error.log
- Access {
- * {
- File = /var/log/hhvm/access.log
- Format = %h %l %u % t \”%r\” %>s %b
- }
- }
- }
- MySQL {
- ReadOnly = false
- ConnectTimeout = 1000 # in ms
- ReadTimeout = 1000 # in ms
- SlowQueryThreshold = 1000 # in ms, log slow queries as errors
- KillOnTimeout = false
- }
- Mail {
- SendmailPath = /usr/sbin/sendmail –t –i
- ForceExtraParameters =
- }
配置hhvm修改/etc/hhvm/server.ini,保持如下:
- ; 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
修改/etc/hhvm/php.ini指定mysql.sock路径(hhvm默认路径sock路径是/var/lib/mysql/mysql.sock)
- hhvm.mysql.socket = /tmp/mysql.sock
- expose_php = 0 ;关闭头信息X–Powered–By (和hhvm.server.expose_hphp = false作用一样)
- memory_limit = 400M
- post_max_size = 50M
添加开机自启动脚本
保证文件/etc/systemd/system/hhvm.service内容如下:
- [Unit]
- Description=HHVM HipHop Virtual Machine (FCGI)
- [Service]
- ExecStart=/usr/local/bin/hhvm —mode daemon —user www —config /etc/hhvm/server.ini \
- —config /etc/hhvm/php.ini —config /etc/hhvm/config.hdf
- [Install]
- WantedBy=multi–user.target
管理hhvm服务
- systemctl enable hhvm #开机自启动
- systemctl start hhvm #启动hhvm
- systemctl status hhvm #查看hhvm状态
参考:linuxeye.com/396.html
https://github.com/facebook/hhvm/wiki/Building-and-installing-hhvm-on-CentOS-7.x