In this articles we’ll show you how to easily connect a new domain to your WordPress website by using SSH and WP-CLI.
Even though shell access via SSH and WP-CLI, i.e. the WordPress command line, is mostly used by advanced users, this tutorial is also well suited to beginners without any prior knowledge. You will need about 5-10 minutes to connect your domain.
Before you start, the following requirements should be met:
- A WordPress standard installation installed via the 1&1 App Center or a self-installed WordPress (If you are using Managed WordPress: Connect a domain with one click using Managed WordPress)
- A free domain that is assigned to your website’s contract
Managing domains in 1&1 Control Panel
- SSH access to your webspace
Adjusting SSH settings in the 1&1 Control Panel
Connecting the domain with your website’s directory
In this step you will adjust the usage type of your domain and connect this with your website’s directory in the 1&1 Control Panel.
- Click on your domain and select the Edit usage type item there. For your domain select usage type: webspace.
- Select your WordPress website’s directory at target folder and confirm with save.
Tip: You can find your website’s directory in the 1&1 App Center in the detail view of your website.
Connecting WordPress with your new domain via SSH and WP-CLI
In this step you will adjust the your website’s database and save the new domain there.
- Access your webspace via SSH.
Logon to your webspace with SSH: It’s that easy
- Switch to your website’s directory with the cd command (replace my-wordpress-website with your website’s directory).
- After arriving there, you can access WP-CLI, which is installed on our servers as a default. You can search the WordPress database with the wp search-replace command and replace the old domain with the new domain there. )
wp search-replace oldDomain.com newDomain.com
- Your WordPress website is now connected to the new domain.
Finally, we recommend that you adjust the settings for your old domain so that these are no longer displayed on your website. For this simply select an empty older or connect the domain with another website in the 1&1 Control Panel at Domains > Usage type.
If required: adjusting wp-config.php
If your website cannot be reached via the new domain after adjusting with WP-CLI, you will have to replace the old domain with the new domain in your website’s wp-config.php.
It’s that easy:
- Connect your webspace with a FTP client such as FileZilla via SFTP.
An overview of settings for FTP/FTPS/SFTP
- Switch to your website’s directory (clickandbuilds/meine-wordpress-website) and open the wp-config.php file with a text editor.
- Search for your old domain and replace this with your new domain.
- Save the wp-config.php file and upload it to your webspace again.