用ubuntu 18.04/debian 9安装wordpress with nginx
今天的教程是ubuntu 18.04/debian 9. wordpress是php中最受欢迎,高级,功能丰富和开源内容管理系统的Nginx的逐步安装。
WordPress将其数据存储在MySQL关系数据库中。
虽然WordPress更为人知是博客平台,但它支持其他类型的Web内容管理,如媒体画廊,论坛,邮寄列表和电子商务。
如果我们试图为或者博客找到最佳内容管理系统,请给出WordPress A射击,我们可能会喜欢它。
用ubuntu 18.04/debian 9安装wordpress with nginx
请按照下面的步骤在Ubuntu 18.04/debian 9上安装wordpress with nginx。
第1步:安装MariaDB/MySQL数据库服务器
我们可以选择使用MariaDB或者MySQL数据库服务器。
以下是安装两个中的任何一个的教程:
如何在Debian 9/Debian 8上安装MariaDB 10.3
在Ubuntu 18.04上安装MariaDB 10.3
对于MySQL数据库服务器,使用:
如何在Debian 9/Debian 8上安装MySQL 8.0
如何在Ubuntu 18.04/16.04上安装MySQL 8.0
安装数据库服务器后,需要为WordPress创建数据库和用户
mysql -uroot -p <<MYSQL_SCRIPT
CREATE USER 'wp_user'@'localhost' identified by 'StrongPassword';
CREATE DATABASE wp_db;
GRANT ALL PRIVILEGES ON wp_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
别忘了替换 StrongPassword使用数据库用户密码。
确认用户可以使用提供的密码连接到数据库:
$mysql -u wp_user -p Enter password: <ENTER PASSWORD> Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 34 Server version: 10.1.34-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04 Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | wp_db | +--------------------+ 2 rows in set (0.00 sec) MariaDB [(none)]> QUIT Bye
第2步:安装PHP和所需的扩展
WordPress支持Ubuntu 18.04和Debian 9上可用的默认PHP。
我们将安装PHP和必需的扩展,例如 fpm,mysql,zip等等。
sudo apt-get install php php-{fpm,pear,cgi,common,zip,mbstring,net-socket,gd,xml-util,mysql,gettext,bcmath}
第3步:安装nginx Web服务器
既然我们对创建WordPress的数据库,我们可以在下载和配置WordPress之前安装nginx Web服务器。
通过运行以下命令在Ubuntu 18.04或者Debian 9上安装nginx:
sudo apt update sudo apt -y install nginx
第4步:下载并安装WordPress
下载WordPress的最新版本:
sudo apt -y install wget vim wget wordpress.org/latest.tar.gz
提取存档文件
tar xvf latest.tar.gz
将生成的目录移动到Web文档根目录
sudo mv wordpress /srv/myblog
配置WordPress数据库连接
cd /srv/myblog sudo cp wp-config-sample.php wp-config.php sudo vim wp-config.php
编辑wp-config.php
define('DB_NAME', 'wp_db');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'StrongPassword');
改变所有权 /srv/myblog到Web用户:
sudo chown -R www-data:www-data /srv/myblog
步骤5:配置nginx并完成WordPress安装
我们需要为WordPress创建一个虚拟主机配置文件。
sudo vim /etc/nginx/conf.d/myblog.conf
添加如下内容:
##################################
# WORDPRESS NGINX CONFIGURATIONS
##################################
server {
listen 80;
root /srv/myblog;
server_name example.com;
access_log /var/log/nginx/wp_client_access.log;
error_log /var/log/nginx/wp_client_error.log;
location/{
index index.php index.html;
try_files $uri $uri//index.php?$args;
}
# Specify a charset
charset utf-8;
# GZIP
gzip off;
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$$scheme://$host$uri/permanent;
# Prevents hidden files (beginning with a period) from being served
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
###########
# SEND EXPIRES HEADERS AND TURN OFF 404 LOGGING
###########
location ~* ^.+.(xml|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)${
access_log off;
log_not_found off;
expires max;
}
# Pass all .php files onto a php-fpm or php-cgi server
location ~ \.php${
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_read_timeout 3600s;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
}
# ROBOTS
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# RESTRICTIONS
location ~* /(?:uploads|files)/.*\.php${
deny all;
}
}
验证配置语法:
# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
重新启动nginx web服务器
sudo systemctl restart nginx sudo systemctl enable nginx
访问WordPress安装向导页面 https://example.com完成安装。1.选择语言
2.提供标题,管理员用户名,密码和电子邮件地址
3单击"安装WordPress"按钮以完成WordPress安装。4.使用集合用户名和密码登录WordPress管理仪表板

