debian安装nginx_如何在Debian 10上使用LEMP(Nginx,MariaDB和PHP)安装WordPress

debian安装nginx

介绍 (Introduction)

WordPress is the most popular CMS (content management system) on the internet. It allows you to easily set up flexible blogs and websites on top of a MySQL-based backend with PHP processing. WordPress has seen incredible adoption and is a great choice for getting a website up and running quickly. After setup, almost all administration can be done through the web frontend.

WordPress是互联网上最流行的CMS(内容管理系统)。 它使您可以在具有PHP处理功能的基于MySQL的后端之上轻松地建立灵活的博客和网站。 WordPress已被广泛采用,是使网站快速启动和运行的理想选择。 设置后,几乎所有管理都可以通过Web前端完成。

In this guide, we’ll focus on getting a WordPress instance set up on a LEMP stack (Linux, Nginx, MariaDB, and PHP) on a Debian 10 server.

在本指南中,我们将重点放在在Debian 10服务器上的LEMP堆栈(Linux,Nginx,MariaDB和PHP)上设置WordPress实例。

先决条件 (Prerequisites)

In order to complete this tutorial, you will need access to a Debian 10 server.

为了完成本教程,您将需要访问Debian 10服务器。

You will need to perform the following tasks before you can start this guide:

在开始本指南之前,您需要执行以下任务:

  • Create a sudo user on your server: We will be completing the steps in this guide using a non-root user with sudo privileges. You can create a user with sudo privileges by following our Debian 10 initial server setup guide.

    在您的服务器上创建sudo用户 :我们将使用具有sudo特权的非root用户来完成本指南中的步骤。 您可以按照Debian 10初始服务器设置指南创建具有sudo特权的用户。

  • Install a LEMP stack: WordPress will need a web server, a database, and PHP in order to correctly function. Setting up a LEMP stack (Linux, Nginx, MariaDB, and PHP) fulfills all of these requirements. Follow this guide to install and configure this software.

    安装LEMP堆栈 :WordPress将需要Web服务器,数据库和PHP才能正常运行。 设置LEMP堆栈(Linux,Nginx,MariaDB和PHP)可以满足所有这些要求。 按照本指南安装和配置此软件。

  • Secure your site with SSL: WordPress serves dynamic content and handles user authentication and authorization. TLS/SSL is the technology that allows you to encrypt the traffic from your site so that your connection is secure. This tutorial will assume that you have a domain name for your blog. You can use Let’s Encrypt to get a free SSL certificate for your domain. Follow our Let’s Encrypt guide for Nginx to set this up.

    使用SSL保护您的网站 :WordPress提供动态内容并处理用户身份验证和授权。 TLS / SSL是允许您加密来自站点的流量以确保连接安全的技术。 本教程将假定您拥有博客的域名。 您可以使用“让我们加密”为您的域获取免费的SSL证书。 请按照我们的Nginx加密算法指南进行设置。

When you are finished with the setup steps, log into your server as your sudo user and continue below.

完成设置步骤后,以sudo用户身份登录服务器并继续以下操作。

第1步-为WordPress创建数据库和用户 (Step 1 — Creating a Database and User for WordPress)

WordPress needs a MySQL-based database to store and manage site and user information. Our setup uses MariaDB, a community fork of the original MySQL project by Oracle. MariaDB is currently the default MySQL-compatible database server available on debian-based package manager repossudo systemctl status php* | grep fpmitories.

WordPress需要一个基于MySQL的数据库来存储和管理站点和用户信息。 我们的设置使用MariaDB ,这是Oracle原始MySQL项目的社区分支。 MariaDB当前是基于debian的软件包管理器repossudo systemctl status php *上可用的默认MySQL兼容数据库服务器。 grep fpmitories。

To get started, log into the MariaDB root (administrative) account. If MariaDB is configured to use the auth_socket authentication plugin, which is the default, you can log into the MariaDB administrative account using sudo:

首先,登录到MariaDB根(管理)帐户。 如果将MariaDB配置为使用auth_socket身份验证插件(默认设置),则可以使用sudo登录到MariaDB管理帐户:

  • sudo mariadb

    苏多·玛丽亚德

If you changed the authentication method to use a password for the MariaDB root account, use the following format instead:

如果您将身份验证方法更改为对MariaDB根帐户使用密码,请改用以下格式:

  • mariadb -u root -p

    mariadb -u根-p

You will be prompted for the password you set for the MariaDB root account.

系统将提示您输入为MariaDB根帐户设置的密码。

First, we can create a separate database that WordPress can control. You can name this whatever you would like, but we will be using wordpress in this guide to keep it simple. You can create the database for WordPress by typing:

首先,我们可以创建一个可由WordPress控制的独立数据库。 您可以随意命名,但是在本指南中我们将使用wordpress使其简单。 您可以通过键入以下内容为WordPress创建数据库:

  • CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

    创建数据库wordpress默认字符集utf8 COLLATE utf8_unicode_ci;

Next, we are going to create a separate MariaDB user account that we will use exclusively to operate on our new database. Creating one-function databases and accounts is a good idea from a management and security standpoint. We will use the name wordpress_user in this guide. Feel free to change this if you’d like.

接下来,我们将创建一个单独的MariaDB用户帐户,该帐户将专门用于在新数据库上进行操作。 从管理和安全的角度来看,创建单一功能的数据库和帐户是一个好主意。 在本指南中,我们将使用名称wordpress_user 。 如果需要,可以随时更改此设置。

The following command will create this account, set a password, and grant access to the database we created. Remember to choose a strong password for your database user:

以下命令将创建此帐户,设置密码,并授予对我们创建的数据库的访问权限。 记住要为数据库用户选择一个强密码:

  • GRANT ALL ON wordpress.* TO 'wordpress_user'@'localhost' IDENTIFIED BY 'password';

    授予对wordpress的所有权限 。* TO'wordpress_user '@'localhost'由' password '标识;

You now have a database and a user account, each made specifically for WordPress. We need to flush the privileges so that the current instance of the database server knows about the recent changes we’ve made:

现在,您有一个数据库和一个用户帐户,每个数据库和一个用户帐户都是专门为WordPress创建的。 我们需要清除特权,以便数据库服务器的当前实例知道我们最近所做的更改:

  • FLUSH PRIVILEGES;

    冲洗特权;

Exit out of MariaDB by typing:

通过键入以下内容退出MariaDB:

  • EXIT;

    出口;

The MariaDB session will exit, returning you to the regular Linux shell.

MariaDB会话将退出,使您返回常规Linux shell。

第2步-安装其他PHP扩展 (Step 2 — Installing Additional PHP Extensions)

When setting up our LEMP stack, we only required a very minimal set of extensions in order to get PHP to communicate with MariaDB. WordPress and many of its plugins leverage additional PHP extensions.

设置LEMP堆栈时,我们只需要很少的扩展集即可使PHP与MariaDB进行通信。 WordPress及其许多插件都利用了其他PHP扩展。

We can download and install some of the most popular PHP extensions for use with WordPress by typing:

我们可以通过键入以下内容来下载并安装一些最流行PHP扩展以用于WordPress:

  • sudo apt update

    sudo apt更新
  • sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip

    sudo apt安装php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip

Note: Each WordPress plugin has its own set of requirements. Some may require additional PHP packages to be installed. Check your plugin documentation to discover its PHP requirements.

注意:每个WordPress插件都有其自己的一组要求。 有些可能需要安装其他PHP软件包。 检查您的插件文档以发现其PHP要求。

When you are finished installing the new extensions, you’ll need to restart the PHP-FPM process so that the running PHP processor can leverage the newly installed features:

完成新扩展的安装后,需要重新启动PHP-FPM流程,以便运行中PHP处理器可以利用新安装的功能:

  • sudo systemctl restart php7.3-fpm.service

    sudo systemctl重新启动php 7.3 -fpm.service

You may need to adjust the highlighted portion of the command with your specific version of PHP-FPM, since that can vary. To verify the exact service name you need to use within systemctl commands, you can use:

您可能需要使用特定版本PHP-FPM来调整命令的突出显示部分,因为这可能会有所不同。 要验证需要在systemctl命令中使用的确切服务名称,可以使用:

  • sudo systemctl status php* | grep fpm.service

    sudo systemctl状态php * | grep fpm.service

You’ll see output like this:

您将看到如下输出:


   
   
Output
● php7.3-fpm.service - The PHP 7.3 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled) CGroup: /system.slice/php7.3-fpm.service

The highlighted string is the name that you’ll need to use when managing the PHP-FPM service with systemctl commands.

高亮显示的字符串是在使用systemctl命令管理PHP-FPM服务时需要使用的名称。

Our PHP extensions are now installed. In the next section, we’ll configure Nginx to use PHP-FPM for handling PHP pages.

我们PHP扩展现已安装。 在下一节中,我们将Nginx配置为使用PHP-FPM处理PHP页面。

步骤3 —配置Nginx (Step 3 — Configuring Nginx)

We’ll now make a few minor adjustments to our Nginx server block files. Based on the prerequisite tutorials, you should have a configuration file for your site in the /etc/nginx/sites-available/ directory configured to respond to your server’s domain name and protected by a TLS/SSL certificate. We’ll use /etc/nginx/sites-available/your_domain as an example here, but you should substitute the path to your configuration file where appropriate.

现在,我们将对Nginx服务器阻止文件进行一些小的调整。 根据先决条件教程,您应该在/etc/nginx/sites-available/目录中具有站点的配置文件,该文件配置为响应服务器的域名并受TLS / SSL证书保护。 我们在这里以/etc/nginx/sites-available/ your_domain为例,但是您应该在适当的地方替换配置文件的路径。

Additionally, we will use /var/www/your_domain as the root directory of our WordPress install. You should use the web root specified in your own configuration.

此外,我们将使用/var/www/ your_domain作为WordPress安装的根目录。 您应该使用自己的配置中指定的Web根目录。

Note: It’s possible you are using the /etc/nginx/sites-available/default default configuration (with /var/www/html as your web root). This is fine to use if you’re only going to host one website on this server. If not, it’s best to split the necessary configuration into logical chunks, one file per site.

注意:您可能正在使用/etc/nginx/sites-available/default默认配置(以/var/www/html作为您的Web根)。 如果您只打算在此服务器上托管一个网站,则可以使用此方法。 如果没有,最好将必要的配置分成逻辑块,每个站点一个文件。

Open your site’s Nginx configuration file with sudo privileges to begin:

使用sudo特权打开站点的Nginx配置文件以开始:

  • sudo nano /etc/nginx/sites-available/your_domain

    须藤纳米/ etc / nginx / sites-available / your_domain

We need to add a few location directives within our main server block. After adding SSL certificates your config may have two server blocks. If so, find the one that contains root /var/www/your_domain and your other location directives and implement your changes there.

我们需要在主server块中添加一些location指令。 添加SSL证书后,您的配置可能有两个 server块。 如果是这样,找到包含root /var/www/ your_domain和其他location指令的目录,然后在其中执行更改。

Start by creating exact-matching location blocks for requests to /favicon.ico and /robots.txt, both of which we do not want to log requests for.

首先创建对/favicon.ico/robots.txt请求的完全匹配的位置块,我们都不希望记录这两个请求。

We will use a regular expression location to match any requests for static files. We will again turn off the logging for these requests and will mark them as highly cacheable since these are typically expensive resources to serve. You can adjust this static files list to contain any other file extensions your site may use:

我们将使用正则表达式位置来匹配对静态文件的任何请求。 我们将再次关闭这些请求的日志记录,并将它们标记为高度可缓存,因为这些请求通常是昂贵的资源。 您可以调整此静态文件列表以包含您的站点可能使用的任何其他文件扩展名:

/etc/nginx/sites-available/your_domain
/ etc / nginx / sites-available / your_domain
server {
    . . .

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
        expires max;
        log_not_found off;
    }
    . . .
}

Inside of the existing location / block, we need to adjust the try_files list so that instead of returning a 404 error as the default option, control is passed to the index.php file with the request arguments.

在现有location /块内部,我们需要调整try_files列表,以便将控制权与请求参数一起传递给index.php文件,而不是将404错误作为默认选项返回。

This should look something like this:

看起来应该像这样:

/etc/nginx/sites-available/wordpress
/ etc / nginx / sites-available / wordpress
server {
    . . .
    location / {
        #try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.php$is_args$args;
    }
    . . .
}

When you are finished, save and close the file.

完成后,保存并关闭文件。

Now, we can check our configuration for syntax errors by typing:

现在,我们可以通过输入以下内容来检查配置中的语法错误:

  • sudo nginx -t

    须藤Nginx -t

If no errors were reported, reload Nginx by typing:

如果没有错误报告,请输入以下命令重新加载Nginx:

  • sudo systemctl reload nginx

    须藤systemctl重新加载nginx

Next, we will download and set up WordPress itself.

接下来,我们将下载并设置WordPress本身。

第4步-下载WordPress (Step 4 — Downloading WordPress)

Now that our server software is configured, we can download and set up WordPress. For security reasons in particular, it is always recommended to get the latest version of WordPress from their site.

现在我们的服务器软件已配置完毕,我们可以下载并设置WordPress。 特别是出于安全原因,始终建议从其站点获取最新版本的WordPress。

Change into a writable directory and then download the compressed release by typing:

切换到可写目录,然后通过键入以下命令下载压缩版本:

  • cd /tmp

    cd / tmp
  • curl -LO https://wordpress.org/latest.tar.gz

    curl -LO https://wordpress.org/latest.tar.gz

Extract the compressed file to create the WordPress directory structure:

解压缩压缩文件以创建WordPress目录结构:

  • tar xzvf latest.tar.gz

    tar xzvf Latest.tar.gz

We will be moving these files into our document root momentarily. Before we do that, we can copy over the sample configuration file to the filename that WordPress actually reads:

我们将暂时将这些文件移到我们的文档中。 在此之前,我们可以将示例配置文件复制到WordPress实际读取的文件名:

  • cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

    cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Now, we can copy the entire contents of the directory into our document root. We are using the -a flag to make sure our permissions are maintained. We are using a dot at the end of our source directory to indicate that everything within the directory should be copied, including any hidden files:

现在,我们可以将目录的全部内容复制到文档根目录中。 我们正在使用-a标志来确保维护我们的权限。 我们在源目录的末尾使用一个点来指示应复制目录中的所有内容,包括所有隐藏文件:

  • sudo cp -a /tmp/wordpress/. /var/www/your_domain

    须藤cp -a / tmp / wordpress /。 / var / www / your_domain

Now that our files are in place, we’ll assign ownership them to the www-data user and group. This is the user and group that Nginx runs as, and Nginx will need to be able to read and write WordPress files in order to serve the website and perform automatic updates.

现在我们的文件就位了,我们将所有权分配给www-data用户和组。 这是Nginx所运行的用户和组,Nginx将需要能够读写WordPress文件才能为网站提供服务并执行自动更新。

  • sudo chown -R www-data:www-data /var/www/your_domain

    须藤chown -R www-data:www-data / var / www / your_domain

Our files are now in our server’s document root and have the correct ownership, but we still need to complete some more configuration.

我们的文件现在位于服务器的文档根目录中,并具有正确的所有权,但是我们仍然需要完成一些配置。

步骤5 —设置WordPress配置文件 (Step 5 — Setting up the WordPress Configuration File)

Next, we need to make a few changes to the main WordPress configuration file.

接下来,我们需要对主要的WordPress配置文件进行一些更改。

When we open the file, our first order of business will be to adjust the secret keys to provide some security for our installation. WordPress provides a secure generator for these values so that you do not have to try to come up with good values on your own. These are only used internally, so it won’t hurt usability to have complex, secure values here.

当我们打开文件时,我们的首要任务是调整秘密密钥,以为我们的安装提供一些安全性。 WordPress为这些值提供了安全的生成器,因此您不必自己尝试提出好的值。 这些仅在内部使用,因此在这里拥有复杂,安全的值不会损害可用性。

To grab secure values from the WordPress secret key generator, type:

要从WordPress密钥生成器获取安全值,请输入:

  • curl -s https://api.wordpress.org/secret-key/1.1/salt/

    curl -s https://api.wordpress.org/secret-key/1.1/salt/

You will get back unique values that look something like this:

您将获得看起来像这样的唯一值:

Warning: It is important that you request unique values each time. Do NOT copy the values shown below!

警告:每次都要求唯一值很重要。 不要复制下面所示的值!


   
   
Output
define('AUTH_KEY', '1jl/vqfs<XhdXoAPz9 DO NOT COPY THESE VALUES c_j{iwqD^<+c9.k<J@4H'); define('SECURE_AUTH_KEY', 'E2N-h2]Dcvp+aS/p7X DO NOT COPY THESE VALUES {Ka(f;rv?Pxf})CgLi-3'); define('LOGGED_IN_KEY', 'W(50,{W^,OPB%PB<JF DO NOT COPY THESE VALUES 2;y&,2m%3]R6DUth[;88'); define('NONCE_KEY', 'll,4UC)7ua+8<!4VM+ DO NOT COPY THESE VALUES #`DXF+[$atzM7 o^-C7g'); define('AUTH_SALT', 'koMrurzOA+|L_lG}kf DO NOT COPY THESE VALUES 07VC*Lj*lD&?3w!BT#-'); define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VY DO NOT COPY THESE VALUES C-?y+K0DK_+F|0h{!_xY'); define('LOGGED_IN_SALT', 'i^/G2W7!-1H2OQ+t$3 DO NOT COPY THESE VALUES t6**bRVFSD[Hi])-qS`|'); define('NONCE_SALT', 'Q6]U:K?j4L%Z]}h^q7 DO NOT COPY THESE VALUES 1% ^qUswWgn+6&xqHN&%');

These are configuration lines that we can paste directly in our configuration file to set secure keys. Copy the output you received now.

这些配置行可以直接粘贴到配置文件中以设置安全密钥。 复制您现在收到的输出。

Now, open the WordPress configuration file:

现在,打开WordPress配置文件:

  • nano /var/www/your_domain/wp-config.php

    纳米/ var / www / your_domain /wp-config.php

Find the section that contains the dummy values for those settings. It will look something like this:

找到包含那些设置的虚拟值的部分。 它看起来像这样:

/var/www/wordpress/wp-config.php
/var/www/wordpress/wp-config.php
. . .

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

. . .

Delete those lines and paste in the values you copied from the command line:

删除这些行,然后粘贴从命令行复制的值:

/var/www/wordpress/wp-config.php
/var/www/wordpress/wp-config.php
. . .

define('AUTH_KEY',         'VALUES COPIED FROM THE COMMAND LINE');
define('SECURE_AUTH_KEY',  'VALUES COPIED FROM THE COMMAND LINE');
define('LOGGED_IN_KEY',    'VALUES COPIED FROM THE COMMAND LINE');
define('NONCE_KEY',        'VALUES COPIED FROM THE COMMAND LINE');
define('AUTH_SALT',        'VALUES COPIED FROM THE COMMAND LINE');
define('SECURE_AUTH_SALT', 'VALUES COPIED FROM THE COMMAND LINE');
define('LOGGED_IN_SALT',   'VALUES COPIED FROM THE COMMAND LINE');
define('NONCE_SALT',       'VALUES COPIED FROM THE COMMAND LINE');

. . .

Next, we need to modify some of the database connection settings at the beginning of the file. You need to adjust the database name, the database user, and the associated password that we configured within MariaDB.

接下来,我们需要在文件开头修改一些数据库连接设置。 您需要调整数据库名称,数据库用户以及我们在MariaDB中配置的关联密码。

The other change we need to make is to set the method that WordPress should use to write to the filesystem. Since we’ve given the web server permission to write where it needs to, we can explicitly set the filesystem method to “direct”. Failure to set this with our current settings would result in WordPress prompting for FTP credentials when we perform some actions. This setting can be added below the database connection settings, or anywhere else in the file:

我们需要进行的另一项更改是设置WordPress用来写入文件系统的方法。 由于我们已授予Web服务器写入所需位置的权限,因此我们可以将文件系统方法显式设置为“ direct”。 如果不使用当前设置对此进行设置,则当我们执行某些操作时,WordPress会提示您输入FTP凭据。 此设置可以添加到数据库连接设置下面,或文件中的其他任何位置:

/var/www/wordpress/wp-config.php
/var/www/wordpress/wp-config.php
. . .

define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpress_user');

/** MySQL database password */
define('DB_PASSWORD', 'password');

. . .

define('FS_METHOD', 'direct');

Save and close the file when you are finished.

完成后保存并关闭文件。

步骤6 —通过Web界面完成安装 (Step 6 — Completing the Installation Through the Web Interface)

Now that the server configuration is complete, we can finish up the installation through the web interface.

现在服务器配置已完成,我们可以通过Web界面完成安装。

In your web browser, navigate to your server’s domain name or public IP address:

在Web浏览器中,导航到服务器的域名或公共IP地址:

http://server_domain_or_IP

Select the language you would like to use:

选择您要使用的语言:

Next, you will come to the main setup page.

接下来,您将进入主设置页面。

Select a name for your WordPress site and choose a username (it is recommended not to choose something like “admin” for security purposes). A strong password is generated automatically. Save this password or select an alternative strong password.

为您的WordPress网站选择一个名称,然后选择一个用户名(出于安全考虑,建议不要选择“ admin”之类的名称)。 系统会自动生成一个强密码。 保存此密码或选择其他强密码。

Enter your email address and select whether you want to discourage search engines from indexing your site:

输入您的电子邮件地址,然后选择是否要阻止搜索引擎将您的网站编入索引:

When you click ahead, you will be taken to a page that prompts you to log in:

当您单击前进时,将转到一个页面,提示您登录:

Once you log in, you will be taken to the WordPress administration dashboard:

登录后,您将被带到WordPress管理仪表板:

From the dashboard, you can begin making changes to your site’s theme and publishing content.

在仪表板上,您可以开始更改网站的主题并发布内容。

结论 (Conclusion)

WordPress should be installed and ready to use! Some common next steps are to choose the permalinks setting for your posts (can be found in Settings > Permalinks) or to select a new theme (in Appearance > Themes). If this is your first time using WordPress, explore the interface a bit to get acquainted with your new CMS, or check the First Steps with WordPress guide on their official documentation.

WordPress应该已安装并可以使用! 接下来的一些常见步骤是选择帖子的永久链接设置(可以在Settings > Permalinks找到)或选择新主题(在“ Appearance > Themes )。 如果这是您第一次使用WordPress,请稍微探索一下界面以熟悉您的新CMS,或者查看其官方文档中的WordPress入门指南。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-nginx-mariadb-and-php-on-debian-10

debian安装nginx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值