使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPress

PHP7.1被制作成了Ubuntu 17.10版本库,WordPress可以完美地运行它。 本教程假设您已经在Ubuntu 17.10上设置了LEMP环境。 如果没有,请查看以下教程。

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

在完成LEMP安装后,回到这里阅读。

第1步:下载WordPress

SSH到你的Ubuntu 17.10服务器并更新现有的软件。

sudo apt update && sudo apt upgrade

接下来,进入wordpress.org下载页面并下载zip压缩文件。 您可以通过右键单击下载按钮并选择复制链接位置来获取直接下载链接。

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr 

然后在命令行提示符处输入wget,然后直接下载链接,将WordPress下载到Ubuntu 17.10服务器。

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

接下来,使用下面的命令解压zip文件。

sudo apt install unzip

sudo unzip latest.zip

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

第2步:为WordPress网站创建一个数据库和用户

使用以下命令以root身份登录到MariaDB shell。(见上图)

sudo mariadb -u root
create database linuxidc;
grant all privileges on linuxidc.* to linuxidc@localhost identified by '你的密码';

 刷新权限表以使更改生效,然后离开MariaDB shell.

flush privileges;

exit;

(见上图)

第3步:配置WordPress

转到您的WordPress目录。

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

复制示例配置文件并将其重命名为wp-config.php。

sudo cp wp-config-sample.php wp-config.php

现在编辑新的配置文件。

sudo nano wp-config.php

找到以下行并用上一步中创建的数据库名称,用户名和密码替换红色文本。

/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

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

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

如下图:

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

修改后如下:

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

保存并关闭文件。 我们还需要使用以下命令将Nginx用户(www-data)设置为WordPress站点目录的所有者。

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

第4步:为WordPress创建一个Nginx服务器文件

我们将在/etc/nginx/conf.d/目录下创建服务器文件。 文件名必须以.conf结尾。

sudo nano /etc/nginx/conf.d/linuxidc.com.conf

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

将以下文本放入文件中。 用您自己的域名替换红色文本。 不要忘记为您的域名创建A记录。

server {
  listen 80;
  server_name www.linuxidc.com linuxidc.com;
  root /usr/share/nginx/linuxidc.com/;
  index index.php index.html index.htm index.nginx-debian.html;

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

  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;

  location = /50x.html {
    root /usr/share/nginx/html;
  }

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

  location ~ /\.ht {
    deny all;
  }
}

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

请注意,如果您遵循我的LEMP教程并安装了PHP7.2,则可以将php7.1-fpm.sock更改为php7.2-fpm.sock,以使Nginx使用PHP7.2。

保存并关闭文件。 然后测试Nginx配置。

sudo nginx -t

如果测试成功,请重新加载Nginx。

sudo systemctl reload nginx

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

最后一步:运行WordPress安装向导

在浏览器地址栏中输入您的域名。 你会看到WordPress的安装向导。 选择一种语言。

linuxidc.com

或者

linuxidc.com/wp-admin/install.php

如果未显示安装向导,则可能需要安装一些PHP7扩展。

sudo apt install php7.1-mbstring php7.1-xml php7.1-mysql php7.1-common php7.1-gd php7.1-json php7.1-cli php7.1-curl

然后重新加载PHP-FPM和Nginx。 现在应该显示向导。

sudo systemctl reload php7.1-fpm

sudo systemctl reload Nginx

创建一个管理员帐户,然后点击安装WordPress按钮。

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

而现在你的新的WordPress网站已经安装。

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

如何将www重定向到非www

我们创建的Nginx配置允许网站访问者通过www和非www域访问网站。 您可以通过转到WordPress仪表板>设置>常规将一个版本重定向到另一个版本。 然后将WordPress地址和网站地址设置为您的首选版本。

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

使用Nginx,MariaDB,PHP7.1(LEMP)在Ubuntu 17.10上安装WordPr

我希望这个教程帮助你在Ubuntu 17.10上安装Nginx,MariaDB和PHP7.1(LEMP环境)的WordPress。 与往常一样,如果你发现这篇文章有用,请分享给更多的朋友。

完整PDF文档可以到Linux公社资源站下载:

------------------------------------------分割线------------------------------------------

具体下载目录在 /2017年资料/12月/18日/Ubuntu 17.10上安装LEMP环境(Nginx,MariaDB,PHP7.1)/

------------------------------------------分割线------------------------------------------

猜你喜欢

转载自www.linuxidc.com/Linux/2017-12/149582.htm