CentOS 7系統中hhvm Nginx環境安裝配置

來源:互聯網
上載者:User

CentOS 7(hhvm只支援64位)下hhvm Nginx環境搭建,,到目前為止CentOS 7下還沒有hhvm rpm安裝包,因此採用源碼編譯。在安裝hhvm前強力建議先利用《lnmp一鍵安裝包》安裝完整的lnmp(包括Nginx、PHP、MySQL),通過這種方式我們可以在同一台伺服器對每個虛擬機器主機進行配置,如在同一台伺服器上有www.111cn.net跑在PHP上、另一個網站blog.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-2.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 http://blog.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狀態

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.