将WordPress网站从一个域移动到另一个域

时间:2012-07-08 作者:Charles

我已经通读了codexs,我正试图找到最好的方法来更改或移动我的MySQL和子目录文件到一个新的域,而无需额外的努力。例如,我以我的名字/子目录/构建了一个stage站点,最近为一个朋友购买了一个新域,并希望将数据迁移到新域。

我与我的域名托管公司进行了长时间的交谈,并向我表示这不是一个托管问题。他们不会为WordPress提供任何支持。因此,我将所有内容都放在public\\u HTML/子目录下……但我不确定接下来要采取什么步骤。我以前曾将WordPress移动到不同的文件夹中,但没有移动到两个不同的域中。任何帮助都将不胜感激,因为我的主人完全不愿意。

附加信息:userabuser-感谢您的详细回复。我认为你应该提供更多的细节,以便缩小哪些选项最有效的范围。舞台网站由我的托管公司托管。当前网站托管在域中的另一个平台上,由Go Daddy拥有和运营。当前站点处于活动状态,负责该站点的人员不希望出现任何服务差距。因此,在网站启动之前,我无法将域名或DNS指向我的托管公司。如果我继续建设网站,添加链接和照片,一切都将留在我的主域名上,我担心一旦舞台网站变成活跃的生活网站,会变得一团糟。我已经多次备份了数据库以及所有WP文件。我有点急于做任何额外的工作,而不必预先计划下一阶段。这有什么帮助或意义吗?

1 个回复
SO网友:Adam

There are a number of ways to do this,

  1. Install WordPress on new host, export, then import post data (via Dashboard) XML file
  2. Install WordPress on new host, export, then import MySQL database file
  3. Use a back up plugin that allows you to clone your site from host-to-host (1:1)

In both cases 1 and 2, you will need to;

  1. copy your theme file folder to your new host
  2. copy your plugins folder(s) to your new host
  3. potentially copy your /wp-content/uploads/ directory across
    • the issue being that media attachments or custom files don\'t always make it in an XML transfer (export/import).

My preferred method in worse case scenarios is to opt for option 2, however I rarely if ever have to resort to that method of transfering a local site, or even remote site to another remote host because I use a backup plugin as described in option 3 called Backup Buddy.

Backup Buddy is not a free plugin, but its invaluable.

It literally allows for backing up a site, its database and all of its files into one archive file that you can transfer and install on your destination host via an intuitive script/process. A total 1:1 copy of your site, its content, all of your settings be they platform settings or plugin settings are preserved including links updated to match your new URL (unless hardcoded).

Backup Buddy is not the only plugin of this nature, there are others, some are also premium (paid plugins) but there are a couple which are FREE too and they do virtually the same, if not the same thing although I have not used them so I can\'t recommend those specifically.

Some links to backup plugins;

UPDATE

In light of the fact that the domains are contained within the same host and likely the same server, am I safe to assume you control both domains? As in the domains are attached to your account? If so then its still just as easy to migrate your installation. If you don\'t want to use any of the suggested plugins above (I recommend you do) then do the following;

Assuming you have cPanel installed


Step #1

Login to your cPanel hosting account then search for PHPMyAdmin as seen in the screenshot below in your "databases" section;

enter image description here

Step #2

Upon entering PHPMyAdmin select the database that applies to the WordPress website you want to migrate (use the drop down list)

enter image description here

Step #3

As in the above screenshot, click on the EXPORT tab to prepare your database for export.

Step #4

Finally hit the GO button and a dialog box will appear asking you where you want to save your SQL file. Save it to your desktop or somewhere memorable. You do not need to change any options on this screen.

enter image description here

Step #5

With your SQL data (WordPress database) safely backed up, you now need to COPY the entire contents of your WordPress installation directory.

The root of your install directory will look a little like this;

enter image description here

Step #6

With all your files safely copied to their new destination its now time to import your SQL file you saved in STEP 4. Remember, you do NOT need to install WordPress from scratch (like from your Fantastico panel etc) because we\'ve already copied our installation, theme and plugins in STEP 5 (this is a migration, not new installation).

In your cPanel go back to your DATABASES section and click on MySQL Database Wizard as now you need to create a new/empty MySQL database so we can import our backup file. Its advised that you create,

  • the same database name
  • the same database user (if already available just select the same user)
  • the same database password

Otherwise if you change any of those credentials you will need to edit your wp-config.php file found in the root directory of the files we copied over in STEP 5.

If you opt for different database details edit your wp-config.php to reflect;

define(\'DB_NAME\', \'new_db_name\');

/** MySQL database username */
define(\'DB_USER\', \'username\');

/** MySQL database password */
define(\'DB_PASSWORD\', \'password\');

/** MySQL hostname */
define(\'DB_HOST\', \'localhost\');  <- this should not need to be changed if on same host

Step #7

Now we have our fresh, empty database setup with matching user/pass/host credentials, our WordPress install, theme and plugin files copied across to their new destination, we need to import the SQL database file we saved in STEP 4. Once we do this, if everything goes well, you\'ll have a fully migrated WordPress site...

BUT HOLD ON JUST A SECOND...

Because before you import your SQL file you need to replace all of the URLs that point to your previous domain, in exchange with the new domain name. So open up the SQL file in an editor (I highly recommend Notepad++ for this - shown in screenshot), then goto:

Search -> Replace -> Find What (olddomain) -> Replace With (newdomain) -> Replace All

It\'s extremely important that you replace only olddomainname.com with newdomainname.com. Do not include any http:// or www. or / trailing slash - instead do just as indicated in the screenshot because this will match all instances of the olddomainname.com regardless of whether there is anything before or after it as you will probably notice that the olddomainname.com URL is scattered through out the SQL file in different variations,

If we try and guess the combinations in which the olddomainname.com appears we might make a mistake, miss one, or more and subsequently botch the migration process.

enter image description here

Step #8

Now that we have prepared our SQL file with the domain name of the new site its time to import it to our database as mentioned above. Back in PHPMyAdmin we repeat the same process as we did when exporting the database, except this time we are importing the database and selecting the new database name from the drop down list (which) then click the IMPORT tab.

enter image description here

Step #9

Select the SQL file that you backed up earlier, that you\'ve also now edited with the new sites domain name!

Step #10

Hit GO! enter image description here

CONCLUSION

If all went well, your SQL database should import successfully and tell you so! To login to your WordPress dashboard all you need to do is visit;

http://www.newdomainname.com/wp-admin/

(assuming you\'re installing within the root of the new domain name).

Your previous Username and Password for the admin or any other user accounts will still work. Additionally, your WordPress parent settings, theme settings, plugin settings and content will be intact without the need to reconfigure.

I hope this guide has helped you, its 10 easy steps, although I still recommend using Backup Buddy, but if you dont wish to pay for that plugin or attempt to use the other suggestions then this old trusted method of manually migrating your site works just the same. Good luck!

结束

相关推荐

WooCommerce permalinks

我有以下问题:当我转到WooCommerce类别时,链接显示如下:http://www.example.com/product-category/category/其中粗体文本是链接,其余是需要显示的产品类别。当我进入WooCommerce设置并进入pages选项卡时,我可以选择更改productcategory slug。如果我在此文本字段中填写以下内容:%product_cat% 链接显示如下:http://www.example.com/category/category/我想在我的链接中显示的是: