Merge pull request #5104 from GHLandy/master

[Translated] 20170117 How to Install WordPress with HHVM and Nginx on CentOS 7
This commit is contained in:
Xingyu.Wang 2017-02-08 23:14:13 +08:00 committed by GitHub
commit 1200c469ce
2 changed files with 508 additions and 448 deletions

View File

@ -1,448 +0,0 @@
GHLandy Translating
How to Install WordPress with HHVM and Nginx on CentOS 7
============================================================
### On this page
1. [Step 1 - Configure SELinux and add the Epel Repository][1]
2. [Step 2 - Install Nginx][2]
3. [Step 3 - Install and Configure MariaDB][3]
4. [Step 4 - Install HHVM][4]
5. [Step 5 - Configure HHVM][5]
6. [Step 6 - Configure HHVM and Nginx][6]
7. [Step 7 - Create a Virtual Host with HHVM and Nginx][7]
8. [Step 8 - Install WordPress][8]
9. [Reference][9]
HHVM (HipHop Virtual Machine) is an open source virtual machine for executing programs written in PHP and Hack language. HHVM has been developed by Facebook, it provides most features of the current PHP 7 version. To run HHVM on your server, you can use a FastCGI to connect HHVM with a Nginx or Apache web server, or you can use the web server built into HHVM called "Proxygen".
In this tutorial, I will show you how to install WordPress with HHVM and Nginx as web server. I will use CentOS 7 as the operating system, so basic knowledge of CentOS is required.
**Prerequisite**
* CentOS 7 - 64bit
* Root privileges
### Step 1 - Configure SELinux and add the Epel Repository
In this tutorial, we will use SELinux in enforcing mode, so we need the SELinux management tools installed on the system. We will use setools and setrobleshoot to manage SELinux policies.
By default, SELinux is enabled on CentOS 7, We can check that for with command below:
sestatus
getenforce
[
![Check SELinux](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/1.png)
][10]
You can see SELinux is enabled with enforcing mode.
Next, Install setools and setroubleshoot with the yum command.
yum -y install setroubleshoot setools net-tools
When the installation has been completed, you can install the EPEL repository.
yum -y install epel-release
### Step 2 - Install Nginx
Nginx or engine-x is a lightweight web server with high performance and low memory consumption. On CentOS, we can use yum to install the Nginx packages. Make sure you are logged in as root user!
Install nginx with this yum command from the CentOS repository:
yum -y install nginx
Now start Nginx and enable it to be started at boot time with the systemctl command:
systemctl start nginx
systemctl enable nginx
To ensure Nginx is running on our server, visit the server IP address with your browser, or use the curl command as shown below to get the results:
curl 192.168.1.110
I'll cehck it with my web browser here:
[
![Nginx is running](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/2.png)
][11]
### Step 3 - Install and Configure MariaDB
MariaDB is an open source database developed by the original MySQL developer Monty Widenius, it has been forked from the MySQL database but stays compatible with it in its major functions. In this step, we will install MariaDB and configure the root password for the MariaDB database. Then we will create a new database and new user that are required for our WordPress installation.
Install mariadb and mariadb-server:
yum -y install mariadb mariadb-server
Start MariaDB and add the service to be automatically started at boot time:
systemctl start mariadb
systemctl enable mariadb
MariaDB has been started, and now we have to configure the root password for the mariadb/mysql database. Type in the command below to setup the MariaDB root password.
mysql_secure_installation
Type in your new password for the MariaDB root user when requested.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
 ... Success!
Disallow root login remotely? [Y/n] Y
 ... Success!
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
 ... Success!
The MariaDB root password has been configured. Now login to the MariaDB/MySQL shell and create a new database **"wordpressdb"** and a new user **"wpuser"** with password **"wpuser@"** for our WordPress installation. Choose a secure password for your installation!
Login to the MariaDB/MySQL shell:
mysql -u root -p
TYPE YOUR PASSWORD
Create a new database and new user:
create database wordpressdb;
create user wpuser@localhost identified by 'wpuser@';
grant all privileges on wordpressdb.* to wpuser@localhost identified by 'wpuser@';
flush privileges;
\q
[
![Create Database for Wordpress Installation on MariaDB](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/3.png)
][12]
MariaDB has been installed and the new database for our WordPress installation has been created.
### Step 4 - Install HHVM
For the HHVM installation, we need to install many dependencies. We can install HHVM from source by downloading the source from github, or installing prebuilt packages that are available on the internet. In this tutorial, I will install HHVM from prebuilt packages.
Install the dependencies for the HHVM installation
yum -y install cpp gcc-c++ cmake git psmisc {binutils,boost,jemalloc,numactl}-devel \
{ImageMagick,sqlite,tbb,bzip2,openldap,readline,elfutils-libelf,gmp,lz4,pcre}-devel \
lib{xslt,event,yaml,vpx,png,zip,icu,mcrypt,memcached,cap,dwarf}-devel \
{unixODBC,expat,mariadb}-devel lib{edit,curl,xml2,xslt}-devel \
glog-devel oniguruma-devel ocaml gperf enca libjpeg-turbo-devel openssl-devel \
mariadb mariadb-server libc-client make
Then install the HHVM prebuilt packages from [this site][13] with the rpm command.
rpm -Uvh http://mirrors.linuxeye.com/hhvm-repo/7/x86_64/hhvm-3.15.2-1.el7.centos.x86_64.rpm
ln -s /usr/local/bin/hhvm /bin/hhvm
HHVM has been installed, check it with the command below:
hhvm --version
In order to use the php command, we can set the hhvm command as php. So when you type 'php' on the shell, you will see the same result as from the hhvm command.
sudo update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60
php --version
[
![Installing HHVM on CentOS](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/4.png)
][14]
### Step 5 - Configure HHVM
In this step, we will configure HHVM. We will run hhvm as a systemd service. Instead of running it on a system port, we will run hhvm on a unix socket file which is faster.
Go to the systemd directory and create the hhvm.service file.
cd /etc/systemd/system/
vim hhvm.service
Paste the service configuration belowinto that file.
```
[Unit]
Description=HHVM HipHop Virtual Machine (FCGI)
After=network.target nginx.service mariadb.service
[Service]
ExecStart=/usr/local/bin/hhvm --config /etc/hhvm/server.ini --user nginx --mode daemon -vServer.Type=fastcgi -vServer.FileSocket=/var/run/hhvm/hhvm.sock
[Install]
WantedBy=multi-user.target
```
Save the file and exit vim.
Next, go to the hhvm directory and edit the server.ini file.
cd /etc/hhvm/
vim server.ini
Replace the hhvm.server.port on line 7 with unix socket configuration below:
hhvm.server.file_socket = /var/run/hhvm/hhvm.sock
Save the file and exit th editor.
In the hhvm service file, we've defined that hhvm is running under the 'nginx' user, so we must change the owner of the socket file directory to the 'nginx' user. Then we must change the SELinux context of the hhvm directoryto allow access to the socket file.
chown -R nginx:nginx /var/run/hhvm/
semanage fcontext -a -t httpd_var_run_t "/var/run/hhvm(/.*)?"
restorecon -Rv /var/run/hhvm
After rebooting the server, hhvm will not be running because there is no directory for the socket file, so we must create it automatically at the boot time.
Edit the rc.local file with vim.
vim /etc/rc.local
Paste configuration below to the end of line.
```
mkdir -p /var/run/hhvm/
chown -R nginx:nginx /var/run/hhvm/
semanage fcontext -a -t httpd_var_run_t "/var/run/hhvm(/.*)?"
restorecon -Rv /var/run/hhvm
```
Save the file and exit vim. Make the file executable.
chmod +x /etc/rc.local
Reload the systemd service, start hhvm and add it to be started at boot time.
systemctl daemon-reload
systemctl start hhvm
systemctl enable hhvm
Make sure that there is no error. Check that hhvm is running under the socket file with the netstat command.
netstat -pl | grep hhvm
[
![Check the HHVM socket file](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/5.png)
][15]
### Step 6 - Configure HHVM and Nginx
In this step, we will configure HHVM to run with the Nginx web server. We need to create a new hhvm configuration file in the Nginx directory.
Go to the /etc/nginx directory and create a hhvm.conf file.
cd /etc/nginx/
vim hhvm.conf
Paste the configuration below:
```
location ~ \.(hh|php)$ {
    root /usr/share/nginx/html;
    fastcgi_keep_conn on;
    fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}
```
Save and exit.
Next, edit the nginx.conf file and add the hhvm configuration include line.
vim nginx.conf
Add the configuration to the server directive line 57.
```
include /etc/nginx/hhvm.conf;
```
Save and exit.
Then change the SELinux context of the hhvm configuration file.
semanage fcontext -a -t httpd_config_t /etc/nginx/hhvm.conf
restorecon -v /etc/nginx/hhvm.conf
Test the Nginx configuration and restart the service.
nginx -t
systemctl restart nginx
Make sure there is no error.
### Step 7 - Create a Virtual Host with HHVM and Nginx
In this step, we will create a new virtual host configuration with Nginx and hhvm. I will use the domain name **"natsume.co"** for this example. Please use your own domain name and replace it in the configuration files and WordPress installation wherever it appears.
Go to the nginx conf.d directory where we will store virtual host file:
cd /etc/nginx/conf.d/
Create the new configuration "natsume.conf" with vim:
vim natsume.conf
Paste the virtual host configuration below:
```
server {
listen 80;
server_name natsume.co;
# note that these lines are originally from the "location /" block
root /var/www/hakase;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
location = /50x.html {
root /var/www/hakase;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
```
Save and exit.
In our virtual host configuration, we've defined the web root directory for the domain name to be the "/var/www/hakase" directory. That directory does not exist yet, so we have to create it and change the ownership to the nginx user and group.
mkdir -p /var/www/hakase
chown -R nginx:nginx /var/www/hakase
Next, configure the SELinux context for the file and directory.
semanage fcontext -a -t httpd_config_t "/etc/nginx/conf.d(/.*)?"
restorecon -Rv /etc/nginx/conf.d
Finally, test the nginx configuration to ensure there is no error, then restart nginx:
nginx -t
systemctl restart nginx
### Step 8 - Install WordPress
In step 5 we've created the virtual host configuration for our WordPress installation. Now we just have to download WordPress and edit the database configuration by using the database and user that we've created in step 3.
Go to the web root directory "/var/www/hakase"  and download WordPress with the wget command:
cd /var/www/hakase
wget wordpress.org/latest.tar.gz
Extract "latest.tar.gz"  and move all WordPress files and directories to the current directory:
tar -xzvf latest.tar.gz
mv wordpress/* .
Next, copy "wp-config-sample.php" file to "wp-config.php" and edit it with vim:
cp wp-config-sample.php wp-config.php
vim wp-config.php
Set DB_NAME to **"wordpressdb"**, DB_USER to **"wpuser"** and DB_PASSWORD to **"wpuser@"**.
```
define('DB_NAME', 'wordpressdb');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'wpuser@');
define('DB_HOST', 'localhost');
```
Save and exit.
[
![WordPress Configuration](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/6.png)
][16]
Change the SELinux context for the WordPress directory.
semanage fcontext -a -t httpd_sys_content_t "/var/www/hakase(/.*)?"
restorecon -Rv /var/www/hakase
Now open a web browser and type in the domain name of your wordpress domain into the address bar, mine is "natsume.co".
Choose English language and click on 'Continue'.
[
![Wordpress Installation - Choose language](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/7.png)
][17]
Fill in the site title and description with your info and click "Install Wordpress".
[
![Wordpress Installation - Configure Admin and Site Title](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/8.png)
][18]
Wait until the installation is finished. You will see the page below, click on "Log In" to log in to the WordPress admin dashboard:
[
![Wordpress Install - Installation Success with HHVM Nginx on CentOS 7](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/9.png)
][19]
Type in your admin user and password, then click "Log In" again.
[
![Login to wordpress admin dashboard](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/10.png)
][20]
Now you're on the WordPress admin dashboard.
[
![Wordpress Admin Dashboard](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/11.png)
][21]
Wordpress Home Page.
[
![Wordpress Home Page Default](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/12.png)
][22]
Wordpress with Nginx and HHVM on CentOS 7 has been installed successfully.
--------------------------------------------------------------------------------
via: https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/
作者:[ Muhammad Arul][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/
[1]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-configure-selinux-and-add-the-epel-repository
[2]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-install-nginx
[3]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-install-and-configure-mariadb
[4]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-install-hhvm
[5]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-configure-hhvm
[6]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-configure-hhvm-and-nginx
[7]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-create-a-virtual-host-with-hhvm-and-nginx
[8]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-install-wordpress
[9]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#reference
[10]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/1.png
[11]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/2.png
[12]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/3.png
[13]:http://mirrors.linuxeye.com/hhvm-repo/7/x86_64/
[14]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/4.png
[15]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/5.png
[16]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/6.png
[17]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/7.png
[18]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/8.png
[19]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/9.png
[20]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/10.png
[21]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/11.png
[22]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/12.png

View File

@ -0,0 +1,508 @@
如何在 CentOS 7 中通过 HHVM 和 Nginx 安装 WordPress
========================
### 导航
1. [步骤 1 - 配置 SELinux 并添加v EPEL 仓库][1]
2. [步骤 2 - 安装 Nginx][2]
3. [步骤 3 - 安装并配置 MariaDB][3]
4. [步骤 4 - 安装 HHVM][4]
5. [步骤 5 - 配置 HHVM][5]
6. [步骤 6 - 配置 HHVM 和 Nginx][6]
7. [步骤 7 - 通过 HHVM 和 Nginx 创建虚拟主机][7]
8. [步骤 8 - 安装 WordPress][8]
9. [参考链接][9]
HHVM (HipHop Virtual Machine) is an open source virtual machine for executing programs written in PHP and Hack language. HHVM has been developed by Facebook, it provides most features of the current PHP 7 version. To run HHVM on your server, you can use a FastCGI to connect HHVM with a Nginx or Apache web server, or you can use the web server built into HHVM called "Proxygen".
In this tutorial, I will show you how to install WordPress with HHVM and Nginx as web server. I will use CentOS 7 as the operating system, so basic knowledge of CentOS is required.
**先决条件**
* CentOS 7 - 64位
* Root 特权
### 步骤 1 - 配置 SELinux 并添加v EPEL 仓库
在本教程中,我们将以强制模式来运行 SELinux所以我们需要在系统上安装一个 SELinux 管理工具。这里我们使用 setools 和 setrobleshoot 来管理 SELinux 的各项配置。
CentOS 7 已经默认启用 SELinux我们可以通过以下命令来确认
```
# sestatus
# getenforce
```
[![验证 SELinux 运行状态](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/1.png)][10]
如图你能够看到SELinux 已经开启了强制模式。
接下来就是使用 yum 来安装 setools 和 setroubleshoot 了。
```
# yum -y install setroubleshoot setools net-tools
```
安装好这两个后,在安装 EPEL 仓库。
```
# yum -y install epel-release
```
### 步骤 2 - 安装 Nginx
Nginx (发音engine-x) 是一个高性能、低消耗的轻量级 Web 服务器软件。在 CentOS 中可以使用 yum 命令来安装 Nginx 包。记住用 root 用登录系统哦。
使用 yum 命令从 CentOS 仓库中安装 nginx。
```
# yum -y install nginx
```
现在可以使用 systemctl 命令来启动 Nginx同时将其设置为跟随系统启动。
```
# systemctl start nginx
# systemctl enable nginx
```
为确保 Nginx 已经正确运行于服务器中,在浏览上输入服务器的 IP或者如下使用 curl 命令检查显示结果。
```
# curl 192.168.1.110
```
我这里使用浏览器来验证。
[![Nginx 正确运行](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/2.png)][11]
### 步骤 3 - 安装并配置 MariaDB
MariaDB 是由原 MySQL 开发者 Monty Widenius 开发的一款开源数据库软件,它由 MySQL 分支而来,但与 MySQL 的主要用法保持一致。在这一步中,我们要安装 MariaDB 数据库并为之配置好 root 密码,然后在为 WordPress 安装的需要创建一个新的数据库和用户。
安装 mariadb 和 mariadb-server
```
# yum -y install mariadb mariadb-server
```
启动 MariaDB 并添加为服务,以便随系统启动。
```
# systemctl start mariadb
# systemctl enable mariadb
```
现在 MariaDB 已经启动了,还需要为 mariadb/mysql 数据库配置 root 用户密码。输入以下命令来设置 MariaDB root 密码。
```
# mysql_secure_installation
```
提示设置 root 用户密码时,输入新密码进行设置:
```
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
 ... Success!
Disallow root login remotely? [Y/n] Y
 ... Success!
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
 ... Success!
```
这样就设置好了 MariaDB 的 root 密码。现在登录到 MariaDB/MySQL shell 并为 WordPress 的安装创建一个新数据库 **"wordpressdb"** 和新用户 **"wpuser"**,密码设置为 **"wpuser@"**。在你的安装设置中要选用一个安全的密码。
登录到 MariaDB/MySQL shell
```
# mysql -u root -p
```
接着输入你刚刚设置的 root 用户密码。
创建数据库和用户:
```
MariaDB [(none)]> create database wordpressdb;
MariaDB [(none)]> create user wpuser@localhost identified by 'wpuser@';
MariaDB [(none)]> grant all privileges on wordpressdb.* to wpuser@localhost identified by 'wpuser@';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> \q
```
[![为 WordPress 的安装创建数据库和用户](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/3.png)][12]
现在安装好了 MariaDB并为 WordPress 创建好了数据库。
### 步骤 4 - 安装 HHVM
对于 HHVM我们需要安装大量的依赖。作为选择你可以从 GitHub 下载 HHVM 的源码来编译安装,也可以从网络上获取预编译的包进行安装。在本教程中,我使用的是预编译的安装包。
为 HHVM 安装依赖。
```
# yum -y install cpp gcc-c++ cmake git psmisc {binutils,boost,jemalloc,numactl}-devel \
> {ImageMagick,sqlite,tbb,bzip2,openldap,readline,elfutils-libelf,gmp,lz4,pcre}-devel \
> lib{xslt,event,yaml,vpx,png,zip,icu,mcrypt,memcached,cap,dwarf}-devel \
> {unixODBC,expat,mariadb}-devel lib{edit,curl,xml2,xslt}-devel \
> glog-devel oniguruma-devel ocaml gperf enca libjpeg-turbo-devel openssl-devel \
> mariadb mariadb-server libc-client make
```
然后是使用 rpm 安装从 [HHVM 预编译包镜像站点][13] 下载的 HHVM 预编译包。
```
# rpm -Uvh http://mirrors.linuxeye.com/hhvm-repo/7/x86_64/hhvm-3.15.2-1.el7.centos.x86_64.rpm
# ln -s /usr/local/bin/hhvm /bin/hhvm
```
安装好 HHVM 之后使用如下命令按了验证:
```
# hhvm --version
```
为了能使用 PHP 命令,可以把 hhvm 命令设置为 php。这样在 shell 中输入 'php' 命令的时候,你会看到和输入 hhvm 命令一样的结果。
```
# sudo update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60
# php --version
```
[![安装 HHVM](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/4.png)][14]
### 步骤 5 - 配置 HHVM
这一步中,我们来配置 HHVM 以系统服务器来运行。我们不通过端口这种常规的方式来运行它,而是选择使用 unix socket 文件的方式,这样运行的更快速一点。
进入 systemd 配置目录,并创建一个 hhvm.service 文件。
```
# cd /etc/systemd/system/
# vim hhvm.service
```
复制粘贴如下配置到文件中去。
```
[Unit]
Description=HHVM HipHop Virtual Machine (FCGI)
After=network.target nginx.service mariadb.service
[Service]
ExecStart=/usr/local/bin/hhvm --config /etc/hhvm/server.ini --user nginx --mode daemon -vServer.Type=fastcgi -vServer.FileSocket=/var/run/hhvm/hhvm.sock
[Install]
WantedBy=multi-user.target
```
保存文件退出 vim。
接下来,进入 hhvm 目录并编辑 server.ini 文件。
```
# cd /etc/hhvm/
# vim server.ini
```
将第 7 行 hhvm.server.port 替换为 unix socket如下
```
hhvm.server.file_socket = /var/run/hhvm/hhvm.sock
```
保存文件并退出编辑器。
我们已在 hhvm 服务文件中定义了 hhvm 以 'nginx' 用户身份运行,所以还需要把 socket 文件目录的属主变更为 'nginx'。然后我们还必须在 SELinux 中修改 hhvm 目录内容以便让它可以访问这个 socket 文件。
```
# chown -R nginx:nginx /var/run/hhvm/
# semanage fcontext -a -t httpd_var_run_t "/var/run/hhvm(/.*)?"
# restorecon -Rv /var/run/hhvm
```
服务器重启之后hhvm 将不能运行,因为没有存储 socket 文件的目录,所有还必须在启动的时候自动创建一个。
使用 vim 编辑 rc.local 文件。
```
# vim /etc/rc.local
```
将以下配置粘贴到文件末行。
```
# mkdir -p /var/run/hhvm/
# chown -R nginx:nginx /var/run/hhvm/
# semanage fcontext -a -t httpd_var_run_t "/var/run/hhvm(/.*)?"
# restorecon -Rv /var/run/hhvm
```
保存文件并退出 vim。然后给文件赋予执行权限。
```
# chmod +x /etc/rc.local
```
重新加载 systemd 服务,启动 hhvm 并设置为随系统启动。
```
# systemctl daemon-reload
# systemctl start hhvm
# systemctl enable hhvm
```
要确保无误,使用 netstat 命令验证 hhvm 运行于 socket 文件。
```
# netstat -pl | grep hhvm
```
[![Check the HHVM socket file](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/5.png)][15]
### 步骤 6 - 配置 HHVM 和 Nginx
在这个步骤中,我们配置好 HHVM 已让它运行在 Nginx Web 服务中,这需要在 Nginx 目录创建一个 hhvm 的配置文件。
进入 /etc/nginx 目录,创建 a hhvm.conf 文件。
```
# cd /etc/nginx/
# vim hhvm.conf
```
粘贴一下内容到文件中。
```
location ~ \.(hh|php)$ {
    root /usr/share/nginx/html;
    fastcgi_keep_conn on;
    fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}
```
然后,保存并退出。
接下来,编辑 nginx.conf 文件,添加 hhvm 配置文件到 include 行。
```
# vim nginx.conf
```
添加配置到第 57 行的 server 指令中。
```
include /etc/nginx/hhvm.conf;
```
保存并退出。
然后修改 SELinux 中关于 hhvm 配置文件的内容。
```
# semanage fcontext -a -t httpd_config_t /etc/nginx/hhvm.conf
# restorecon -v /etc/nginx/hhvm.conf
```
测试 Nginx 配置并重启服务。
```
# nginx -t
# systemctl restart nginx
```
记住确保没有错误。
### 步骤 7 - 通过 HHVM 和 Nginx 创建虚拟主机
在这一步中能,我们要为 Nginx 和 hhvm 创建一个新的虚拟主机配置文件。这里我使用域名 **"natsume.co"** 来作为例子.你可以使用你主机喜欢的域名,并在配置文件中相应位置以及 WordPress 安装过程中进行替换。
进入 nginx conf.d 目录,我们将在该目录存储虚拟主机文件。
```
# cd /etc/nginx/conf.d/
```
使用 vim 创建一个名为 "natsume.conf" 的配置文件。
```
# vim natsume.conf
```
粘贴以下内容到虚拟主机配置文件中。
```
server {
listen 80;
server_name natsume.co;
# note that these lines are originally from the "location /" block
root /var/www/hakase;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
location = /50x.html {
root /var/www/hakase;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
```
保存并退出。
在这给虚拟主机配置文件中,我们定义该域名的 Web 根目录为 "/var/www/hakase"。目前该目录还不存在,所有我们要创建它,并变更属主为 nginx 用户和组。
```
# mkdir -p /var/www/hakase
# chown -R nginx:nginx /var/www/hakase
```
Next, configure the SELinux context for the file and directory.
```
# semanage fcontext -a -t httpd_config_t "/etc/nginx/conf.d(/.*)?"
# restorecon -Rv /etc/nginx/conf.d
```
最后,测试 nginx 配置文件以确保没有错误后,重启 nginx
```
# nginx -t
# systemctl restart nginx
```
### 步骤 8 - 安装 WordPress
在步骤 5 的时候,我们已经为 WordPress 配置好了虚拟主机,现在只需要下载 WordPress 和使用我们在步骤 3 的时候创建的数据库和用户来编辑数据库配置就好了。
进入 Web 根目录 "/var/www/hakase" 并使用 Wget 命令下载 WordPress
```
# cd /var/www/hakase
# wget wordpress.org/latest.tar.gz
```
解压 "latest.tar.gz" 并将 wordpress 文件夹中所有的文件和目录移动到当前目录:
```
# tar -xzvf latest.tar.gz
# mv wordpress/* .
```
下一步,复制一份 "wp-config-sample.php" 并更名为 "wp-config.php",然后使用 vim 进行编辑:
```
# cp wp-config-sample.php wp-config.php
# vim wp-config.php
```
将 DB_NAME 设置为 **"wordpressdb"**、DB_USER 设置为 **"wpuser"** 以及 DB_PASSWORD 设置为 **"wpuser@"**。
```
define('DB_NAME', 'wordpressdb');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'wpuser@');
define('DB_HOST', 'localhost');
```
保存并退出。
[![WordPress 配置](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/6.png)][16]
修改关于 WordPress 目录的 SELinux 配置指令。
```
# semanage fcontext -a -t httpd_sys_content_t "/var/www/hakase(/.*)?"
# restorecon -Rv /var/www/hakase
```
现在打开 Web 浏览器,在地址栏输入你之前为 WordPress 设置的域名,我这里是 "natsume.co"。
选择英语并点击 '继续 (Continue)'。
[![安装 Wordpress - 语言选择](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/7.png)][17]
根据自身要求填写站点标题和描述并点击 "安装 Wordpress (Install Wordpress)"。
[![安装 Wordpress - 配置管理员账号和站点标题](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/8.png)][18]
耐心等待安装完成。你会见到如下页面,点击 "登录 (Log In)" 来登录到管理面板。
[![安装 Wordpress - 成功安装](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/9.png)][19]
输入你设置的管理员用户账号和密码,在此点击 "登录 (Log In)"。
[![登录到 wordpress 管理面板](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/10.png)][20]
现在你已经登录到 WordPress 的管理面板了。
[![Wordpress 管理面](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/11.png)][21]
Wordpress 主页。
[![Wordpress 默认主页](https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/12.png)][22]
至此,我们已经在 CentOS 7 上通过 Nginx 和 HHVM 成功安装 Wordpress。
### 参考链接
- [https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-opensuse-leap-42-1/](https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-opensuse-leap-42-1/)
- [https://www.nginx.com/blog/nginx-se-linux-changes-upgrading-rhel-6-6/https://www.nginx.com/blog/nginx-se-linux-changes-upgrading-rhel-6-6/](https://www.nginx.com/blog/nginx-se-linux-changes-upgrading-rhel-6-6/)
------------------------------------
译者简介:
[GHLandy](http://GHLandy.com) —— 划不完粉腮柳眉泣别离。
------------------------------------
via: https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/
作者:[ Muhammad Arul][a]
译者:[GHLandy](https://github.com/GHLandy)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/
[1]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-configure-selinux-and-add-the-epel-repository
[2]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-install-nginx
[3]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-install-and-configure-mariadb
[4]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-install-hhvm
[5]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-configure-hhvm
[6]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-configure-hhvm-and-nginx
[7]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-create-a-virtual-host-with-hhvm-and-nginx
[8]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#step-install-wordpress
[9]:https://www.howtoforge.com/tutorial/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/#reference
[10]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/1.png
[11]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/2.png
[12]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/3.png
[13]:http://mirrors.linuxeye.com/hhvm-repo/7/x86_64/
[14]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/4.png
[15]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/5.png
[16]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/6.png
[17]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/7.png
[18]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/8.png
[19]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/9.png
[20]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/10.png
[21]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/11.png
[22]:https://www.howtoforge.com/images/how-to-install-wordpress-with-hhvm-and-nginx-on-centos-7/big/12.png