阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

在Ubuntu 18.04上安装带有Nginx,MariaDB 10和PHP 7的WordPress

169次阅读
没有评论

共计 4534 个字符,预计需要花费 12 分钟才能阅读完成。

WordPress 5 最近发布了一些核心变化,例如 Gutenberg 编辑器。我们的许多读者可能想在自己的服务器上测试它。对于那些人,在本教程中,我们将在 Ubuntu 18.04 上使用 LEMP 设置 WordPress 5。

对于不了解的人,LEMP 是 Linux,Nginx,MySQL / MariaDB 和 PHP 的流行组合。

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

要求

  • 使用 Ubuntu 18.04 最小安装的专用服务器或 VPS(虚拟专用服务器)。

本教程将指导您完成所有必需软件包的安装,创建自己的数据库,准备 vhost 以及通过浏览器完成 WordPress 安装。

在 Ubuntu 18.04 上安装 Nginx Web 服务器

首先,我们将准备我们的 Web 服务器 Nginx。要安装软件包,请运行以下命令:

linuxidc@linuxidc:~$ sudo apt update && sudo apt upgrade
linuxidc@linuxidc:~$ sudo apt install nginx

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

要启动 nginx 服务并在系统引导时自动启动它,请运行以下命令:

linuxidc@linuxidc:~$ sudo systemctl start nginx.service
linuxidc@linuxidc:~$ sudo systemctl enable nginx.service

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

在 Nginx 上为 WordPress 网站创建虚拟主机

现在我们将为您的 WordPress 网站创建虚拟主机。使用您喜欢的文本编辑器创建以下文件:

$ sudo vim /etc/nginx/sites-available/wordpress.conf

在下面的示例中,使用您要使用的域更改 linuxidc.com:

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/wordpress;
    index  index.php index.html index.htm;
    server_name linuxidc.com www.linuxidc.com;

    client_max_body_size 100M;

    location / {
        try_files $uri $uri/ /index.php?$args;       
    }

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass            unix:/var/run/php/php7.2-fpm.sock;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

保存文件并退出。然后启用该站点:

$ sudo ln -s /etc/nginx/sites-available/wordpress.conf  /etc/nginx/sites-enabled/

然后重新加载 nginx:

$ sudo systemctl reload nginx

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

在 Ubuntu 18.04 上安装 MariaDB 10

我们将使用 MariaDB 作为您的 WordPress 数据库。要安装 MariaDB,请运行以下命令:

$ sudo apt install mariadb-server mariadb-client

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

安装完成后,我们将启动它并将其配置为在系统引导时自动启动:

$ sudo systemctl start mariadb.service
$ sudo systemctl enable mariadb.service

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

接下来,通过运行以下命令来保护 MariaDB 安装:

linuxidc@linuxidc:~$ sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we’ll need the current
password for the root user.  If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer ‘n’.

Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 … Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 … Success!

Normally, root should only be allowed to connect from ‘localhost’.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 … skipping.

By default, MariaDB comes with a database named ‘test’ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 – Dropping test database…
 … Success!
 – Removing privileges on test database…
 … Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 … Success!

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

只需在提示中回答问题即可完成任务。

为网站创建 WordPress 数据库

之后,我们将为该用户准备数据库,数据库用户和密码。它们将由我们的 WordPress 应用程序使用,因此它可以连接到 MySQL 服务器。

linuxidc@linuxidc:~$ sudo mariadb -u root

使用下面的命令,我们将首先创建数据库,然后创建数据库用户及其密码。然后我们将授予用户对该数据库的权限。

CREATE DATABASE linuxidc;
grant all privileges on linuxidc.* to linuxidc@localhost identified by ‘ 你的密码 ’;
FLUSH PRIVILEGES;
EXIT;

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

在 Ubuntu 18.04 上安装 PHP 7

由于 WordPress 是用 PHP 编写的应用程序,我们将安装 PHP 和运行 WordPress 所需的 PHP 包,使用以下命令:

$ sudo apt install php-fpm php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-ldap php-zip php-curl

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

安装完成后,我们将启动 php-fpm 服务并启用它:

linuxidc@linuxidc:~$ sudo systemctl start php7.2-fpm
linuxidc@linuxidc:~$ systemctl enable php7.2-fpm
Synchronizing state of php7.2-fpm.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable php7.2-fpm

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

在 Ubuntu 18.04 上安装 WordPress 5

从这一点开始,开始简单的部分。使用以下 wget 命令下载最新的 WordPress 包:

linuxidc@linuxidc:~$ cd /tmp && wget https://wordpress.org/latest.tar.gz

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

然后用以下内容提取存档:

linuxidc@linuxidc:/tmp$ sudo tar -xvzf latest.tar.gz -C /var/www/html

以上将创建我们在 vhost 中设置的文档根目录,即 /var/www/html/wordpress。然后,我们需要更改该目录中文件和文件夹的所有权:

linuxidc@linuxidc:/tmp$ sudo chown www-data: /var/www/html/wordpress/ -R

现在我们准备运行 WordPress 的安装。如果您使用了未注册 / 不存在的域,则可以使用以下记录配置 /etc/hosts 的 hosts 文件:

192.168.1.100 www.linuxidc.com

假设您的服务器的 IP 地址是 192.168.1.100 并且您使用的域是 linuxidc.com 那么您的计算机将在给定的 IP 地址上解析 linuxidc.com。

现在将您的域加载到浏览器中,您应该看到 WordPress 安装页面:

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

在下一页上输入我们之前设置的数据库凭据:

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

提交表单,然后在下一个屏幕上配置您的网站标题,管理员用户和电子邮件:

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

您的安装现已完成,您可以开始管理您的 WordPress 网站。您可以先安装一些全新的主题或通过插件扩展网站功能。

在 Ubuntu 18.04 上安装带有 Nginx,MariaDB 10 和 PHP 7 的 WordPress

总结

就是这样。在 Ubuntu 18.04 上安装设置自己的 WordPress 过程。我希望这个过程简单明了。

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4534字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中