站长资讯网
最全最丰富的资讯网站

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

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过程。 我希望这个过程简单明了。

赞(0)
分享到: 更多 (0)