Move a WordPress site

Contents
Files and database
wp-config.php
The address of the site
.htaccess
Settings and links

A WordPress site is two things: the files (WordPress itself, themes, plugins, uploads) and a MySQL database with the posts and settings. A move copies both and tells WordPress where the database and the site now are. What to arrange with the old provider first: Moving a website.

Files and database

  1. Create the site at the new hosting and copy all files of the old site into its folder.
  2. Export the database at the old hosting, in phpMyAdmin with Export, to an .sql file.
  3. Create a database and a user at the new hosting. Give it a long random password and note the database name, the user name and the host.
  4. Open phpMyAdmin of the new database and import the .sql file with Import.

wp-config.php

In the root folder of the site, set the new database credentials:

vi wp-config.php

/** The name of the database for WordPress */ define( 'DB_NAME', 'example_db' ); /** Database username */ define( 'DB_USER', 'example_user' ); /** Database password */ define( 'DB_PASSWORD', 'a-long-random-password' ); /** Database hostname */ define( 'DB_HOST', 'localhost' );

The address of the site

If the domain changes too, set the new address in the same file. These two lines win over the address stored in the database:

define( 'WP_HOME', 'https://www.example.com' ); define( 'WP_SITEURL', 'https://www.example.com' );

.htaccess

WordPress sends every address that is not a real file or folder to its index.php. On Apache this needs the standard block in .htaccess in the root folder; more about the file in .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

Settings and links

Log in at https://www.example.com/wp-admin, open Settings, General, check WordPress Address (URL) and Site Address (URL) and save. Posts still contain links and image paths with the old domain. With WP-CLI on the server, replace them in the whole database, first as a dry run:

wp search-replace 'https://old.example.com' 'https://www.example.com' --dry-run

Then run it again without --dry-run. Old addresses that visitors still use should answer 301 to the new ones, see Redirects.

Article authors: Andrei Olegovich, Klavdiya Kondakova

Related articles
Responsive design: an adaptive menu
Beget mail: create a mailbox
Canonical page: rel=canonical
CSS
Firefox
Which hosting to choose
VPS hosting
HTTP status codes
Joomla
OpenCart
PUT vs POST
Redirects
Russian IP ranges
SEO
Element tbody not allowed as child of element table in this context
CSS test: shapes and line numbers
CSS test 2: the code blocks of this site
Website testing
A tram drawn with CSS
URL encoding
UTM tags
Telling bots from people
WebP images
Moving a website: domain and hosting
WordPress
Move a WordPress site
Yandex Metrica: goals
Yandex Mail: collect mail from other mailboxes

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: