最新消息:本站所有跳转向bbs.ykit.cn的附件将全面停止,附件已转移到https://www.qingsj.com

HHvm Apache 2.4 Nginx建站环境搭建方法安装运行WordPress博客

Linux经验 有客 1730浏览 0评论

HHVM是一个强大的可以用于替代PHP的建站环境,出自Facebook团队,它是一个PHPJITJust-In- Time)编译器,同时具有产生快速代码和即时编译的优点。实践证明HHVM可以明显地提升PHP执行速度,节省大量的服务器资源。

HHVM单独安装的话比较简单,官方也针对各种个操作系统推出了详细的说明文档,一般按照文档的说明就可以安装成功,HHVM主要是用于替换PHP,平常的LNMPLinuxNginxMysqLPHP架构被替换为LNMHH即为HHVM)。

本篇文章就来分享一下Debian7 x64CentOS 6.5 (64-bit) Ubuntu 12.04 上搭建HHvm Apache 2.4 Nginx建站环境,同时安装和运行WordPress博客程序,HHvm强大的性能提升能力可以最大限度地提升WordPress运行效率,节省服务器费用。

HHvm Apache 2.4 Nginx建站环境搭建方法安装运行WordPress博客

一、Debian安装HHvmNginx搭建LNMH环境

1
Debian 7 64位的Linux上安装HHvmNginxMysqL,并搭建LHMH建站环境,可以参考这篇文章:HHVM安装使用教程高效的PHP运行环境提升PHP性能9倍以上

二、在CentOS上安装HHvmApache 2.4

1、实际上Apache 2.2也可以与HHvm搭配使用,但是Apache 2.2因为没有mod_proxy_fcgi 还需要安装libapache2-mod-fastcgi,配置起来比较麻烦。安装Apache 2.4可以直接和HHvm整合使用。况且Apache 2.4在性能有很大提升,支持更大流量、更好地支持云计、利用更少的内存处理更多的并发等。

2CentOS上安装HHvmApache 2.4 ,执行以下命令:

cd /etc/yum.repos.d

sudo wget http://repos.fedorapeople.org/repos/jkaluza/httpd24/epel-httpd24.repo

sudo wget http://www.hop5.in/yum/el6/hop5.repo

sudo yum install httpd24-httpd httpd24-httpd-devel httpd24-mod_ssl

sudo yum install hhvm


3
配置Apache 2.4,启用HHvm。进入配置目录:cd /opt/rh/httpd24/root/etc/httpd/conf,编辑:vim httpd.conf,在最后查看这句不要被注释了:IncludeOptional conf.d/*.conf


4、接着进入配置目录:cd /opt/rh/httpd24/root/etc/httpd/conf.d,编辑配置文件:vim httpd24-vhosts.conf(没有的话直接新建一个),加入以下代码,保存。

<virtualhost *:80>

ServerName hhvmtest.dev

DocumentRoot /var/www/html/hhvmtest

ErrorLog logs/hhvmtest.dev-error_log

CustomLog logs/hhvmtest.dev-access_log common

# where HHVM is running

# use either Proxy Pass or ProxyPassMatch

# ProxyPass routes all traffic to FastCGI

ProxyPass / fcgi://127.0.0.1:9000/var/www/html/hhvmtest

# ProxyPassMatch regular expression routes only PHP files

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/hhvmtest/$1

<directory hhvmtest html www var> # relaxed permissions for testing

AllowOverride all

Options -MultiViews

Require all granted

</directory>

</virtualhost>


5
执行命令开启HHvm/usr/bin/hhvm –mode server -vServer.Port=9000 -vServer.Type=fastcgi &


6、执行命令:ps aux | grep hhvm,可以看到HHvm已经运行。
(点击放大)


7、启动Apache命令:sudo service httpd24-httpd start

8、在网站根目录:cd /opt/rh/httpd24/root/var/www/html,新建一个文件目录:mkdir hhvmtest。这个hhvmtest就是网站的根目录。至此CentOS上安装HHvmApache 2.4 完成,

三、Ubuntu 上安装HHvmNginxMysqL

1Ubuntu 上安装HHvmNginxLaravel过程也比较简单,首先是安装Nginx,执行:

sudo apt-get update

sudo apt-get install -y unzip vim git-core curl wget build-essential python-software-properties

sudo add-apt-repository -y ppa:nginx/stable

sudo apt-get update

sudo apt-get install -y nginx

2
接着是安装HHvm了。

#Ubuntu 12.04:

sudo add-apt-repository -y 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 -y hhvm

#Ubuntu 14.04:

wget -O – http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add –

echo deb http://dl.hhvm.com/ubuntu trusty main | sudo tee /etc/apt/sources.list.d/hhvm.list

sudo apt-get update

sudo apt-get install -y hhvm


3
安装完了HHvm会提示如下:(点击放大)


4、这里给出了FastCGI配置的脚本,执行以下命令:

sudo /usr/share/hhvm/install_fastcgi.sh

sudo /etc/init.d/nginx restart #重启Nginx

sudo update-rc.d hhvm defaults #开机启动

sudo service hhvm restart #重启hhvm


5
如果你想像执行PHP命令那样使用HHvm,可以执行:sudo /usr/bin/update-alternatives –install /usr/bin/php php /usr/bin/hhvm 60,这样就可以使用:php -v这样的命令了。


6hhvm的配置文件是放在/etc/nginx/hhvm.conf,打开配置文件,可以看到Nginx已经配置完成。


7、而在/etc/nginx/sites-available/default中也可以看到Nginx包含了hhvm.conf配置文件。


8、网站的根目录是在/usr/share/nginx/html,你可以上传PHP文件到这个目录,查看phpinfo()可以看到是HipHop


9、安装MysqL数据库。执行一句命令:apt-get install mysql-server,安装过程中会要求你设置好MysqL数据库密码。


10、然后将MysqL添加到开机启动,命令:chkconfig add mysqld chkconfig mysql on


11、如果有提示说:/sbin/insserv: No such file or directory,执行:ln -s  /usr/lib/insserv/insserv /sbin/insserv,再执行:chkconfig –levels 235 mysql on

12、执行:chkconfig –list,可以看到所有开机启动项,有三个on以上的就是开机启动项目。重启MysqLservice mysqld start(点击放大)


13、在S-S-H中登录MysqL用命令:mysql -u root -p,然后输入密码。新建freehao123wp数据库:create database freehao123wp;   ,创建用户名和密码:create user freehao123user@’localhost’ identified by ‘123456789’; 


14、授于部分读写权限:grant select on freehao123wp.* to freehao123user@’localhost’;   ,授于全部权限给用户:grant select on freehao123wp.* to freehao123user@’localhost’;  show databases;   是查看数据库(注意:每条命令后面都是以“;”结束)


15、如果是修改MysqL用户名和密码,则执行以下命令:

use mysql;

update user set password=PASSWORD(‘新密码’) where user=’用户名’;

flush privileges;

四、 Ubuntu 上安装HHvmNginxMariaDBWordPress PhpMyAdmin

1Ubuntu 用的是Ubuntu 12.04,先来安装MariaDB。参考:rosehosting。(注:MariaDBMysqL一个分支,完全兼容MysqL,但有多项改进,性能提升,新版的LNMP也增加了MariaDB

apt-get update && apt-get upgrade

apt-get install python-software-properties curl

apt-key adv –recv-keys –keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db

add-apt-repository ‘deb http://ftp.osuosl.org/pub/mariadb/repo/5.5/ubuntu precise main’

apt-get update

echo -e “Package: *\nPin: origin ftp.osuosl.org\nPin-Priority: 1000” | tee /etc/apt/preferences.d/mariadb

apt-get install mariadb-server

2
执行以下命令创建数据库、数据库用户名,方法同上。

mysql -uroot -p

CREATE DATABASE wpdb;

GRANT ALL PRIVILEGES ON wpdb.* TO ‘freehao123’@’localhost’ IDENTIFIED BY ‘123456789’;

FLUSH PRIVILEGES;

\q


3
安装Nginx 1.4.x

add-apt-repository ppa:nginx/stable

apt-get install nginx

4
如果VPS有多核CPU的话,可以在nginx.conf中配置以最大限度地利用好多线程,提升性能。执行以下命令:

sed -i “0,/^worker_processes/ s/^worker_processes .*$/worker_processes `grep -c processor /proc/cpuinfo`;/” /etc/nginx/nginx.conf

5、安装hhvm and hhvm-fastcgi。执行以下命令:

apt-key adv –recv-keys –keyserver keyserver.ubuntu.com 5A16E7281BE7A449

echo deb http://dl.hhvm.com/ubuntu precise main | tee /etc/apt/sources.list.d/hhvm.list

apt-get update

apt-get install hhvm-fastcgi

6
安装完成后,会提示如下:

********************************************************************

* HHVM is installed. Here are some more things you might want to do:

*

* Configure your webserver to use HHVM:

* $ sudo /usr/share/hhvm/install_fastcgi.sh

* $ sudo /etc/init.d/nginx restart

* $ sudo /etc/init.d/apache restart

* $ sudo /etc/init.d/hhvm restart

*

* Start HHVM at boot:

* $ sudo update-rc.d hhvm defaults

*

* Run command line scripts with HHVM:

* $ hhvm whatever.php

*

* 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

********************************************************************

7、如果你想像使用PHP那样使用HHvm,执行:ln -s $(which hhvm) /usr/local/bin/php

8、为域名freehao123.infowww根目录下创建一个网站根目录和日志存放目录。同时下载WordPress放在该目录。

mkdir -p /var/www/freehao123.info/{public_html,logs}

wget -q -O – http://wordpress.org/latest.tar.gz | tar -xzf – –strip 1 -C /var/www/freehao123.info/public_html

chown www-data: -R /var/www/freehao123.info/public_html


9
上面下载的是最新版本的WordPress,英文(不用担心,安装好了WordPress可以直接到后台设置为中文),大家也可以到WordPress中文网站上下载有中文包的WordPress

10、在Nginx中添加虚拟主机。执行:cat <<‘EOF’ > /etc/nginx/sites-available/freehao123.info,将以下命令放在里面(注意:替换为自己的域名和路径):

server {

server_name hhvm.freehao123.info;

listen 80;

root /var/www/freehao123.info/public_html;

access_log /var/www/freehao123.info/logs/access.log;

error_log /var/www/freehao123.info/logs/error.log;

index index.php;

location / {

try_files $uri $uri/ /index.php?q=$uri&$args;

}

location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {

access_log off;

expires max;

}

location ~ /\.ht {

deny all;

}

location ~ \.php$ {

fastcgi_index index.php;

fastcgi_keep_conn on;

include /etc/nginx/fastcgi_params;

fastcgi_pass 127.0.0.1:9000;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}

}

11
最后输入:EOF 保存退出。再执行以下命令:

ln -s /etc/nginx/sites-available/freehao123.info /etc/nginx/sites-enabled/freehao123.info

/etc/init.d/nginx restart

12
Nginxhhvmmysql设置为开机启动,执行命令:

update-rc.d nginx defaults

update-rc.d hhvm defaults

update-rc.d mysql defaults


13 HHvm安装运行WordPress。将你的域名DNS解析到HHvm这个服务器上(刚刚在添加Nginx配置时加入的域名),打开域名就会进入到WordPress安装页面,没有跳转到WordPress安装页面的前检查一下你的WordPress有没有放在该域名的根目录中。


14HHvm运行WordPress没有任何问题,插件安装、主题升级、权限、固定链接等都OK

15、安装PhpMyAdmin来管理MysqL。追求极简的朋友或者喜欢在S-S-H中管理MysqL数据库,但是不少人还是喜欢用PhpMyAdmin来管理MysqL

16、进入你的Web可访问的目录,新建目录用来存放PhpMyAdmin,然后直接下载和解压

wget http://jaist.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.2.2/phpMyAdmin-4.2.2-all-languages.zip

unzip phpMyAdmin-4.2.2-all-languages.zip

17
解压后的PhpMyAdmin建立将目录重命名,以方便访问。用命令新建一个文件夹:mkdir config  ,设置可写:chmod o+rw config

18、然后打开安装页面,类似于:http://hhvm.freehao123.info/db/phpmyadmin/setup/,新建一个服务器。


19、这里可以服务器的端口、名称、SSL、连接方式等进行设置。(点击放大)


20、认证方式一般选择Cookie


21PhpMyAdmin安装还提供了高级功能,有需要调整MysqL的朋友可以直接在这里设置。(点击放大)


22、所以的设置好后点击应用。然后返回到PhpMyAdmin安装页面,在配置文件中选择刚刚创建好的配置文件,点击保存,至此MysqL服务器配置完成。

23、接着将config文件夹生成的config.inc.php移动到PhpMyAdmin根目录当中,同时删除整个config文件夹,将config.inc.php设置为全部不可写:chmod o-rw config.inc.php

24、现在打开PhpMyAdmin访问页面,就会看到登录页面了。输入你的Root账号和密码


25、登录完成后,就可以开始在线管理SQL了。


五、 HHvm Apache 2.4 Nginx运行WordPress博客小结

1HHvm完全可以替换PHP来跑WordPress,鉴于WordPress在处理大数据库和大流量压力时表现不如人意,使用HHvm 来跑WordPress实在是一个不错的选择。

2HHvmNginx是最佳搭档,NginxApache在很多方面还需要完善,安装了MysqL数据库后可以直接使用命令来管理,当然WordPress自带的数据库管理插件足够了。

转载请注明:有客帮 » HHvm Apache 2.4 Nginx建站环境搭建方法安装运行WordPress博客

您必须 登录 才能发表评论!