Preface#
In the past couple of days, I received a message from Alibaba Cloud, notifying me that my virtual host is about to expire. I was considering whether to renew it. Actually, I have long thought about consolidating all my websites together, especially since I have a VPS from Vultr. There’s no issue with hosting my websites on it; the main problem is the 备案 (record-filing) issue, which is really a hassle. Without 备案,I can't use domestic CDN services, and my mini-programs can't run properly either, which is quite awkward. After some consideration, I decided to host it on a VPS in the United States for now, and later think about switching to a domestic cloud server, which will probably require re-filing.
By the way! There’s another very important reason... my domain is .me, which cannot be 备案 in China.
Below is the process of migrating my server and some pitfalls I encountered, serving as a record that might help others facing the same issues.
Original Website Data Backup#
- Use an FTP tool to package and download all website data.
- Use Alibaba Cloud's built-in database management tool to back up the entire database, all tables! utf8 encoding!
2.1 Note here, when importing the old database to the new server, I encountered an error:
T FOREIGN_KEY_CHECKS = 0;
This is the method to start and stop foreign key constraints in MySQL; just remove it.
- Method (execute through the command line of the database management tool)
SET FOREIGN_KEY_CHECKS = 0
SET FOREIGN_KEY_CHECKS = 1
If there are no errors, continue with normal operations. If the above error occurs, execute the commands above and re-export the database.
New Server Deployment#
My server is CentOS 7, and I deployed Baota. It's already 2023, and I'm still typing commands!! (Mainly because I'm too lazy...)
-
Use Baota's built-in one-click deployment source code tool to directly deploy Typecho! Since my previous PHP version was 5.5, I also chose 5.5 during deployment to avoid more issues!
-
After successful deployment, enter PHPMyAdmin, delete all tables first! Then import the previously backed-up database! If a 500 error occurs, check if config.inc.php is set correctly.
-
Disable address rewriting (pseudo-static function) in the website backend.
-
Change the website address to http.
-
Import the old Typecho usr directory to your new website root directory for replacement!
-
Enable pseudo-static in the Baota management panel (just select Typecho).
-
Enable pseudo-static in the Typecho website backend (force enable it if the pseudo-static settings are correct).
-
Change the website address to https.
-
Enable https in Baota. I used a Cloudflare certificate, and after successfully deploying the certificate, force redirect to https!
Content Replacement#
Some old data is hard-coded, such as the address of the first image. At this point, we need to manually replace it. If there are few data entries, it can be modified manually. I have dozens of entries to change, so I used a command, which only takes a few seconds.
- Table name: typecho_fields
- Field name: str_value
The general meaning: Replace the content under the field name str_value in the table typecho_fields from blog.45share.com to adao.me (where blog.45share.com is the old blog address).
UPDATE typecho_fields SET str_value = replace(str_value, 'blog.45share.com', 'adao.me')