Remember the experience of a wordpress website migration

Wordpress website migration is difficult, simple but not simple, and there are many and complicated things involved.

I found a lot of information about what plug-ins to use, and some of them need to be paid to use them. After using them, there are various problems.
I made a simple attempt. I don’t need wordpress plug-ins. I am familiar with linux commands and can migrate by myself.

环境: Centos 7 ,  LNMP

旧站点:a.test.com
旧数据库: atest
旧项目代码路径: /var/www/atest

新的站点: b.test.com
新数据库: btest
新项目代码路径: /var/www/btest

Migrate the old a.test.com site to the new b.test.com domain site

Migration steps: Copy wordpress code-->change configuration domain name/database connection information-->export database modify domain name/storage path information-->import new database-->add nginx configuration-->restart service

1. Copy the complete code of a.test.com, here you can compress it or copy a copy of the wordpress code directly

# cp -r atest  btest

2. Modify all characters that appear in the a.test.com domain name in the newly copied wordpress code and replace them with b.test.com

# cd  b-test
# for i in `grep -R "a.test.com" . | awk -F":" '{print $1}' | sort -u`;do sed -i 's/a.test.com/b.test.com/g' $i; done

Modify the wordpress database configuration

# vi  wp-config.php 


Change the new database connection information

So far, the new WordPress site project code has been modified with the new domain name and new database information

3. Export database (mysqldump) and save as sql format file

以 atest数据库为例
 # mysqldump -uroot -p  atest > atest.sql


4. Modify the database file atest.sql (you can also use the wp-cli tool wp search-replace to modify it directly), here is the
safest way to modify the sql file directly to replace the character of a.test.com in the atest.sql database file b.test.com

# sed -i 's/a.test.com/b.test.com/g'  atest.sql


Modify and replace the website storage path in the test.sql database file, my old storage path is /var/www/a-test, and changed to the new storage path /var/www/b-test

# sed -i 's/var\/www\/a-test/var\/www\/b-test/g'  atest.sql


5. Create a new database btest, allowing all permissions of the admin/admin user to be defined according to the situation

    > create database btest character set utf8;
    > grant all privileges on btest.* to 'admin'@'%' identified by 'admin';
    > flush privileges;
    导入修改好的atest.sql数据
    > use btest;
    > source /root/atest.sql;

So far the database migration is completed, and the new site related domain name has been modified, and the path information is stored

6. The last step to configure nginx (supports nginx multi-site configuration)

nginx  https配置 和  root路径根据自身情况自行配置,这里不多说 
 #  vi /etc/nginx/conf.d/btest.conf
server {
  server_name b.test.com;
  fastcgi_pass_request_headers on;
  fastcgi_pass_header Authorization;

   root /var/www/btest;

   #Load configuration files for the default server block.
  rewrite ^/([_0-9a-zA-Z-]+/)?wp-admin$ /$1wp-admin/ permanent;
  if (-f $request_filename){
        set $rule_2 1;
  }
  if (-d $request_filename){
        set $rule_2 1;
  }
  if ($rule_2 = "1"){
  }
  rewrite ^/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) /$2 last;
  rewrite ^/([_0-9a-zA-Z-]+/)?(.*.php)$ /$2 last;
  rewrite /. /index.php last;

   location / {
       index  index.html index.php;
   }
   location ~ ^(.+\.php)(.*)$ {
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_split_path_info       ^(.+\.php)(.*)$;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO       $fastcgi_path_info;
      include        fastcgi_params;
   }
  listen 443 ssl;
  ssl_certificate /etc/nginx/ssl/b.test.com.crt;
  ssl_certificate_key /etc/nginx/ssl/b.test.com.key;
}
server {
    if ($host = b.test.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
  listen 80;
  server_name b.test.com;
  return 404; # managed by Certbot
}

7. Restart the nginx service and visit the new address.


problem:

In the multi-site migration test, it is found that if the domain name of a.test.com is changed to cc.test.com after visiting the new address, it is found that some of the original theme style settings are invalid and need to be reset. Reset is impossible, some I forgot the operation settings

My solution:

The character length of the domain name of a.test.com before the migration is 10, and the character length of the new domain name cc.test.com after the migration is 11. If the character length of the two domain names is different, the style settings will be lost after the migration. The most likely reason is that the database will also save the length of the domain name string to determine the uniqueness. So after changing my domain name to the same character length as b.test.com after the migration, it will display normally after the migration, and the website will be the same as the original wordpress.
This is just a temporary solution for me. It should be possible to directly modify the character length setting of this domain name in the database, but I don't know how to modify it. If there is a better solution, please leave a message to me. I will learn from it. !

Guess you like

Origin blog.51cto.com/8789878/2542722