如何在 CentOS 7 上安装 WordPress

在本教程中,我们将向您展示如何在 CentOS 7 上安装和配置 WordPress。对于那些不知道的人,WordPress 是一个用 PHP 编写的在线开源网站创建工具。 但用非极客的话来说,它可能是当今存在的最简单、最强大的博客和网站内容管理系统(或 CMS)。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 我将向您展示在 CentOS 7 服务器上逐步安装 WordPress。

在 CentOS 7 上安装 WordPress

第 1 步。首先,让我们首先确保您的系统是最新的。

yum -y update

步骤 2. 安装 LAMP 服务器。

需要 CentOS 7 LAMP 服务器。 如果您没有安装 LAMP,您可以在此处按照我们的指南进行操作。 此外,为 WordPress 安装所需的 PHP 模块:

yum install php-gd php-xml php-xmlrpc

第 3 步。安装 WordPress。

首先要做的就是去 WordPress的下载页面 并下载最新的稳定版 WordPress,在撰写本文时它是 4.4.1 版:

wget https://wordpress.org/latest.zip

将 WordPress 存档解压缩到服务器上的文档根目录:

unzip -q latest.zip -d /var/www/html/ cd wordpress cp -a * ..

我们将需要更改一些文件夹权限:

chown -R apache:apache /var/www/html

我们需要手动创建上传目录:

mkdir -p /var/www/html/wp-content/uploads

允许 Apache 网络服务器写入上传目录。 通过将此目录的组所有权分配给您的 Web 服务器来执行此操作,这将允许 Apache 创建文件和目录。 发出以下命令:

chown -R :apache /var/www/html/wp-content/uploads

步骤 4. 为 WordPress 配置 MariaDB。

默认情况下,MariaDB 未加固。 您可以使用 mysql_secure_installation 脚本。 您应该仔细阅读以下每个步骤,这些步骤将设置 root 密码、删除匿名用户、禁止远程 root 登录、删除测试数据库和访问安全 MariaDB:

mysql_secure_installation

像这样配置它:

- 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 - Reload privilege tables now? [Y/n] y

接下来,我们需要登录 MariaDB 控制台并为 WordPress 创建一个数据库。 运行以下命令:

mysql -u root -p

这将提示您输入密码,因此输入您的 MariaDB 根密码并点击 Enter. 登录到数据库服务器后,您需要为 WordPress 安装创建一个数据库:

CREATE DATABASE wordpress; GRANT ALL PRIVILEGES on wordpress.* to 'wpuser'@'localhost' identified by 'your_password'; FLUSH PRIVILEGES; exit

步骤 5. 配置 WordPress

在这一步我们将配置WordPress的主要配置文件,我们需要在其中配置它的基本参数,以便它可以连接数据库和用户:

mv wp-config-sample.php wp-config.php

现在使用您喜欢的任何编辑器打开它,以在 WordPress 配置文件中进行任何更改:

nano wp-config.php

以下是我们需要根据之前的数据库和用户设置更新的值:

// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress');  /** MySQL database username */ define('DB_USER', 'wpuser');  /** MySQL database password */ define('DB_PASSWORD', 'your_password');  /** MySQL hostname */ define('DB_HOST', 'localhost');

步骤 6. 配置 Apache WordPress 的网络服务器。

我们将创建一个 Apache WordPress 网站的虚拟主机。 首先,创建’/etc/httpd/conf.d/vhosts.conf‘ 使用您选择的文本编辑器创建文件:

nano /etc/httpd/conf.d/vhosts.conf  IncludeOptional vhosts.d/*.conf

接下来,创建虚拟主机:

mkdir /etc/httpd/vhosts.d/ nano /etc/httpd/vhosts.d/yourdomain.com.conf

添加以下行:

<VirtualHost YOUR_SERVER_IP:80> ServerAdmin [email protected] DocumentRoot "/var/www/html/" ServerName yourdomain.com ServerAlias www.yourdomain.com ErrorLog "/var/log/httpd/yourdomain.com-error_log" CustomLog "/var/log/httpd/yourdomain.com-access_log" combined  <Directory "/var/www/html/"> DirectoryIndex index.html index.php Options FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>

Save 和 close 文件。 重新启动 apache 服务以使更改生效:

systemctl restart httpd.service

接下来,允许 Apache 服务器防火墙中的端口:

firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload

第 7 步。访问 WordPress。

默认情况下,WordPress 将在 HTTP 端口 80 上可用。 打开您喜欢的浏览器并导航到 https://your-domain.com 并完成所需的步骤以完成安装。

恭喜! 您已成功安装 WordPress。 感谢您使用本教程在您的 CentOS 7 系统上安装 WordPress CMS(内容管理系统)。 如需其他帮助或有用信息,我们建议您查看 官方 WordPress 网站.