How to change domain name for wordpress


In this post, I am going to show how to chage the domain name of wordpress website. There are several ways to change domain name for WordPress.


Using dashboard

This is probably easiest way to change domain name. After DNS registration and configuration, in admin page, setting -> general, you will see something like the image below.



You will probably see 'http://ip_address/' in both text box.

You just need to chage these to the domain name that you have registered and save that change.

After clicking save button, you will get to the login page.
※ If you can't login, it is because of cached data and cookies in your internet browser, so you just need to delete them (cached data and cookies) in your browser and try to login again through configured domain name.


Using wp-config.php

If you followed my wordpress installation.

How to install wordpress with LAMP (Debian, Ubuntu)

WordPress should be installed in /var/www/html/

Type the commands below through console.

sudo -s

cd

cd /var/www/html

nano wp-config.php

Between <?php and ?> add the texts below.
※ It could be better placed under the database configuration.

define('WP_HOME','http://domain_name');
define('WP_SITEURL','http://domain_name');


Save wp-config.php with 'ctrl + x', 'y' and 'Enter'.

※ If you can't login or can't load the login page, it is because of cached data and cookies in your internet browser, so you just need to delete them (cached data and cookies) in your browser and try to login again through configured domain name.

- Just be aware, if you are using this method, it won't let you change domain name Using dashboard. Because when wp-config.php loaded, it is covering the domain name from dashboard.


Using function.php

Type the commands below through console.

sudo -s

cd

cd /var/www/html/wp-content/theme/name_of_current_theme_you_are_using

nano function.php 

Under <?php add the texts below.

update_option( 'siteurl', 'http://domain_name' );
update_option( 'home', 'http://domain_name' );

Save function.php with 'ctrl + x', 'y' and 'Enter'.

※ If you can't login or can't load the login page, it is because of cached data and cookies in your internet browser, so you just need to delete them (cached data and cookies) in your browser and try to login again through configured domain name.


Using database (MariaDB, MySQL)

Type the commands below through SSH console.
sudo -s

mysql -u root -p

root the_root_password

UPDATE wp_options SET option_value = replace(option_value, 'http://ip_address(or old domain)', 'http://new_domain_name') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://ip_address(or old domain)','http://new_domain_name');

UPDATE wp_posts SET post_content = replace(post_content, 'http://ip_address(or old domain)', 'http://new_domain_name');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://ip_address(or old domain)','http://new_domain_name');

quit

※ 'http://ip_address(or old domain)' is meaning of current address that you are using it to load wordpress page.

※ If you can't login or can't load the login page, it is because of cached data and cookies in your internet browser, so you just need to delete them (cached data and cookies) in your browser and try to login again through configured domain name.


Using phpmyadmin

There are 2 ways to do this.

1. Chaging current address to new domain name one by one.

2. Using database commands in phpmyadmin.

UPDATE wp_options SET option_value = replace(option_value, 'http://ip_address(or old domain)', 'http://new_domain_name') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://ip_address(or old domain)','http://new_domain_name');
UPDATE wp_posts SET post_content = replace(post_content, 'http://ip_address(or old domain)', 'http://new_domain_name');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://ip_address(or old domain)','http://new_domain_name');


No comments:

Post a Comment