WordPress is a free and open-source content management system (CMS) based on PHP and MySQL.This has to be installed on a web server, which would either be part of an Internet hosting service or a network host in its own right. And has a web template system using a template processor. Its architecture is a front controller, routing all requests for non-static URIs to a single PHP file which parses the URI and identifies the target page. This allows support for more human-readable permalinks.

Let’s discuss the steps involved in WordPress Migration.

1. Login Via SSH To Your Existing Web Hosting Account


SSH (Secure Shell) is a network protocol that enables you to securely enter your server across an encrypted connection. Login to your current web hosting account. The essential command to do this is: 


ssh username@domainname.com or ssh username@ipaddress

If the port is different than the default, append the port number by using the option ‘-p’. 


2. Backup your Files


It’s normal method to always backup your website before doing any modifications. To build the backup you can compress your whole folder using the following command: 

tar -cvzf wpback.tar.gz public_html

3. Transfer your Files

Once you are logged into your existing web hosting account, you can begin the transfer process. Before you can start the transfer, you need to know where your content is located on the existing server, and where you require to put the content on the new server. In most of the cases, everything will be found in the public_html folder. You will be performing the transfer using the SCP command, which stands for Secure Copy.


 Type: pwd to figure out where you’re at on the server:


pwd
/home/admin

Type: cd public_html to “change directory” to public_html:
cd public_html

Type: pwd again to verify your location on the server and to get the full address location:
pwd
/home/admin/public_html

The address location will be required when you begin the command to start the transfer. Check the location you want to transfer your content to on your fresh server. In most cases, the location will be the similar, public_html. To commence the transfer use this command, but be sure to change it to match your username, addresses, and locations for both servers: 


scp –P 2200 -r source_folder/location/ username@serveraddress.com: /destination_folder/

The username and server IP would be of your destination server.

You can also use sftp to transfer files.


4. Backup the Database

WordPress stores data in a MySQL database. You’ll need to move this database to move the site. You’ll need to back up the database from the old site first.

You can export the database with the following command.

mysqldump -u [username] -p [database_name] > [name_your_backup_file].sql

The username isn’t the same here as your SSH login, it’s your MySQL access username. The database name you can get from the 'wp_config.php' file if you’ve disremembered. It will also ask you for a password after this command, which is the database password, which you can also get from the 'wp- config.php' file.

This will generate a file (which you mentioned in the last part of that command) which is a whole backup of your database.

Now, to transfer your database, use scp command:

scp –P 2200 [backup_file].sql [username]@[server-ip]:[backup_file].sql

The usename and server IP would be of your destination server.


5. Extract your Files

To extract your files at the destination server. For the purpose, login to your destination server via ssh. Now, you can extract the compressed file ( here; wpback.tar.gz) to the document root of your new website, using the following command:

tar -xzvf wpback.tar.gz public_html

Also, change the ownership of the public_html as newusername.nobody and all the files and folders within the public_html folder as newusername.newusername and using the following command

chown admin.nobody pubic_html
chown -R admin.betsy public_html

As of now ensure that the default permissions of files and folder as 644 and 755 are correctly updated.


6. Import the database

To import the database first you need to login to MYSQL as root user using the following command.

mysql -u root -p

Now you need to create new database and user. (Refer the screenshot attached mysql3.png)

Once you created new user and database, log in to the mysql as the new user and follow the steps to import the database.

(Refer the screenshot attached mysql5.png


7.Edit the wp-config file

WordPress stores your database information in the wp-config.php file. Without this information, your WordPress website will not work, and you will get the ‘error establishing database connection‘ error. So you will need to edit the

wp-config file with the new user, database, and the password.

  1. Change the database name:
define(‘DB_NAME’, ‘db_name’);
  1. Change the Database Username:
define(‘DB_USER’, ‘db_user’);
  1. Change The Database User Password
define(‘DB_PASSWORD’, ‘db_pass’);


8. Changing the Site URL and Home URL

If you are moving to a new/different domain be sure to replace <old_url> with

<new_url> .If not, then you can skip this because you don’t have to update your site to point to a different domain.

The following steps will help you to find and replace all the old URLs with the new URLs.

mysql -u wp_user1 -p Enter password:

Use the database named “store-db”

mysql> use store-db;

Database changed, Show the tables

mysql> show tables;

Tables_in_store-db

| wp_commentmeta| | wp_comments| | wp_customcontactforms_field_options | | wp_customcontactforms_fields | | wp_customcontactforms_forms | | wp_customcontactforms_styles | | wp_customcontactforms_user_data | | wp_links | | wp_options | | wp_postmeta | | wp_posts | | wp_term_relationships | | wp_term_taxonomy | | wp_terms | | wp_usermeta | | wp_users |

16 rows in set (0.00 sec)
mysql> select * from wp_options where option_value = ‘http://www.domain1.com/wordpress’;
mysql> update wp_options set option_value = ‘http://www.domain2.com’ where option_id = 1;

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

 

mysql> select * from wp_options where option_value = ‘http://www.domain1.com/wordpress’;

Empty set (0.00 sec)

mysql> select * from wp_options where option_value = ‘http://www.domain2.com.com’;
| option_id | blog_id | option_name | option_value | autoload |
| 1 | 0 | siteurl | http://www.domain2.com | yes |
1 row in set (0.00 sec)
“`


9. Changing the DNS Records

Before you can use the site on your new host you will need to check whether all the contents and databases are correctly updated on the new website. You need to forcefully load your website from your local machine, for this you need to add host entry in your local machine.

To add hosts entry :

1) In a Windows machine, Add an entry in this file: %SystemRoot%\system32\drivers\etc\hosts

(where %SystemRoot% is C:\Windows in a Normal case, change it accordingly)

2) In a Linux machine, Add an entry in this file: /etc/hosts

3) In Mac OS, Add entry in this file : /private/etc/hosts

The entry is:

 domain.com www.domain.com

Please keep in mind to remove this entry once testing is done.

After confirming that your website is working fine on your local machine, you need to reconfigure your domain’s DNS settings. They will be set to point to your old host and you will need to point the correct records to the new server IP address. This process will depend on where you have your domain registered. DNS changes can take up to 48 hours to fully propagate. During this 48 hour, you should avoid making any changes to your website as you may be changing the old version of the site.

Though WordPress migration seems to be difficult it would be easy if you follow the above steps correctly.

War diese Antwort hilfreich? 0 Benutzer fanden dies hilfreich (0 Stimmen)