Install WordPress with new domain on the same sever

Question:

How to set up WordPress with a new domain on the same server?

summary:

Changing the domain in WordPress must be done both in the website settings and in all other data records (e.g. internal links). There are numerous plugins for this (e.g. WP Migrate DB) or manual solutions via DB Manager and wp-config.php.

demarcation:

This article is about changing the domain of a WordPress instance. If you want to set up additional WordPress instances on the same server, read our other articles.


You have a WordPress website that is currently accessible under an old domain (alte-domain.de) and now it should be accessible on the same server under a new domain (neue-domain.de)? You can usually change the domain of your WordPress website relatively easily. I’ll show you different options here:

  • Domain change via plugin
  • Domain change via external script
  • Domain change via WP-CLI
  • Domain change manually

BACKUP! As before any system change, you should of course make sure that you have an up-to-date backup of your entire website!

Domain change via plugin

For most users, the plugin solution is probably the easiest and fastest way. There are numerous WordPress plugins for database editing that you can use here. I recommend using one of the following:

Both tools offer a “Search & Replace” mode that searches your entire database and replaces all matches accordingly. The only thing to keep in mind with this method is the correct use of the two strings.

On the one hand, you should think carefully about how specifically the find condition is chosen. If you only enter “alte-domain.de”, it is possible that more will be changed than you want (e.g. if you wrote about your website in the text and the old name should remain in the old articles). Is the find text too specific, e.g. “https://www.old-domain.de/” would not replace things where your e.g. only used http, no www or no trailing slash. A good average is “//www.alte-domain.de”. Alternatively, you can of course run the process several times with different variants.

On the other hand, you absolutely have to make sure that the search and the replace string have exactly the same format. If you work with “http://” in the search, this must also be included in the replacement, otherwise it will inevitably lead to errors due to invalid URLs.

Domain change via external script

If you don’t want to install a plugin for a one-off change that can’t be uninstalled without a trace and you have no problem playing files on your server, interconnect’s search-and-replace script is recommended.

The tool is free and all you have to do is put a few files in your website’s folder on your server. Then you can easily call the script via the browser and run a search-and-replace process over your entire database. Of course, the same notes as for the plugin solution must be observed.

Domain change via WP-CLI

If you are familiar with SSH and command line programs, the WP-CLI is also a very elegant option. If you already have the WP-CLI installed, all you have to do is enter the following command:

php_cli wp-cli.phar search-replace www.alte-domain.de www.neue-domain.de

Domain change manually

All 3 methods don’t appeal to you? A domain change can of course also be done completely manually, but of course it also involves more risks. So I would only resort to this if the other methods really don’t work.

domain change

The first thing to do is to change the main domain. This is relatively easy and can be done in a number of ways:

In the WordPress backend: just go to Settings > General in the backend and change the domain in the WordPress address and Website address fields.

A domain can also be defined in wp-config.php (if this is not already the case). Simply make the following entries in the file:

define('WP_SITEURL', 'http://www.neue-domain.de');
define('WP_HOME', 'http://www.neue-domain.de');

The way using the RELOCATE function is a little less known but also good. To do this, set the entry “define(‘RELOCATE’, true);” in wp-config.php. then you call up the login via http://www.neue-domain.de/wp-login.php and then remove the relocate entry from the wp-config.php again.

Ultimately, the domain can also be changed directly in the database (e.g. via phpmyadmin). Simply adjust the “siteurl” and “home” entries in the “wp_options” table.

change database contents

The website should now be accessible under the new domain, but all internal links and possible settings from various plugins can still refer to your old domain and thus cause broken links or other errors. Without a proper search and replace tool, you now have to search all columns of all tables for the old domain in the database (again via pypmyadmin or similar) and then replace it. E.g:

update wp_posts set post_content =
replace(post_content,'www.alte-domain.de','www.neue-domain.de');

Until you have made sure that you have caught all the entries, this is of course quite time-consuming.

Leave a Reply

Your email address will not be published.