笔记:在LNMP下部署HHVM

      4 Comments on 笔记:在LNMP下部署HHVM

LNMP,http://lnmp.org/  ,是我目前看见的最方便的一键部署脚本。什么都不用担心,全傻瓜(bi)化操作。
但是,由于他几乎更换了所有的默认目录,HHVM会认不出这货。
网上所有的教程都是从0开始安装Nginx。这多不爽。
这里记录一下具体操作。
环境: Ubuntu 12.04 x64(<----重要!x86不能安装,在这里浪费了两个小时)
1.准备环境,安装HHVM:
Ubuntu有deb包,不必自己编译了。
具体列表看这里:https://github.com/facebook/hhvm/wiki/Prebuilt%20Packages%20for%20HHVM

#安装依赖
sudo add-apt-repository ppa:mapnik/boost
sudo apt-get update
sudo apt-get install libboost1.49-dev libboost-regex1.49-dev \
  libboost-system1.49-dev libboost-program-options1.49-dev \
  libboost-filesystem1.49-dev libboost-thread1.49-dev
#安装HHVM
# If this command is not found then do this: sudo apt-get install python-software-properties
sudo add-apt-repository ppa:mapnik/boost
wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -
echo deb http://dl.hhvm.com/ubuntu precise main | sudo tee /etc/apt/sources.list.d/hhvm.list
sudo apt-get update
sudo apt-get install hhvm

最后你会看见:

********************************************************************
* HHVM is installed.
*
* Running PHP web scripts with HHVM is done by having your webserver talk to HHVM
* over FastCGI. Install nginx or Apache, and then:
* $ sudo /usr/share/hhvm/install_fastcgi.sh
* $ sudo /etc/init.d/hhvm restart
* (if using nginx)  $ sudo /etc/init.d/nginx restart
* (if using apache) $ sudo /etc/init.d/apache restart
*
* Detailed FastCGI directions are online at:
* https://github.com/facebook/hhvm/wiki/FastCGI
*
* If you're using HHVM to run web scripts, you probably want it to start at boot:
* $ sudo update-rc.d hhvm defaults
*
* Running command-line scripts with HHVM requires no special setup:
* $ hhvm whatever.php
*
* You can use HHVM for /usr/bin/php even if you have php-cli installed:
* $ sudo /usr/bin/update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60
********************************************************************

2. 修改/usr/share/hhvm/install_fastcgi.sh
替换L187~220:

nginx_check_installed() {
	echo "Checking if Nginx is installed"
	if [ -d "/usr/local/nginx/conf/" ]
	then
		echo "Detected Nginx installation"
		return 0
	fi
	echo "Nginx not found"
	return 1
}
nginx_check_custom() {
	echo "Checking for custom Nginx configuration"
	if [ ! \( -z "$(grep -E "^[^#]*(fastcgi|hhvm.conf)" "/usr/local/nginx/conf/nginx.conf")" \) \
	  -o ! \( -z "$(grep -ER "^[^#]*(fastcgi|hhvm.conf)" "/usr/local/nginx/conf/")" \) \
          -o ! \( -z "$(grep -ER "^[^#]*(fastcgi|hhvm.conf)" "/usr/local/nginx/conf/vhost/")" \) ]
	then
		echo "WARNING: Detected clashing configuration. Look at /etc/nginx/hhvm.conf for information how to connect to the hhvm fastcgi instance."
		return 0
	fi
	return 1
}
nginx_enable_module() {
	echo "Enabling hhvm Nginx module"
	insert_line "/usr/local/nginx/conf/nginx.conf" 'server_name.*$' 'include hhvm.conf;'
	echo "Finished enabling module"
}
nginx_disable_module() {
	echo "Disabling hhvm Nginx module"
	remove_line "/usr/local/nginx/conf/nginx.conf" "hhvm.conf"
	echo "Finished disabling module"
}

执行。
3.修改相关文件:
1)
/usr/local/nginx/conf
将所有的vhosts都改成

include hhvm.conf;

2)修改~/vhosts.sh:
同样修改。
4.删除启动项:
停止php-fpm服务,删除/etc/init.d/ 里面的php-fpm,这样这东西就不自动启动了。
5.添加监视脚本:
HHVM有可能会直接就死了。需要个脚本盯着。
脚本:

#! /bin/bash
PID="`cat /var/run/hhvm/pid`"
if [ "$PID" == "" ]; then
        /etc/init.d/hhvm start
        if [ "`ps ax -o pid | grep $PID`" == "" ]; then
                /etc/init.d/hhvm stop
                /etc/init.d/hhvm start
        fi
fi

保存为/root/check_hhvm.sh,加入执行权限,添加进cron:
crontab -e

* * * * * root /root/check_hhvm.sh

好了,LNMP已经成功供PHP-FPM换成HHVM了。
从探针可以看见。
www.bilicloud.com/
正运行在HHVM上。
Reference:
 
hjc.im/auto-check-hhvm-status/
www.freehao123.com/hhvm-wordpress/
github.com/facebook/hhvm
github.com/facebook/hhvm/wiki/Prebuilt-Packages-on-Ubuntu-12.04
github.com/facebook/hhvm/wiki/Building-and-installing-HHVM-on-Ubuntu-12.04#installing-boost-149
www.digitalocean.com/community/tutorials/how-to-configure-the-nginx-web-server-on-a-virtual-private-server
lnmp.org/faq/lnmp-software-list.html
blog.csdn.net/xiyuan1999/article/details/8160998
man.ddvip.com/soft/vieditor/vi.html
hjc.im/ubuntufu-wu-qi-shang-de-zui-you-wordpressfang-an/

4 thoughts on “笔记:在LNMP下部署HHVM

    1. Beining Post author

      因为原先有个Nginx,很多vhosts。
      全redo很痛苦,而且添加vhosts不方便。。。
      但是这个改版的Nginx。。。。的确有时闹心啊。。。。挠头

      Reply
    1. Beining Post author

      按理说我可以写个自动化脚本,但是我不是懒嘛。。。而且只有Ubuntu,不能全面啊。
      HHVM明确说不支持x86,所以。。。升级吧。。。

      Reply

Leave a Reply

Your email address will not be published.