1. 安装 mariadb 并建库
sudo apt-get install mariadb-server -y | |
sudo systemctl start mariadb | |
sudo systemctl enable mariadb | |
# | |
sudo mysql_secure_installation |
这里执行 sudo mysql_secure_installation
进行安全安装, 直接设置密码, 如password123
. 其它都一直按y
(yes)。记住你设置的密码。
进入 mysql,mysql -u root -p
。输入上面的密码 password123。依次输入一下命令:
CREATE DATABASE wp_db; | |
GRANT ALL ON wp_db.* TO 'wpuser'@'localhost' IDENTIFIED BY 'password123' WITH GRANT OPTION; | |
FLUSH PRIVILEGES; | |
exit |
2. 安装 php
sudo apt-get update | |
apt-get install php7.2 php7.2-cli php7.2-fpm php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl | |
# 检查 php 版本 | |
php -verson |
这里你可以安装其它版本,比如 7.4.
3. 安装 WordPress 并配置
mkdir -p /usr/data/wordpress | |
cd /usr/data/wordpress | |
sudo wget https://wordpress.org/latest.tar.gz | |
sudo tar -zxvf latest.tar.gz | |
sudo mv wordpress/* . | |
sudo rm -rf wordpress latest.tar.gz | |
# 将 wordpress 文件夹中访问权限授权给 www-data:www-data | |
sudo chown -R www-data:www-data * | |
sudo chmod -R 755 * |
现在你应该在路径下,ls
应该可以看到 wp-config-sample.php
. 重命名它,并用 vim 打开修改。
sudo mv wp-config-sample.php wp-config.php | |
# 配置 wp-config.php | |
sudo vim wp-config.php |
在对应的字段修改为一下:
define('DB_NAME', 'wp_db'); | |
define('DB_USER', 'wpuser'); | |
define('DB_PASSWORD', 'password123'); |
并且将:
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'); |
删除,点击这个. 复制替换到删除的位置。
4. 安装 Nginx
sudo apt-get install nginx -y | |
sudo systemctl status nginx | |
sudo systemctl start nginx | |
sudo systemctl enable nginx | |
#sudo systemctl disable nginx |
注意查看 Nginx 的状态,要 Nginx 是 active 的。接下来修改 nginx 的配置. 输入sudo vim /etc/nginx/sites-available/wordpress.conf
,粘贴下面内容。
server { | |
listen 80; | |
listen 443 ssl; | |
if ($server_port !~ 443){rewrite ^(/.*)$ https://$host$1 permanent; | |
} | |
server_name domain.com; | |
ssl_certificate /xx/ssl/fullchain.crt; | |
ssl_certificate_key /xx/ssl/private.pem; | |
ssl_session_timeout 1d; | |
ssl_session_cache shared:MozSSL:10m; | |
ssl_session_tickets off; | |
ssl_protocols TLSv1.2 TLSv1.3; | |
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; | |
ssl_prefer_server_ciphers off; | |
ssl_stapling on; | |
ssl_stapling_verify on; | |
root /usr/data/wordpress; | |
index index.php index.html; | |
access_log /var/log/nginx/www.access.log; | |
error_log /var/log/nginx/www.error.log; | |
location / {try_files $uri $uri/ /index.php?$args;} | |
location ~ \.php$ { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/run/php/php7.2-fpm.sock; | |
} | |
location ~ /\.ht {deny all;} | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { | |
expires max; | |
log_not_found off; | |
} | |
} |
这里 domain.com 改为你自己的域名。/usr/data/wordpress
改为你上面下载安装 wp 的位置。
下面代码依次是:
1. 测试,测试成功后。
2. 建立软链接。
3. 然后重载 nginx。
如果所有的设置都没问题,输入域名就能看到 WordPress 安装界面了。
nginx -t | |
#你输入上面的测试命令后应该出现这个信息 | |
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | |
nginx: configuration file /etc/nginx/nginx.conf test is successful | |
#建立软链接 | |
cd /etc/nginx/sites-enabled | |
sudo ln -s ../sites-available/wordpress.conf . | |
# 重载以应用 nginx 配置 | |
sudo systemctl reload nginx |
正文完