Question

Switch the domain of my wordpress droplet

Hello everyone,

I bought a new domain for my website, and now I managed to successfully add it to my droplet, to the point where now I have two domains pointing to the same droplet:

image alt text
networking

Both domains access the same website from my browser, but the default appears to be openplcproject.com where I want it to be autonomylogic.com. If I launch autonomylogic.com on my browser, the browser address changes to openplcproject.com. Can I invert this behavior? I will eventually phase out openplcproject.com over time, but right now I don’t want it to be disconnected as many users are still using that domain. So ideally it would be even better if openplcproject.com was directed to a specific page saying that openplcproject.com is now autonomylogic.com and then redirect the user automatically after a few seconds. How can that be done?

Thanks!

Thiago Alves


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
August 25, 2023
Accepted Answer

Hi there,

Changing your WordPress website domain name would require a few steps, and I recommend that you first take a backup of your Droplet so that in case anything goes wrong, you can revert to a working version of your server.

WordPress site and home URLs

You would need to start by updating your WordPress site and Home URLs to the new domain name:

  1. Log in to your WordPress Dashboard for the site hosted on openplcproject.com.

  2. Navigate to “Settings” > “General.”

  3. Update the “WordPress Address (URL)” and “Site Address (URL)” fields to https://autonomylogic.com.

  4. Save the changes.

This will update the internal WordPress configuration to use the new domain.

If the options to change the WordPress Address and Site Address URLs are not available in the WordPress Dashboard, you can modify these settings by editing the wp-config.php file.

Here’s how to do it:

  1. Access the File System: Using an FTP client or your hosting provider’s file manager, navigate to the root directory of your WordPress installation.

  2. Find the wp-config.php File: This file is located in the root directory of your WordPress installation.

  3. Open the wp-config.php File: Edit the file using a text editor.

  4. Add or Modify the Following Lines: These lines define the WordPress Address (URL) and Site Address (URL). Replace "http://autonomylogic.com" with your actual URL.

    define('WP_HOME', 'http://autonomylogic.com');
    define('WP_SITEURL', 'http://autonomylogic.com');
    
  5. Save and Close the File: Once you’ve made the changes, save and close the file.

  6. Clear the Cache: Depending on your setup, you may need to clear the cache on your web server and your browser to see the changes take effect.

  7. Check the Site: Visit your site at the new domain to make sure everything is working as expected.

Apache virtual host update

Once this is done, you will need to update your Apache configuration to define the new domain name.

First start by accessing your server via SSH:

https://docs.digitalocean.com/products/droplets/how-to/connect-with-ssh/

  1. Open the Apache Configuration File: Find the configuration file for your site, it should be located at /etc/apache2/sites-available/your-site.conf

  2. Modify the ServerName Directive: Look for the ServerName directive in the file and change it to your new domain name. If you have a ServerAlias directive for the old domain, you may want to update that as well:

    ServerName autonomylogic.com
    ServerAlias www.autonomylogic.com
    
  3. Save and Close the File: Once you’ve made the changes, save and close the file.

    After that check the /etc/apache2/sites-available/ directory and see if you have a separate virtual host for the HTTPS version, you can use the ls -l /etc/apache2/sites-available/ to see the availalbe virtual hosts in that directory.

  4. Reload Apache: Run the following command to reload Apache and apply the changes:

    sudo systemctl reload apache2
    

Issue a New SSL Certificate with Certbot

Next, as the SSL certificate will be still for the old domain, you will have to use Certbot to request a new certificate for your new domain.

  1. Run the following command, replacing "autonomylogic.com" with your actual domain:

    sudo certbot --apache -d autonomylogic.com -d www.autonomylogic.com
    
  2. Follow the Prompts: Certbot will guide you through the process, including verifying domain ownership.

  3. Reload Apache Again: After obtaining the certificate, reload Apache again to ensure the new certificate is being used.

    sudo systemctl reload apache2
    
  4. Test Your Site: Access your site via HTTPS to ensure that the SSL certificate is working correctly.

By updating both the Apache configuration and the SSL certificate, you’ll ensure that your site is accessible at the new domain name and that the connection is secured with HTTPS. Make sure to back up any configuration files before modifying them, as incorrect changes can lead to issues with your server.

As this requires a few steps, I would like to mention again that it is best to make sure that you have a backup of your server before you proceed with this!

Hope that this helps!

Best,

Bobby

KFSys
Site Moderator
Site Moderator badge
September 6, 2023

Heya,

In such cases I recommend using WP-CLI. WP-CLI provides a command-line interface for many actions you might perform in the WordPress admin. For instance, wp plugin install --activate (doc) lets you install and activate a WordPress plugin:

https://wp-cli.org/

In the site are the steps on how to install it on your Droplet.

Here’s a step-by-step guide on how to switch your domain using WP-CLI:

Backup Your Database: Before making any changes, it’s essential to backup your WordPress database in case something goes wrong.

wp db export backup.sql

Search and Replace: Run the search-replace command to replace the old domain with the new domain. Replace old-domain.com with your current domain and new-domain.com with your desired domain.

wp search-replace 'http://old-domain.com' 'http://new-domain.com' --all-tables

If your site uses https, ensure you replace http with https in the above command accordingly. Update WordPress and Site URL (if they are not hard-coded in wp-config.php):

wp option update home 'http://new-domain.com'
wp option update siteurl 'http://new-domain.com'

Flush Rewrite Rules: To ensure that the site’s permalinks work correctly, you might want to flush the rewrite rules.

wp rewrite flush

Update Your DNS: Make sure to update your DNS settings to point the new domain to your DigitalOcean droplet’s IP address.

Update .htaccess: If there are domain-specific rules in your .htaccess file, make sure to update them.

Update SSL Certificate: If you’re using an SSL certificate, you’ll need to obtain a new one for the new domain or update your current one to support the new domain.

Test the Site:

-   After making these changes, clear your browser cache.
-   Visit the new domain and navigate through the site to ensure everything is working correctly.
-   Ensure that resources (images, scripts, stylesheets) load correctly, and there are no mixed content warnings (this can happen if some resources still point to the old domain on an https site).
  1. Update Search Engines (Optional): If you’re moving a live site, you might want to notify search engines about the change of address to maintain SEO rankings. You can do this through tools like Google Search Console.

By following these steps, you should have your WordPress site functioning correctly on the new domain. Remember, domain propagation can take some time (up to 48 hours, though often much less), so you might not see the changes immediately.

alexdo
Site Moderator
Site Moderator badge
August 26, 2023

Heya,

The steps provided by Bobby are what you need to get this sorted. I would like to share a question which was previously asked in our community on the same topic.

https://www.digitalocean.com/community/questions/change-url-in-wordpress

Regards

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel