Contents
Preface
WordPress supports multi-site functionality, but I have never felt that there is an urgent need for multi-site, and I don’t want to use the equipment that normally runs the site to experiment, so I have never tried it.
A few days ago, in order to write a solution for WordPress multi-site (see article:Home data center series uses cloudflare tunnel to realize automatic takeover of disaster recovery site when WordPress main site fails), and bought an Alibaba Cloud server for 99 yuan. Now that the plan is written and the cloud server is idle, I thought I might as well take this opportunity to familiarize myself with the WordPress multi-site function so that I can use it immediately when needed in the future.
However, after following various online tutorials for a long time, I found that for a site that has been running for a long time, directly enabling the multi-site function has too many inconveniences:
1. Sub-directory deployment cannot be used
For sites that have been running for more than a month, the sub-directory deployment method is no longer an option (although I don’t use it), but I believe this is a convenient deployment method for many friends.
2. The subdomain model will have some inexplicable problems
After enabling the subdomain-based multisite mode, set up the WordPress site according to the previous domain name access method (see article:A simple tutorial on how to set up WordPress to support multiple domain name access), different inexplicable problems would occur. Finally, the problem was solved by modifying the site url and home in the wp_options table of the wordpress database. However, it didn’t feel right after it was accessible. Sometimes the page could not be opened in the console and needed to be refreshed. In short, it was not very pleasant.
最终,决定采用重新部署新站,开启多站点之后,再恢复其他设置的方式来进行,本文中假定将我的域名”blog.tangwudi.com”对应的wordpress的内容迁移到域名为”test.tangwudi.com”的全新的并开启了多站点wordpress上。
Redeploy WordPress
I won’t go into details here, you can refer to previous articles:Docker series uses Docker to set up a blog slave site based on WordPress and implement regular backup of master-slave site configuration.
Enable multisite
Edit the wp-config.php file and find the following description:
/* That's all, stop editing! Happy publishing. */
Then add the code above this line and save:
define( 'WP_ALLOW_MULTISITE', true );
As shown below:
Then enter the dashboard, and under the Tools menu there is an option to configure the network:
If the following warning appears, it is because the wildcard domain name resolution of *.test.tangwudi.com is not configured to point to the site. Don't worry about it. You only need to configure the subdomain correctly afterwards:
Configure the site network correctly according to the prompts in the red box below:
保存完后重新登录,可以看到多出来一个”我的站点”的选项,里面的”管理网络”就是添加新站点的关键了。
I will not go into details about how to add a new site or how to add an administrator for a site. There are many tutorials online and it is not difficult. This is not the focus of this article.
Migrate old site data to the new site
In fact, many tutorials on how to start WordPress multi-site on the Internet end at the previous section. If it is a brand new site, this is normal. However, if we want to start multi-site on an old site that has been running for a long time and has a lot of content, we need to migrate the data. Of course, this migration is also divided into WordPress program data and content in the database.
Migrate old site wordpress program data
前置知识:wordpress程序有3个目录,分别是”wp-admin”、”wp-incloudes”、”wp-content”。
“wp-admin”目录:包含了控制 WordPress 仪表板的管理文件;”wp-incloudes”:包含了存储管理 WordPress 外观的文件;”wp-content”:包含网站使用的所有主题、插件、升级或上传的文件夹。
为了尽量不影响新站的配置文件,我直接把老站的3个目录:”wp-admin”、”wp-content”、”wp-incloudes”拷贝到新站上,然后访问出现如下报错:
理论上这个时候最佳方式应该是找到哪个配置文件里指定了twentytwentyfour这个主题,然后修改为指向已有的主题,但是我大概看了一下,没找到。。懒得折腾,直接把现有的主题,如下图红框的文件夹”twentytwentytwo”的名字,改成了”twentytwentyfour”,
Then you can access:
use
https://test.tangwudi.com/wp-admin/my-sites.php
Visit and you can see that all the plugins are here:The theme has also come over, but the agron theme used by the old site is not the default theme and is not enabled:
Change the argon theme to enable it for all sites:
Note 1: After enabling multisite, usehttps://test.tangwudi.com/wp-admin
访问的只是主站点”test.tangwudi.com”的仪表盘(后续其他的子站点都是类似的),要全局控制所有站点的插件、主题、文章等内容,需要访问https://test.tangwudi.com/wp-admin/my-sites.php
:
注2:倒腾了很久,最后发现”wp-content”目录下的”plugins”目录,就是原本插件的安装目录,最好还是清空比较好,因为有些插件不支持多站点(或者收费版才支持多站点),直接考过去会引起一堆问题,还是在新站点上根据实际情况重新安装的好,这个问题浪费了我起码一天的时间。
Migrate old site articles and other data to the main site of the new site
Originally, I thought it was very simple: either directly import the wordpress database of the old site to the new site, or use the WPvivid backup plug-in to directly restore the database content, but I found that it didn't work. After directly importing the sql file exported from the old site, the site might not be opened. . , I think it's because the database formats of single site and multi-site are different, and the WPvivid backup plug-in simply said that the free version does not support multi-site and needs to be upgraded to pro. So I adopted a more primitive method: export all data on the old site as an xml file, and then import it on the main site of the new site:
The default maximum upload file limit for WordPress deployed by Docker is 1 MB. If the XML file exported from the old site does not exceed 1 MB, you can import it directly. However, mine is 2.7 MB, which is much larger than 1 MB, so I need to modify the php.ini in the WordPress container.
因为我习惯使用vim,所以需要使用apt安装,但是,默认的wordpress容器里没有”/etc/apt/sources.list”文件,所以无法使用apt,所以我使用如下命令生成了sources.list:
cat < /etc/apt/sources.list deb http://deb.debian.org/debian/ bookworm main contrib non-free-firmware deb http://deb.debian.org/debian/ bookworm-updates main contrib non-free-firmware deb http://deb.debian.org/debian/ bookworm-backports main contrib non-free-firmware deb http://deb.debian.org/debian- security/ bookworm-security main contrib non-free-firmware EOF
Then you can run the following command to install vim:
apt update apt install vim
Finally, edit php.ini using the following command:
cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini vim /usr/local/etc/php/php.ini
Generally, you only need to modify the following two parameters:
upload_max_filesize = 20M # Modify according to your actual needs post_max_size = 30M # Modify according to your actual needs, generally this value should be larger than the above upload_max_filesize
Import the XML file exported from the old site into the main site:
Then start the argon theme in the appearance:
Finally visit the main site, now the basic framework is ready:
All that’s left is to reinstall the plug-ins and see which plug-ins support multi-site mode. If they don’t, you need to find alternatives. You also need to set up the plug-ins. If you really want to do it, it will take some time, so I won’t go into details here.
Summarize
Actually, after going through all this trouble, I found that the multi-site mode is indeed not as convenient as the single-site mode in terms of operation and maintenance. Migrating from a single site to the multi-site mode is still quite troublesome. If one of the sites in the multi-site mode is much more important than the other sites, I think it is better not to use the multi-site mode. Otherwise, if one of the unimportant sites is attacked and has problems, the important sites will also be affected.
In addition, I think that if you want to use the multi-site mode, it is best to plan it from the beginning and start setting up from a brand new site. First, the sub-directory mode is still very practical and there is no need to bother with sub-domain names. If you deploy a cluster of sites and have a detailed plan, the sub-directory mode will be very suitable; second, after running for a month, you can only set up the sub-domain mode. If it has been running for so long, it is estimated that the plug-ins have been configured and run-in. If you use the multi-site mode based on sub-domain names, it will be very troublesome to use the plug-ins, which feels a bit like getting half the result with twice the effort.
使用子域名模式,如果能使用二级域名作为主域名是最好的,比如我这里就是”tangwudi.com”,这样在后续添加其他站点的时候,解析会比较容易添加,按照我文章的”test.tangwudi.com”,如果要添加子域的话,就是”site1.test.tangwudi.com”,这样会比较难看,当然,这个可以使用cname来解决,比如”abc.tangwudi.com cname site1.test.tangwudi.com”,这样访问也没问题,只是配置反向代理的时候访问host做好正确的设置即可。
To sum up, the default single-site mode and multi-site mode each have their own advantages. It is best to make a good plan when building a website and choose the one that suits you best. Once the site is running, it is best not to bother with it anymore.