WordPress の移行

WordPress を新しいサーバーに移す場合でも、サーバー上の別の場所に移す場合でも、WordPress を再インストールする必要はありません。WordPress は、これらすべての状況に柔軟に対応することができます。

新しいサーバーへの移行 新しいサーバーへの移行

WordPress をあるサーバーから別のサーバーに移動する場合は、まず WordPress のディレクトリ、画像、プラグイン、サイト上のその他のファイル、およびデータベースのバックアップから始めましょう。WordPress のバックアップデータベースのバックアップを参照してください。

ドメイン名と URL を変更しないとき ドメイン名と URL を変更しないとき

WordPress サイトのホームとサイト URL を変更せずにドメインを移動することはとても単純で、ほとんどの場合はファイルを移動するだけで済みます。

  • データベースと URL が変わらない場合は、ファイルとデータベースをコピーするだけで移動できます。
  • データベース名やユーザーが変わる場合は、正しい値になるように wp-config.php を編集してください。
  • 切り替える前にテストしたい場合は、データベーステーブル「wp_options」の「siteurl」と「home」を一時的に変更する必要があります (phpMyAdmin などを通じて) 。
  • もしリライト (パーマリンク) の設定をしていたら、.htaccess を無効にして、パーマリンクを再設定しなければなりません。

トップ ↑

ドメイン名と URL を変更するとき ドメイン名と URL を変更するとき

ウェブサイトを移動したり、ドメイン名や URL を変更したりするには (例: http://example.com/site から http://example.com へ、または http://example.com から http://example.net へ) 、以下の手順を順番に実行する必要があります。

  1. 既存サイトのファイルをダウンロードします。
  2. データベースのエクスポート – MySQL に入ってデータベースをエクスポートします。
  3. バックアップされたファイルとデータベースを新しいフォルダに移動します – どこか安全な場所に – これはあなたのサイトのバックアップです。
  4. 移動したいサイトにログインして、「設定」 > 「一般」と進み、URLを変更します。(例: http://example.com/ から http://example.net へ) – 設定を保存し、404ページが表示されることを期待してください。
  5. サイトのファイルを再度ダウンロードします。
  6. データベースを再度エクスポートします。
  7. wp-config.php を新サーバーの MySQL データベース名、ユーザー名、パスワードに書き換えます。
  8. ファイルをアップロードします。
  9. 新しいサーバーにデータベースをインポートします。

ドメイン名や URL が変更されると、さらに懸念されることがあります。ファイルやデータベースは移動できますが、古いドメイン名や場所への参照はデータベースに残り、リンクやテーマの表示に問題が生じる可能性があります。

URL を変更するためにデータベース全体の検索と置換を行うと、いくつかのテーマやウィジェットには URL の長さを示す値を保存しているものがあるため、データのシリアライゼーションに問題が生じる可能性があります。これが変更されると、壊れてしまいます。シリアライズの問題を回避するには、3つのオプションがあります。

  1. ダッシュボードにアクセスできる場合は、 Velvet Blues Update URLs または Better Search Replace プラグインを使用してください。
  2. ホスティングプロバイダー (またはあなた) が WP-CLI をインストールしている場合は、WP-CLI の検索置換 を使用してください。
  3. Search and Replace for WordPress Databases Script を使用して、古いドメイン上のすべてのインスタンスやパスを新しいものに安全に変更することができます。(** データベース管理に慣れている場合のみ、このオプションを使用してください ** )

注意: wp_posts テーブルでのみ検索と置換を実行してください。
注意: Search and Replace for WordPress Databases Script はサードパーティ製のスクリプトです。

トップ ↑

既存のサーバー上でのディレクトリの移動 既存のサーバー上でのディレクトリの移動

Moving the WordPress files from one location on your server to another – i.e. changing its URL – requires some special care. If you want to move WordPress to its own folder, but have it run from the root of your domain, please read Giving WordPress Its Own Directory for detailed instructions.

Here are the step-by-step instructions to move your WordPress site to a new location on the same server:

  1. Create the new location using one of these two options:
    1. If you will be moving your WordPress core files to a new directory, create the new directory.If you want to move WordPress to your root directory, make sure all index.php, .htaccess, and other files that might be copied over are backed up and/or moved, and that the root directory is ready for the new WordPress files.
  2. Log in to your site.
  3. Go to the Administration > Settings > General screen.
  4. In the box for WordPress Address (URL): change the address to the new location of your main WordPress core files.
  5. In the box for Site Address (URL): change the address to the new location, which should match the WordPress (your public site) address.
  6. Click Save Changes.
  7. (Do not try to open/view your site now!)
  8. Move your WordPress core files to the new location. This includes the files found within the original directory, such as http://example.com/wordpress, and all the sub-directories, to the new location.
  9. Now, try to open your site by going to yourdomain.com/wp-admin. Note, you may need to go to yourdomain.com/wp-login.php
  10. If you are using Permalinks, go to the Administration > Settings > Permalinks panel and update your Permalink structure to your .htaccess, file, which should be in the same directory as the main index.php file.
  11. Existing image/media links uploaded media will refer to the old folder and must be updated with the new location. You can do this with the Better Search Replace or Velvet Blues Update URLs plugins, WP-CLI’s search-replace if your hosting provider (or you) have installed WP-CLI, manually in your SQL database, or by using the 3rd party database updating tool Search and Replace Databases Script * Note: this script is best used by experienced developers.
  12. In some cases your permissions may have changed, depending on your ISP. Watch for any files with “0000” permissions and change them back to “0644”.
  13. If your theme supports menus, links to your home page may still have the old subdirectory embedded in them. Go to Appearance > Menus and update them.
  14. Sometimes you would need to restart your server, otherwise your server may give out an error. (happens in MAMP software (Mac)).

It is important that you set the URI locations BEFORE you move the files.

トップ ↑

If You Forget to Change the Locations If You Forget to Change the Locations

If you accidentally moved the files before you changed the URIs: you have two options.

  1. Suppose the files were originally in /path/to/old/ and you moved them to /path/to/new before changing the URIs. The way to fix this would be to make /path/to/old/ a symlink (for Windows users, “symlink” is equivalent to “shortcut”) to /path/to/new/, i.e. ln -s /path/to/new /path/to/old and then follow the steps above as normal. Afterwards, delete the symlink if you want.
  2. If you forget to change the WordPress Address and Blog Address, you will be unable to change it using the wordpress interface. However, you can fix it if you have access to the database. Go to the database of your site and find the wp_options table. This table stores all the options that you can set in the interface. The WordPress Address and Blog Address are stored as siteurl and home (the option_name field). All you have to do is change the option_value field to the correct URL for the records with option_name=’siteurl‘ or option_name=’home‘.

トップ ↑

If You Have Accidentally Changed your WordPress Site URL If You Have Accidentally Changed your WordPress Site URL

Suppose you accidentally changed the URIs where you cannot move the files (but can still access the login page, through a redirection or something).

wp-login.php can be used to (re-)set the URIs. Find this line:

require( dirname(__FILE__) . '/wp-load.php' );

and insert the following lines below:

//FIXME: do comment/remove these hack lines. (once the database is updated)
update_option('siteurl', 'http://your.domain.name/the/path' );
update_option('home', 'http://your.domain.name/the/path' );

You’re done. Test your site to make sure that it works right. If the change involves a new address for your site, make sure you let people know the new address, and consider adding some redirection instructions in your .htaccess file to guide visitors to the new location.

Changing The Site URL also provides the details of this process.

トップ ↑

Managing Your Old Site Managing Your Old Site

トップ ↑

Shutting It Down Shutting It Down

  1. Download a copy of the main wordpress files from your OLD site to your hard drive and edit wp-config.php to suit the new server.
  2. Go back to your OLD site and go to Administration > Settings > General screen and change the URL (both of them) to that of your new site.
  3. Login on your server, go to phpMyAdmin, export as file, and save your database (but keep the old one just in case). Now, upload this new database and the copy of the wordpress core files with the edited wp-config.php to your new server. That’s it!

トップ ↑

Keeping it Running Keeping it Running

Caution: Make sure you have a backup of your old site’s WordPress database before proceeding!

Part A – Activating Your New Site

  1. Download your entire WordPress installation to your hard drive. Name the folder appropriately to indicate that this is your OLD site’s installation.
  2. Download your database.
  3. Go back to your OLD site and go to options and change the url (both of them) to that of your new site.
  4. Again, download your entire WordPress installation to your hard drive. Name the folder appropriately to indicate that this is your NEW site’s installation.
  5. Download your database once again (but keep the old one). Upload this database to your new server. It will be easiest if you use the same database name and you create a user with the same login credentials on your new server as on your old server.
  6. If you used a different database name and/or user (see previous step), edit wp-config.php in your NEW site’s installation folder appropriately.
  7. Upload the NEW site’s installation folder to your new site. Presto, your NEW site should be working!

Part B – Restoring Your Old Site

  1. On the original server, delete your OLD site’s database (remember, you should have a copy on your local computer that you made at the very beginning).
  2. Upload your OLD site’s installation folder to your original server, overwriting the files that are currently there (you may also delete the installation folder on the server and simply re-upload the OLD site’s files).
  3. Upload your OLD site’s database from your local computer to the server. That should do it!

Another procedure for making copies of posts, comments, pages, categories and custom field (post status, data, permalinks, ping status, etc.) easy to follow:

  1. Install a new WordPress site
  2. Go on old site Admin panel. Here, in Manage > Export select “all” in menu Restrict Author.
  3. Click on Download Export File
  4. In new site go on Manage > Import, choose WordPress item.
  5. In the page that will be shown, select the file just exported. Click on Upload file and Import
  6. It will appear a page. In Assign Authors, assign the author to users that already exist or create new ones.
  7. Click on Submit
  8. At the end, click on Have fun

Note: using this method, if there are some articles in the new site (like Hello World, Info Page, etc.), these will not be erased. Articles are only added. Using the former procedure, the articles in new site will be deleted.

トップ ↑

Moving WordPress Multisite Moving WordPress Multisite

Multisite is somewhat more complicated to move, as the database itself has multiple references to the server name as well as the folder locations. If you’re simply moving to a new server with the same domain name, you can copy the files and database over, exactly as you would a traditional install.

If, instead, you are changing domains, then the best way to move Multisite is to move the files, edit the .htaccess and wp-config.php (if the folder name containing Multisite changed), and then manually edit the database. Search for all instances of your domain name, and change them as needed. This step cannot yet be easily automated. It’s safe to search/replace any of the wp_x_posts tables, however do not attempt blanket search/replace without the Search and Replace for WordPress Databases script (aka the interconnectit script).

If you’re moving Multisite from one folder to another, you will need to make sure you edit the wp_blogs entries to change the folder name correctly. You should manually review both wp_site and wp_blogs regardless, to ensure all sites were changed correctly.

Also, manually review all the wp_x_options tables and look for three fields and edit them as needed:

  • home
  • siteurl
  • fileupload_url

If you are moving from subdomains to subfolders, or vice-versa, remember to adjust the .htaccess file and the value for SUBDOMAIN_INSTALL in your wp-config.php file accordingly.

トップ ↑