记一次 wordpress 搬家与速度优化

最近阿里云搞双11促销,原价2700多的云服务器只需要229,配置大致是1M带宽,2G内存,1核,其他参数嘛,不是本文重点哈。买到服务器后,第一件事就是把博客从俄罗斯迎过来,本来是在俄罗斯租了服务器,用途嘛,博客算是其一,但不是最重要的哈哈哈哈,好在我用了 cdn ,速度也还凑合。现在呢,既然有了阿里云服务器,那么把博客迁移到阿里云来就再正常不过了。

搬迁的原因很简单,万一俄罗斯哪家因为各种原因挂了,我的数据虽然每天都会备份到 Google Drive,但是终究会有丢失,得不偿失!本文将主要记录此事,也是个小博客,迁移可能很简单啦。

首先,安装 php,大致如下:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.3-fpm php7.3-common php7.3-mbstring php7.3-xmlrpc php7.3-gd php7.3-xml php7.3-mysql php7.3-cli php7.3-zip php7.3-curl

接着安装 redis ,命令为 sudo apt install redis 但是遇到一个 问题:

installed redis-server package post-installation script subprocess returned error exit status 1

错误信息如下:

After this operation, 0 B of additional disk space will be used.
Setting up redis-server (5:4.0.9-1ubuntu0.2) ...

Job for redis-server.service failed because a timeout was exceeded.
See "systemctl status redis-server.service" and "journalctl -xe" for details.
invoke-rc.d: initscript redis-server, action "start" failed.
● redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; disabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: timeout) since Sun 2019-10-27 22:49:45 CST; 9ms ago
     Docs: http://redis.io/documentation,
           man:redis-server(1)
dpkg: error processing package redis-server (--configure):
 installed redis-server package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of redis:
 redis depends on redis-server (<< 5:4.0.9-1ubuntu0.2.1~); however:
  Package redis-server is not configured yet.
 redis depends on redis-server (>= 5:4.0.9-1ubuntu0.2); however:
  Package redis-server is not configured yet.

dpkg: error processing package redis (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 redis-server
 redis
E: Sub-process /usr/bin/dpkg returned an error code (1)

要解决它,你只需要  sudo vim /etc/redis/redis.conf  将 bind 127.0.0.1 ::1  改为  bind 0.0.0.0,接着安装 mariadb

sudo apt install mariadb-client mariadb-server

然后备份之前的数据,需要登录之前博客的 mysql 服务器,命令如下:mysqldump -u wordpress -p wordpress > wordpress.sql ,这里,假设你之前的博客的数据库用户名为 wordpress,数据库也为 wordpress,-u 后面是用户名,-p 后面是数据库名,最后的 wordpress.sql 为你备份文件的路径以及文件名。备份完毕后,将 wordpress.sql 文件复制到 新博客的 mysql 服务器的 /root/ 目录下面,然后登录新博客的 mysql 服务器,接着执行:

create database wordpress;
grant all privileges on wordpress.* to 'wordpress'@'localhost' identified by 'wordpress';
use wordpress;
sources /root/wordpress.sql;

现在,mariadb、redis、php 都已经就绪,接着我们安装 nginx,即 sudo apt install nginx,最后将以前的博客的网站数据复制到新服务器,具体不再赘述。最后,补充下我的 nginx 的配置文件:

server {
  listen 443 ssl;
  server_name www.kpromise.top;
  server_tokens off;
  index index.php index.html index.htm;
  root /var/www/html/wordpress;
  ssl_certificate /etc/letsencrypt/live/kpromise.top/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/kpromise.top/privkey.pem;
  ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
  ssl_prefer_server_ciphers on;

  location ~\.php$ {
    fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }

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

  location ~/\. {
    deny all;
    access_log off;
    log_not_found off;
  }
}

 

本博客若无特殊说明则由 full-stack-trip 原创发布
转载请点名出处:编程生涯 > 记一次 wordpress 搬家与速度优化
本文地址:https://www.kpromise.top/move-wordpress-to-aliyun-and-speedup/

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注