基于ubuntu14.04下搭建hhvm环境

时间:2021-11-01 20:36:53

                基于ubuntu14.04下搭建hhvm环境

一直想试试facebook的hhvm,今天搭建一下.

HHVM (HipHop Virtual Machine)会将PHP代码转换成高级别的字节码(通常称为中间语言)。然后在运行时通过即时(JIT)编译器将这些字节码转换为x64的机器码。在这些方面,HHVM十分类似与C#的CLR和Java的JVM。

1.编译hhvm

http://github.com/facebook 

基于ubuntu14.04下搭建hhvm环境

找到hhvm

基于ubuntu14.04下搭建hhvm环境

github提供已经编译的[prebuilt package],我们这里就自己执行一下 点击[compile from source ]


基于ubuntu14.04下搭建hhvm环境

我们这里是选择在Ubuntu14.04下编译选择14.04


安装hhvm只能在64位机器里面

You must be running a 64-bit OS to compile & install HHVM.

Using sudo or as root user: (it is recommended to run sudo apt-get update andsudo apt-get upgrade first, or you may receive errors)

Packages Installation

安装编译所需要的库

sudo apt-get install autoconf automake binutils-dev build-essential cmake g++ git \
  libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-regex-dev \
  libboost-system-dev libboost-thread-dev libbz2-dev libc-client-dev libldap2-dev \
  libc-client2007e-dev libcap-dev libcurl4-openssl-dev libdwarf-dev libelf-dev \
  libexpat-dev libgd2-xpm-dev libgoogle-glog-dev libgoogle-perftools-dev libicu-dev \
  libjemalloc-dev libmcrypt-dev libmemcached-dev libmysqlclient-dev libncurses-dev \
  libonig-dev libpcre3-dev libreadline-dev libtbb-dev libtool libxml2-dev zlib1g-dev libevent-dev \
  libmagickwand-dev libinotifytools0-dev libiconv-hook-dev libedit-dev libiberty-dev libxslt1-dev ocaml-native-compilers


Downloading the HHVM source-code

git clone git://github.com/facebook/hhvm.git
cd hhvm
git submodule update --init --recursive
cd ..

Building HHVM

cd hhvm
cmake .
make
sudo make install

Running programs

The hhvm binary can be found in /usr/local/bin.(安装的hhvm在/usr/local/bin)

(1)试验一

cd /var/www/html 
sudo vim index.php 
<?php
echo"hello world\n"
退出保存.

在终端执行一下代码

hhvm index.php

结果如下:

基于ubuntu14.04下搭建hhvm环境

(2)试验二

cd /var/www/html 
sudo vim test.php 

<?php
function sayHello(){
echo "Hello PHP\n";
}
sayHello();

保存退出

hhvm test.php

结果如下:

基于ubuntu14.04下搭建hhvm环境

使用facebook hack 语法

<?php
function sayHello():void{
echo "Hello PHP\n";
}
sayHello();
hhvm test.php
结果如下:

基于ubuntu14.04下搭建hhvm环境

语法不对,所以执行时候需要添加参数

hhvm    -v Eval.EnableHipHopSyntax=true   test.php
结果如下:

基于ubuntu14.04下搭建hhvm环境

(3)试验三

使用hcak语法

<?hh
function sayHello():void{
echo "Hello PHP\n";
}
sayHello();

执行的时候可以不用加 参数

hhvm   test.php
结果如下:

基于ubuntu14.04下搭建hhvm环境

(4)试验四

将文件后缀改成xx.hh

mv test.php test.hh
执行

基于ubuntu14.04下搭建hhvm环境

完成..

Errors

出现错误.


If any errors occur, it may be required to remove the CMakeCache.txt file in the checkout.

If your failure was on the make command, try to correct the error and runmake again,

it should restart from the point it stops. If the error persists, try to remove as explained above.


2.  接下来是对服务器的配置 让hhvm用到服务器中

(1)下载xampp

百度xampp

下载 linux版本的xampp


cd 下载

chmod +x  xampp-linux-x64-1.8.3-4-installer.run

sudo ./xampp-linux-x64-1.8.3-4-installer.run


一直按next

安装完成.



https://github.com/facebook/hhvm  在右边栏找到wiki  进去后选择FastCGI 

Running the server

To run the server in FastCGI mode pass the following parameters to hhvm runtime:

hhvm --mode server -vServer.Type=fastcgi -vServer.Port=9000

The server will now accept connections on localhost:9000. To use a UNIX socket, use theServer.FileSocket option instead:

hhvm --mode server -vServer.Type=fastcgi -vServer.FileSocket=/var/run/hhvm/sock

To turn the server into a daemon, change the value of mode:

hhvm --mode daemon -vServer.Type=fastcgi -vServer.FileSocket=/var/run/hhvm/sock
Note, all the usual options that are accepted by hhvm runtime can be used in FastCGI mode as well. In particular,-vAdminServer.Port=9001 will create an additional "admin" server listening on a port 9001

Making it work with Apache

Apache 2.4

The recommended way of integrating with Apache is usingmod_proxymod_proxy_fcgi. Enable the modules, then in your Apache configuration, add a line as so:

ProxyPass / fcgi://127.0.0.1:9000/path/to/your/www/root/goes/here/
# Or if you used a unix socket
# ProxyPass / unix:/var/run/hhvm/sock|fcgi://127.0.0.1:9000/path/to/your/www/root/goes/here/

This will route all the traffic to the FastCGI server. If you want to route only certain requests (e.g. only those from a subdirectory or ending *.php, you can useProxyPassMatch, e.g.

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/path/to/your/www/root/goes/here/$1 

Consult mod_proxy_fcgi docs for more details on how to useProxyPass andProxyPassMatch.


Apache 2.2

Apache 2.2 does not have mod_proxy_fcgi so you need to install libapache2-mod-fastcgi and then enable the module. Additionally you need theactions module which comes bundled with apache 2.2.

a2enmod actions alias

In you virtual host add these lines:

<IfModule mod_fastcgi.c>
    <FilesMatch \.php$>
        SetHandler hhvm-php-extension
    </FilesMatch>

    <FilesMatch \.hh$>
        SetHandler hhvm-hack-extension
    </FilesMatch>

    Alias /hhvm /hhvm
    Action hhvm-php-extension /hhvm virtual
    Action hhvm-hack-extension /hhvm virtual

    FastCgiExternalServer /hhvm -host 127.0.0.1:9000 -pass-header Authorization -idle-timeout 300
</IfModule>

This will make all .php and .hh files go over to the FastCGI server.Note: It won't work without the "Alias /hhvm /hhvm" line!

If you started hhvm as a socket, change the FastCGIExternalServer line to

FastCGIExternalServer /hhvm -socket /var/run/hhvm/socket -pass-header Authorization -idle-tim

Making it work with Nginx

The default FastCGI configuration from Nginx should work just fine with HHVM-FastCGI. For instance you might want to add the following directives inside one of yourlocation directives:

root /path/to/your/www/root/goes/here;
fastcgi_pass   127.0.0.1:9000;
# or if you used a unix socket 
# fastcgi_pass   unix:/var/run/hhvm/hhvm.sock;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
include        fastcgi_params;

The traffic for the surrounding location directive will be now routed to the HHVM-FastCGI server.















错误问题

-- CMAKE_PREFIX_PATH was missing, proceeding anyway
CMake Warning at CMake/HPHPSetup.cmake:62 (message):
  chrpath not found, rpath will not be stripped from installed binaries
Call Stack (most recent call first):
  third-party/CMakeLists.txt:18 (include)


CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1131 (message):
  Unable to find the requested Boost libraries.

  Unable to find the Boost header files.  Please set BOOST_ROOT to the root
  directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  Boost's headers.
Call Stack (most recent call first):
  CMake/HPHPFindLibs.cmake:33 (find_package)
  CMake/HPHPSetup.cmake:78 (include)
  third-party/CMakeLists.txt:18 (include)


-- Could NOT find LIBGLOG (missing:  LIBGLOG_LIBRARY LIBGLOG_INCLUDE_DIR)
-- Could NOT find LIBJSONC (missing:  LIBJSONC_LIBRARY LIBJSONC_INCLUDE_DIR)
CMake Error at CMake/FindMySQL.cmake:116 (MESSAGE):
  Cannot find MySQL.  Include dir: MYSQL_INCLUDE_DIR-NOTFOUND library dir:
Call Stack (most recent call first):
  CMake/HPHPFindLibs.cmake:69 (find_package)
  CMake/HPHPSetup.cmake:78 (include)
  third-party/CMakeLists.txt:18 (include)


-- Configuring incomplete, errors occurred!
See also "/home/ubuntujobs/hhvm/CMakeFiles/CMakeOutput.log".
See also "/home/ubuntujobs/hhvm/CMakeFiles/CMakeError.log".

-----------------------------------------------------------------------------------------------------

以上错误是因为我在刚装在vbox的Ubuntu 的情况下执行 cmake . 出现的错误


解决方法: