如果您想将 WordPress 站点(move WordPress site)从托管/非托管/共享/专用/ VPS托管移动到另一个没有任何重大停机时间的站点,这就是您需要的指南。如果您已经拥有SSL或者您想将站点从共享主机移动到VPS,您可能会面临一些停机时间。
将 WordPress(Migrate WordPress)站点从一台服务器迁移到另一台服务器
如果您有一个托管在Hostgator、Bluehost、Siteground等共享主机上的网站,这些是您需要遵循的步骤。通常,这些共享托管公司提供 cPanel,因此,在 cPanel 的帮助下移动所有内容非常容易。
首先,您需要备份所有内容,包括文件和数据库。
要备份您的文件,您必须打开应由您的托管服务提供商提供的“文件管理器”,您可以在您的 cPanel 中找到它。如果您在托管帐户中添加了多个域,则需要相应地导航。否则,您可以找到一个名为public_html的目录,您将在其中获取包括WordPress核心在内的所有文件。选择(Select)所有文件,创建一个扩展名为 .zip 的存档并制作压缩文件夹。将其下载到您的计算机上。不要忘记单个文件——主要是.htaccess,默认情况下它是隐藏的。
现在你需要备份你的数据库。由于您已经拥有 cPanel 和 phpMyAdmin,您可以使用该工具下载数据库。为此,请打开您的 cPanel 并转到 phpMyAdmin。您可以在左侧找到您的数据库名称。选择它并切换到导出(Export )选项卡。
从这里,您需要选择Quick作为Export method,并从Format下拉菜单中选择SQL 。之后,单击“开始”(Go )按钮开始下载。
现在,您必须转到新的托管帐户并首先添加域。如果您在注册新帐户时已经这样做了,则不必再次这样做。但是,如果您还没有这样做,您需要将您的域添加到您的 cPanel。您可以使用Addon Domains选项(它可以不同,但术语保持相似)。
之后,您必须为您的新网站创建一个数据库。创建时,不要忘记记下数据库名称、用户 ID 和密码。没有这些,您将无法将文件映射到数据库。
您可以在您的 cPanel 中找到MySQL 数据库(MySQL Database)选项,您可以使用它来完成它。要创建数据库,您需要输入数据库名称、用户 ID 和密码。您必须创建数据库名称文件,然后添加用户 ID 和密码。之后,您必须允许用户 ID 访问数据库。为此,您可以使用名为Add user to database的部分。
单击“添加(Add )”按钮后,您应该会找到一个窗口,您必须允许/阻止用户 ID 访问数据库的某些内容。要解决任何问题,您可以在ALL PRIVILEGES选项中打勾,然后单击Make Changes按钮。
现在,您需要上传从旧主机帐户下载的数据库。为此,打开 phpMyAdmin 应用程序并从左侧选择数据库。之后,转到导入(Import)选项卡。您应该找到一个名为“选择文件”(Choose File)的按钮。单击(Click)它并从您的计算机中选择文件。
请勿更改屏幕上的任何内容并直接单击Go按钮。完成上传需要几秒钟。
下一步是上传从旧服务器下载的文件。为此,请使用文件管理器(File Manager)打开域的根目录并转到public_html。如果您有一个域,请在此处上传所有文件。如果您有多个域,请导航到该域的根目录并在那里上传文件。上传后需要解压压缩包。
现在,您需要用新的数据库详细信息替换旧的数据库详细信息。为此,打开wp-config.php文件并替换数据库名称、用户 ID 和密码。更改后,保存文件。
接下来,您需要更改域的名称服务器。为此,请从您的主机帐户中获取名称服务器,然后在您的域的控制面板中输入它们。不同(Different)的域名提供商有不同的选择。但是,您可以搜索它或向支持团队寻求帮助。
完成该步骤后,您就完成了将文件从一台主机迁移到另一台主机的过程。传播所有内容可能需要长达 48 小时。同时,你可以打开这个网站(this website),看看你的网站是显示新IP还是旧IP。如果新 IP 地址可见,则传播完成。您还可以使用计算机上的 ping 工具来检查 IP 地址。如果您的计算机显示旧 IP 但在线工具显示新 IP,则需要刷新 DNS 缓存(flush your DNS cache)。
如何将WordPress网站从共享主机移动到非托管VPS
将WordPress(WordPress)网站从共享主机移动到另一个共享主机非常容易,因为它们都有 cPanel,它具有所有必要的工具,如 phpMyAdmin、文件管理器(File Manager)等。但是,有很多人经常选择非托管VPS,因为您可以获得 root 访问权限,并且非托管VPS比共享托管相对便宜。
什么是非托管 VPS
VPS表示虚拟专用服务器(Private Server)。简单来说,如果您的VPS主机账户没有 cPanel,您可以称其为非托管VPS。要访问非托管VPS服务器,您需要一些工具,例如Putty、FTP 客户端(FTP client)(例如Filezilla或Cyber duck(Cyberduck) ) 。非托管VPS提供商的一些示例包括Digital Ocean、Linode、Vultr等。
如果您已经购买了非托管VPS帐户,并且您一无所知,但您想将您的WordPress网站从共享主机迁移到非托管VPS,您可以按照以下步骤操作。
在开始之前,请从此处(here)下载 Cyberduck(download Cyberduck)和 Putty 。此外,您需要下载旧站点备份,包括所有文件和数据库。上面提到了这些步骤。
现在,您应该知道一些公司,如WordPress、Ghost、Joomla、Discourse等,提供一键式应用程序,而其他如Linode不提供这样的东西。在这种情况下,您可以使用其他一些第三方工具,如ServerPilot、ServerAvatar、EasyEngine等。其中,ServerPilot最近已成为付费工具——但就安全性和可用性而言,这是迄今为止最好的。
无论您使用哪个托管帐户,您都必须先创建服务器,安装操作系统,并记下 root 密码。不同(Different)的托管服务提供商有不同的选择,但核心是一样的。但是,如果您使用ServerPilot,则必须使用 64 位版本的Ubuntu LTS 16.04或 18.04。他们不支持其他任何东西。
因此,您需要在您的托管帐户中添加域名并更改您的域帐户中的名称服务器。此外,建议从现在开始使用VPN。否则(Otherwise),您将无法从您的计算机中检测到新的主机帐户。
如果您使用Digital Ocean或Vultr的一键式应用程序,您可以快速安装WordPress。如果您选择此方法,您可以在此处找到您的WordPress安装文件:
/var/html
如果您使用 ServerPilot 安装WordPress,您可以在此处找到您的WordPress安装文件:
/srv/users/user_name/apps/app_name/public
您应该找到一个名为wp-config.php的文件。下载它并保留数据库用户名和密码。不要忘记这样做。
您必须删除所有WordPress安装文件。由于 wp-admin、wp-content 和 wp-includes 文件夹需要很长时间才能删除,您可以使用 putty 删除它们。为此,打开Putty并输入服务器的 IP 地址。确保(Make)端口(Port)设置为22。之后,单击打开(Open )按钮并确认连接。之后,您需要输入您的用户名和密码。输入root作为用户名。在您的主机帐户中创建服务器后,您应该在同一页面上或通过电子邮件获得密码。
接下来,输入:
一键应用用户:(One-click app users:)
rm -rf /var/html/wp-admin
rm -rf /var/html/wp-content
rm -rf /var/html/wp-includes
ServerPilot 用户:(ServerPilot users:)
rm -rf /srv/users/user_name/apps/app_name/public/wp-admin
rm -rf /srv/users/user_name/apps/app_name/public/wp-content
rm -rf /srv/users/user_name/apps/app_name/public/wp-includes
之后,您可以打开Cyberduck应用程序,导航到该文件夹并删除其他安装文件。
在下一步中,您需要上传压缩(zipped)的备份文件。这样做,然后解压缩文件。如果解压时遇到任何错误,可以在Putty中输入以下命令:
sudo apt-get update
sudo apt-get install unzip
解压缩这些文件后,您必须替换数据库信息。为此,打开您下载的 wp-config.php 文件。接下来,打开您刚刚上传的当前 wp-config.php 文件。从下载的 wp-config.php 文件中复制数据库名称、用户 ID 和密码,并将其替换为上传的 wp-config.php 文件。
之后,您需要安装 phpMyAdmin。否则,您无法导入数据库。为此,请按照以下步骤操作。
S0 从这里(here)下载最新版本的 phpMyAdmin并将 zip 文件上传到您的根目录。之后,解压缩文件并重命名。确保(Make);你使用了一个难以猜测的名字。例如,如果您选择abcd,您可以像这样打开 phpMyAdmin:
http://your-domain-name/abcd
选择名称后,打开文件夹并找到config.sample.inc.php文件。您可以将其重命名为config.inc.php。之后,使用编辑器打开此文件并进行如下更改:
$cfg['blowfish_secret']
它应该如下所示:
$cfg['blowfish_secret'] = 'k7i259684(*^3q42bd^$4353yow*q5Trs^1'
现在,打开 phpMyAdmin,输入数据库用户 ID 和密码登录。然后,选择左侧的数据库名称,选择所有数据库表,并相应地删除它们。
然后,转到导入(Import )选项卡,并导入您之前下载的数据库。
就这样!现在您的网站应该可以在新的托管帐户上正常运行。
如何将WordPress网站从非托管VPS移动到共享主机
这很容易,也不需要太多时间。最好的事情是步骤几乎相同。除了,如果你还没有安装 phpMyAdmin,你需要这样做来下载数据库。
简而言之,这些是您需要遵循的步骤。
- (Download)从VPS(VPS)帐户下载所有文件。
- 下载数据库。
- 在您的共享主机帐户中创建一个数据库并将该数据库分配给一个用户。
- 将所有文件上传到您的新主机帐户。
- 更改 wp-config.php 文件中的数据库名称、用户名和密码。
- 在域控制面板中更改名称服务器。
就这样!
更换服务器后的常见问题
完成迁移后,您可能会遇到不同的问题。其中一些在下面提到。
主页正在打开,但帖子显示 404 错误(Homepage is opening, but posts are showing 404 error)
检查您的 .htaccess 文件并将其用作默认值:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
另外,去这里:
/etc/apache2/apache2.conf
并进行此更改:
<Directory /var/www/>
AllowOverride All
</Directory>
无法安装插件,询问 FTP 登录详细信息(Unable to install plugins, asking FTP login details)
这是人们遇到的一个非常普遍的问题。您需要打开 wp-config.php 文件并将其粘贴到底部;
define( 'FS_METHOD', 'direct' );
安装失败:无法创建目录(Installation failed: Could not create directory)
如果您无法上传图片、安装插件、更新主题或插件,并且出现上述错误,您可以通过更改权限来解决此问题。打开腻子(Open Putty)并输入:
chmod -R 775 directory_path
您可以从此处(here)了解有关文件权限的更多信息。
使用 htaccess 将非 www 重定向到 www(Redirect non-www to www using htaccess)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^your-domain-name.com [NC]
RewriteRule ^(.*)$ http://www.your-domain-name.com/$1 [L,R=301,NC]
将 www 重定向到非 www(Redirect www to non-www)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.your-domain-name.com [NC]
RewriteRule ^(.*)$ http://your-domain-name.com/$1 [L,R=301]
但是,您还应该输入带有www以及@或空白的CNAME记录。
请(Please)注意,您需要单独安装SSL。如果您的托管服务提供商提供免费SSL,您可以要求他们为您安装。否则,您可以使用 Let's Encrypt,它提供免费但共享的SSL证书。
How to move WordPress site from one host to another
If you want tо move WordPress site from a managed/unmanaged/shared/dedicated/VPS hosting to another without any major downtime, this is the guide you need. If you already have SSL or you want to move a site from shared hosting to VPS, you might face a little bit of downtime.
Migrate WordPress site from one server to another
If you have a website hosted on shared hosting like Hostgator, Bluehost, Siteground, etc., these are the steps you need to follow. Generally, these shared hosting companies provide a cPanel and therefore, it is quite easy to move everything with the help of the cPanel.
First, you need to backup everything including your files as well as the database.
To back up your files, you have to open the ‘File Manager’ that should be provided by your hosting provider, and you can find it in your cPanel. If you have added multiple domains in your hosting account, you need to navigate accordingly. Otherwise, you can find a directory called public_html, where you will get all the files including WordPress core. Select all the files, create an archive with a .zip extension and make the compressed folder. Download it to your computer. Do not forget a single file – mainly the .htaccess, which is hidden by default.
Now you need to backup your database. As you already have cPanel and phpMyAdmin, you can use that tool to download the database. To do so, open up your cPanel and go to phpMyAdmin. You can find your database name on your left-hand side. Select that and switch to Export tab.
From here, you need to choose Quick as Export method, and SQL from the Format drop-down menu. After that, click the Go button to start the download.
Now, you have to go to your new hosting account and add the domain first. If you have already done that while signing up for a new account, you do not have to do that again. However, if you haven’t done that already, you need to add your domain to your cPanel. You can use the Addon Domains option (it can be different, but the term remains similar).
After that, you have to create a database for your new website. While creating, do not forget to note down the database name, user ID and password. Without these, you would not be able to map your files to your database.
You can find the MySQL Database option in your cPanel that you can use to get it done. To create a database, you need to enter a database name, user ID, and password. You have to create the database name file and then add the user ID and password. After that, you have to permit the user ID to access the database. For that, you can use the section called Add user to database.
After clicking the Add button, you should find a window where you have to allow/block user ID to access certain things of the database. To get rid of any problem, you can make a tick in the ALL PRIVILEGES option and click the Make Changes button.
Now, you need to upload the database that you downloaded from the old hosting account. For that, open phpMyAdmin app and select the database from your left-hand side. After that, go to Import tab. You should find a button called Choose File. Click on that and select the file from your computer.
Do not change anything on the screen and click the Go button directly. It should take a couple of seconds to finish the upload.
The next step is to upload the files that you downloaded from the old server. To do so, open up your root directory of your domain using the File Manager and go to public_html. If you have one domain, upload all the files here. If you have multiple domains, navigate to that domain’s root directory and upload files there. After uploading, you need to unzip the zipped folder.
Now, you need to replace the old database details with the new one. For that, open up the wp-config.php file and replace database name, user ID and password. After changing, save the file.
Next, you need to change the name server of your domain. For that, get the name server from your hosting account and enter them in your domain’s control panel. Different domain provider has different options. However, you can search for that or ask the support team for help.
With that step done, you are finished migrating your files from one host to another. It might take up to 48 hours to propagate everything. In the meantime, you can open this website, and check if your site is showing new IP or old one. If the new IP address is visible, the propagation is done. You can also use the ping tool on your computer to check the IP address. If your computer is showing old IP but the online tool is showing the new IP, you need to flush your DNS cache.
How to move WordPress site from shared hosting to unmanaged VPS
It is quite easy to move a WordPress website from shared hosting to another shared hosting since both of them have cPanel, which has all the necessary tools like phpMyAdmin, File Manager and so on. However, there are many people, who often choose unmanaged VPS because you can get root access and unmanaged VPS is comparatively cheaper than shared hosting.
What is an unmanaged VPS
VPS means Virtual Private Server. In simple words, if your VPS hosting account doesn’t have a cPanel, you can call it an unmanaged VPS. To access an unmanaged VPS server, you need some tools like Putty, FTP client like Filezilla or Cyberduck. Some examples of unmanaged VPS providers are Digital Ocean, Linode, Vultr, and so on.
If you have already purchased an unmanaged VPS account, and you do not know anything, but you want to move your WordPress site from shared hosting to unmanaged VPS, you can follow these following steps.
Before getting started, download Cyberduck and Putty from here. Also, you need to download the old site backup including all files and database. The steps are mentioned above.
Now, you should know that some companies like WordPress, Ghost, Joomla, Discourse, etc., provide one-click apps, whereas others like Linode do not offer such a thing. In that case, you can use some other third-party tools like ServerPilot, ServerAvatar, EasyEngine, etc. Among them, ServerPilot has recently become a paid tool – but this is the best so far in terms of security and usability.
No matter which hosting account you use, you have to create a server first, install the OS, and note down the root password. Different hosting providers have different options, but the core thing is the same. However, if you use ServerPilot, you have to use the 64-bit version of Ubuntu LTS 16.04 or 18.04. They do not support anything else.
Therefore, you need to add the domain name in your hosting account and change the nameserver in your domain account. Also, this is suggested to use a VPN from now on. Otherwise, you cannot detect the new hosting account from your computer.
If you use the one-click app of Digital Ocean or Vultr, you can install WordPress quickly. If you choose this method, you can find your WordPress installation files here:
/var/html
If you use ServerPilot to install WordPress, you can find your WordPress installation files here:
/srv/users/user_name/apps/app_name/public
You should find a file called wp-config.php. Download it and keep the database username, and password. Do not forget to do this.
You have to delete all the WordPress installation files. As wp-admin, wp-content, and wp-includes folders take a lot of time to be deleted, you can use putty to remove them. For that, open Putty, and enter the IP address of your server. Make sure the Port is set as 22. Following that, click the Open button and confirm the connection. After that, you need to enter your username and password. Enter root as username. You should get a password on the same page or via email after creating the server in your hosting account.
Next, enter this:
One-click app users:
rm -rf /var/html/wp-admin
rm -rf /var/html/wp-content
rm -rf /var/html/wp-includes
ServerPilot users:
rm -rf /srv/users/user_name/apps/app_name/public/wp-admin
rm -rf /srv/users/user_name/apps/app_name/public/wp-content
rm -rf /srv/users/user_name/apps/app_name/public/wp-includes
After that, you can open the Cyberduck app, navigate to that folder and delete other installation files.
In the next step, you need to upload the zipped backup file. Do that, and unzip the file. If you get any error while unzipping, you can enter this command in the Putty:
sudo apt-get update
sudo apt-get install unzip
After unzipping those files, you have to replace the database information. For that, open up the wp-config.php file that you downloaded. Next, open the current wp-config.php file that you just uploaded. Copy the database name, user ID and password from the downloaded wp-config.php file and replace them with the uploaded wp-config.php file.
Following that, you need to install phpMyAdmin. Otherwise, you cannot import the database. For that, follow these steps.
S0 download the latest version of phpMyAdmin from here and upload the zip file to your root directory. After that, unzip the file and rename it. Make sure; you use an unguessable name. For example, if you choose abcd, you can open the phpMyAdmin like this:
http://your-domain-name/abcd
After choosing a name, open the folder and find out config.sample.inc.php file. You can rename it to config.inc.php. After that, open this file with an editor and make a change in the like that says:
$cfg['blowfish_secret']
It should look like this:
$cfg['blowfish_secret'] = 'k7i259684(*^3q42bd^$4353yow*q5Trs^1'
Now, open phpMyAdmin, and enter the database user ID and password to log in. Following that, select the database name on your left-hand side, select all the database tables, and remove them accordingly.
Then, go to Import tab, and import the database that you downloaded earlier.
That’s all! Now your website should run properly on the new hosting account.
How to move WordPress site from unmanaged VPS to shared hosting
This is quite easy and not much time-consuming as well. The best thing is the steps are almost the same. Except, if you haven’t installed the phpMyAdmin, you need to do that to download the database.
In a nutshell, these are the steps you need to follow.
- Download all files from VPS account.
- Download the database.
- Create a database in your shared hosting account and assign the database to a user.
- Upload all the files to your new hosting account.
- Change the database name, username, and password in the wp-config.php file.
- Change the nameserver in your domain control panel.
That’s all!
Common problems after changing the server
You might face different problems after completing the migration. Some of them are mentioned below.
Homepage is opening, but posts are showing 404 error
Check your .htaccess file and use this as default:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Also, go here:
/etc/apache2/apache2.conf
And make this change:
<Directory /var/www/>
AllowOverride All
</Directory>
Unable to install plugins, asking FTP login details
This is a very common problem that people encounter. You need to open your wp-config.php file and paste this at the bottom;
define( 'FS_METHOD', 'direct' );
Installation failed: Could not create directory
If you are unable to upload an image, install plugins, update theme or plugin, and you are getting the error above, you can fix that by changing the permission. Open Putty and enter this:
chmod -R 775 directory_path
You can learn more about file permission from here.
Redirect non-www to www using htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^your-domain-name.com [NC]
RewriteRule ^(.*)$ http://www.your-domain-name.com/$1 [L,R=301,NC]
Redirect www to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.your-domain-name.com [NC]
RewriteRule ^(.*)$ http://your-domain-name.com/$1 [L,R=301]
However, you should also enter a CNAME record with www as well as @ or blank.
Please note that you need to install the SSL separately. If your hosting provider offers free SSL, you can ask them to install that for you. Otherwise, you can use Let’s Encrypt, which provides free but shared SSL certificate.