Moving WordPress and site to new Domain

Hi All - have a question on moving a WordPress site from a sub-domain to main domain…

So, I have 2 web domains setup…. [examples used but am sure you get the idea]

mydomain.co.uk which has a static “new site coming soon” HTML page

test.mydomain.co.uk which has a WordPress site against it (as was developing the new site using WP)…

Its now come to the point I want to move test.mydomain.co.uk to the main site (mydomain.co.uk) - I know I could install WordPress against the main site and use a tool to migrate the sub-domain site to the main site but assume/guess that would mean having to setup all the users again etc in WordPress?

I was wondering, could I just use v-change-web-domain-name? - my plan is to delete the test.mydomain.co.uk site and then run [as root] v-change-web-domain-name myuser test.mydomain.co.uk mydomain.co.uk - would that work? It’s the WordPress bit I’m unsure of [I installed WordPress by Hestia itself - so assume it just creates it under the domain name?]

Will add at this point, just want to move the web site [hence thinking of using v-change-web-domain-name as there is already email setup on the main domain [mydomain.co.uk]

I haven’t used any hard-links in my site [I never referenced the test.mydomain.co.uk itself] but does WordPress? I know there is something in WP settings for the domain name - so guess I just need to change that?

Lastly, there is the certificate itself - assume I just disable/re-enable SSL on the domain after it has been moved?

Many thanks and sorry if this seems obvious…

Are both sites under the same Hestia user?

Do both of your sites already have a Let’s Encrypt certificate? Is your test WordPress site currently using http://test.mydomain.co.uk or https://test.mydomain.co.uk?

Assumptions:

1.- Both sites are under the same Hestia user.
2.- Both sites have their respective SSL certificates.
3.- The wordpress site url is set to https://test.mydomain.co.uk.
4.- I will use YourUser as the Hestia user in the commands below.
5.- CRITICAL: You have a backup of both, the database and the WordPress installation.

Steps

1.- Login as root:

sudo -i

2.- Install wp-cli for the user:

/usr/local/hestia/bin/v-add-user-wp-cli YourUser

3.- Remove the index.html file or any other files from mydomain.co.uk (make sure to back them up first):

rm /home/YourUser/web/mydomain.co.uk/public_html/index.html

4.- Copy all WordPress files from the document root of test.mydomain.co.uk to mydomain.co.uk:

cp -apf /home/YourUser/web/test.mydomain.co.uk/public_html /home/YourUser/web/mydomain.co.uk

5.- Replace all occurrences of https://test.mydomain.co.uk with https://mydomain.co.uk in the Wordpress db.

First, you can use the --dry-run param to see how many changes will be made before applying them:

runuser -u YourUser -- /home/YourUser/.wp-cli/wp search-replace 'http://test.mydomain.co.uk' 'https://mydomain.co.uk' --path=/home/YourUser/web/mydomain.co.uk/public_html --skip-columns=guid --all-tables --dry-run

If all is ok, remove the param --dry-run to apply the changes:

runuser -u YourUser -- /home/YourUser/.wp-cli/wp search-replace 'http://test.mydomain.co.uk' 'https://mydomain.co.uk' --path=/home/YourUser/web/mydomain.co.uk/public_html --skip-columns=guid --all-tables

After that your site should work in the new domain.

4 Likes

Your assumptions below were correct :slight_smile:

That great - thank you for the instructions [and your assumptions were spot on!]

Just one more question please - will that also move the WordPress “site” as well? [guessing so as it’s just a web page of the site isn’t it?]… so, I currently access WordPress via test.mydomain.co.uk/wp-admin and after the change, I can access it by mydomain.co.uk/wp-admin and WordPress will keep/use all the existing users/plugins etc [so I don’t need to install WordPress]?

1 Like

Yes, the cp -apf ... command will copy all your Worpress installation to the new site.

Yes, you will be able to access https://mydomain.co.uk/wp-admin (pay attention that I’ve used https instead of http).

Yes, all your users and plugins should be there and you don’t need to install Wordpress again.

Brillaint Thank You - once again, many thanks for the help/advice/instruction(s)

1 Like

You can use GitHub - christoskaterini/Hestia-flexx-staging-UI · GitHub

1 Like