2015-09-01 23:51:53 +08:00
|
|
|
|
在 Debian 或者 Ubuntu 上配置高性能的 HHVM、Nginx/Apache 和 MariaDB
|
2015-09-01 16:14:32 +08:00
|
|
|
|
================================================================================
|
2015-09-02 00:48:54 +08:00
|
|
|
|
HHVM全称为 HipHop Virtual Machine, 它是一个由 running Hack(一种编程语言)和 PHP的相关应用组成的开源虚拟机。HHVM 在保证了 PHP 程序员最关注的高灵活性的要求下,通过使用最新编译结果的方式来达到一个客观的性能。到目前为止,HHVM 为 FaceBook 在 HTTP 请求的吞吐量上提高了9倍的性能,在内存的占用上,减少了5倍左右的内存占用。
|
|
|
|
|
|
|
|
|
|
+ [APC (Alternative PHP Cache)][1].
|
|
|
|
|
|
2015-09-01 16:14:32 +08:00
|
|
|
|
HHVM can also be used along with a FastCGI-based web-server like Nginx or Apache.
|
2015-09-02 00:48:54 +08:00
|
|
|
|
同时,HHVM 也可以通过 FastCGI 接口,与像 Nginx 或者 Apache 进行集成。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
安装 HHVM,Nginx和 Apache 还有 MariaDB
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
在本教程中,我们一起来进行 Nginx/Apache web 服务器、 数据库服务器 MariaDB 和 HHVM 的设置。设置中,我们将使用 Ubuntu 15.04 (64 位),同时,该教程也适用于 Debian 和 Linux Mint。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
### Step 1: 安装 Nginx 或者 Apache 服务器 ###
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
1. 首先,先进行一次系统的升级或者更新软件仓库列表.
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# apt-get update && apt-get upgrade
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
System Upgrade
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
2. 正如我之前说的,HHVM 能和 Nginx 和 Apache 进行集成。所以,究竟使用哪个服务器,这是你的自由,不过,我们会教你如何安装这两个服务器。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
#### 安装 Nginx ####
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
我们通过下面的命令安装 Nginx/Apache 服务器
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# apt-get install nginx
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
安装 Nginx 服务器
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
#### 安装 Apache ####
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# apt-get install apache2
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
安装 Apache 服务器
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
完成这一步,你能通过以下的链接看到 Nginx 或者 Apache 的默认页面
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
http://localhost
|
|
|
|
|
OR
|
|
|
|
|
http://IP-Address
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
#### Nginx 默认页面 ####
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
Nginx 默认页面
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
#### Apache 默认页面 ####
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
Apache 默认页面
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
### Step 2: 安装和配置 MariaDB ###
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
3. 这一步,我们将通过如下命令安装 MariaDB,它是一个比 MySQL 更好的数据库
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# apt-get install mariadb-client mariadb-server
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
安装 MariaDB
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
4. 在 MariaDB 成功安装之后,你可以启动它,并且设置 root 密码来保护数据库:
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# systemctl start mysql
|
|
|
|
|
# mysql_secure_installation
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
回答以下问题,只需要按下`y`或者 `n`并且回车。请确保你仔细的阅读过说明。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
Enter current password for root (enter for none) = press enter
|
|
|
|
|
Set root password? [Y/n] = y
|
|
|
|
|
Remove anonymous users[y/n] = y
|
|
|
|
|
Disallow root login remotely[y/n] = y
|
|
|
|
|
Remove test database and access to it [y/n] = y
|
2015-09-02 00:48:54 +08:00
|
|
|
|
Reload privileges tables now[y/n] = y
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
5. 在设置了密码之后,你就可以登陆 MariaDB 了。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# mysql -u root -p
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
### Step 3: 安装 HHVM ###
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
6. 我们需要添加 HHVM 的仓库到你的`sources.list`文件中,然后更新软件列表。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | apt-key add -
|
|
|
|
|
# echo deb http://dl.hhvm.com/ubuntu DISTRIBUTION_VERSION main | sudo tee /etc/apt/sources.list.d/hhvm.list
|
|
|
|
|
# apt-get update
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
**重要**:不要忘记用你的 Ubuntu 发行版型号替换上述的DISTRIBUTION_VERSION (比如:lucid, precise, trusty) 或者是 Debian 的 jessie 或者 wheezy。在 Linux Mint 中也是一样的,不过只支持 petra。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
添加了 HHVM 仓库之后,你就可以安装了。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# apt-get install -y hhvm
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
安装之后,即可启动它,但是它并没有做到开机启动。可以用如下命令做到开机启动。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# update-rc.d hhvm defaults
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
### Step 4: 配置 Nginx/Apache 连接 HHVM ###
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
7. 现在,nginx/apache 和 HHVM 都已经安装完成了,并且都独立运行起来了,所以我们需要对他们进行设置,来让他们互相关联。这个关键的步骤,就是需要nginx/apache 将所有的 php 文件,都交给 HHVM 进行处理。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
如果你用了 Nginx,请按照如下步骤:
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
nginx 的配置文件在 /etc/nginx/sites-available/default, 并且这些配置文件会在 /usr/share/nginx/html 中寻找文件执行,不过,他不知道如何处理 PHP。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
为了确保 Nginx 可以连接 HHVM,我们需要执行如下的脚本。他可以帮助我们正确的配置 Nginx。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
这个脚本可以确保 Nginx 可以对 .hh 和 .php 的做正确的处理,并且通过 fastcgi 与 HHVM 进行通信
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# /usr/share/hhvm/install_fastcgi.sh
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
配置 Nginx、HHVM
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
**重要**: 如果你使用的是 Apache,这边就不需要进行配置了
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
8. 接下来,你需要使用 hhvm 来提供 php 的运行环境。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# /usr/bin/update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
以上步骤完成之后,你现在可以启动并且测试他了。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# systemctl start hhvm
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
### Step 5: 测试 HHVM 和 Nginx/Apache ###
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
9. 为了确认 hhvm 是否工作,你需要在 nginx/apache 的根目录下建立 hello.php。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
# nano /usr/share/nginx/html/hello.php [For Nginx]
|
|
|
|
|
OR
|
|
|
|
|
# nano /var/www/html/hello.php [For Nginx and Apache]
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
在文件中添加如下代码:
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
if (defined('HHVM_VERSION')) {
|
2015-09-02 00:48:54 +08:00
|
|
|
|
echo 'HHVM is working';
|
|
|
|
|
phpinfo();
|
|
|
|
|
} else {
|
|
|
|
|
echo 'HHVM is not working';
|
2015-09-01 16:14:32 +08:00
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
然后访问如下链接,确认自己能否看到 "hello world"
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
http://localhost/info.php
|
|
|
|
|
OR
|
|
|
|
|
http://IP-Address/info.php
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
HHVM Page
|
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
如果 “HHVM” 的页面出现了,那就说明你成功了
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
### 结论 ###
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
2015-09-02 00:48:54 +08:00
|
|
|
|
以上的步骤都是非常简单的,希望你能觉得这是一篇有用的教程,如果你在以上的步骤中遇到了问题,给我们留一个评论,我们将全力解决。
|
2015-09-01 16:14:32 +08:00
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
via: http://www.tecmint.com/install-hhvm-and-nginx-apache-with-mariadb-on-debian-ubuntu/
|
|
|
|
|
|
|
|
|
|
作者:[Ravi Saive][a]
|
2015-09-02 00:48:54 +08:00
|
|
|
|
译者:[MikeCoder](https://github.com/MikeCoder)
|
2015-09-01 16:14:32 +08:00
|
|
|
|
校对:[校对者ID](https://github.com/校对者ID)
|
|
|
|
|
|
|
|
|
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
|
|
|
|
|
|
|
|
[a]:http://www.tecmint.com/author/admin/
|
2015-09-01 23:51:53 +08:00
|
|
|
|
[1]:http://www.tecmint.com/install-apc-alternative-php-cache-in-rhel-centos-fedora/
|