Merge multiple cPanel accounts into one account using SSH

In this article we’ll discuss an advanced method for taking multiple cPanel accounts, and merging them down into one cPanel account. You can only have multiple cPanel accounts on a VPS or dedicated server plan. So if you’re looking at downgrading to shared hosting, or simply would like the convenience of managing multiple sites from one cPanel account this would be the guide for you.

For our example we have two cPanel accounts, userna1 with the domain name PrimaryDomain.com, and userna2 with the domain name AddonDomain.com. We’re going to take the AddonDomain.com domain and merge it into the userna1 cPanel account so that both of these domains can be managed from the single cPanel login going forward.

The AddonDomain.com site has a WordPress install on it, so we’ll need to ensure that we grab a copy of the MySQL database, and also ensure that we are updating the database credentials in any scripts once the files have been moved over to the userna1 account.

cPanel creation is no longer unlimited. Learn more about cPanel Pricing Changes and related FAQs.

To follow along with these steps you’ll need root access to your server. If you do not have root access then you’ll want to follow along with our more basic article on how to merge multiple cPanel accounts into one..

  1. Login to your server via SSH as the root user.
  2. You’ll want to find the document root for our AddonDomain.com domain then change to that directory with these commands: <code”>grep addondomain.com /etc/userdatadomains </code”>

    Which should give back:

    addondomain.com: userna2==root==main==addondomain.com==/home/userna2/public_html==70.39.151.52:80==

    Next change to the directory in-between the ==’s with:

    cd /home/userna2/public_html

  3. Next we’ll want to look for any database configuration files. This can be accomplished by looking for the username followed by an underscore _ using the following command: grep userna2_ . -RH

    Which should spit back:

    ./wp-config.php:define('DB_NAME', 'userna2_wrdp1');
    ./wp-config.php:define('DB_USER', 'userna2_wrdp1');

    Now we can see because this is using a wp-config.php script that these are the database credentials for a WordPress site. You’ll want to open up this file with your favorite text-editor and copy down the values for DB_NAME, DB_USER, and DB_PASSWORD for use later.

  4. Now that we know the database name we can backup that database using the following command: mysqldump userna2_wrdp1 > ~userna2/userna2_wrdp1.sql
  5. Now you’ll want to start copying over all of the data from the userna2 account to the userna1 account using the following commands: cp -frp ~userna2/etc/addondomain.com ~userna1/etc/

    cp -frp ~userna2/mail/addondomain.com ~userna1/mail/

    cp -frp ~userna2/mail/.*@addondomain_com ~userna1/mail/

    cp -frp ~userna2/public_html ~userna1/public_html/addondomain.com

  6. Next we’ll want to temporarily modify our AddonDomain.com domain so that we can add it to our userna1 cPanel account. To do this log into WHM.
  7. In the top-left Find box type in modify, then click on Modify an Account.
    whm-click-on-modify-an-account

     
  8. Select AddonDomain.com, then click on Modify.
  9. In the Primary Domain: field add a -temp.com suffix to your domain, so in this case we use AddonDomain-temp.com. Then scroll to the bottom and click on Save.
  10. Still in WHM in the top-left Find box type in List, and then click on List Accounts.
  11. Now click on the cPanel icon for the PrimaryDomain.com account with the username userna1.
    whm-click-on-cpanel-icon-for-userna1

     
  12. Under the Domains section, click on Addon Domains.

     
  13. Now type in AddonDomain.com as the new domain name, and choose a FTP username and document root for the site as well then click on Add Domain.
  14. Now that you have all of your website data loaded under the userna1 cPanel account the next thing you need to do is restore your MySQL database that you backed up. To do this login to your cPanel with the userna1 username.
  15. Under the Databases section click on MySQL Database Wizard.

     
  16. Now in this case I already know the userna1 user has one WordPress site and database already, so I’ll be naming my database userna1_wrdp2, then click on Next Step.
  17. I’m also going to set my database username to userna1_wrdp2, give that user a password then click on Create User.
  18. Finally on the last step of the database wizard, click on ALL PRIVILEGES to check everything, then click on Next Step.
  19. Now back in your SSH session you can import the MySQL database backup using the following command: mysql -u userna1_wrdp1 -p userna1_wrdp1 < ~userna2/userna2_wrdp1.sql

    At the Enter password: prompt enter in the password that you copied down earlier.

  20. Now we want to correct all of the ownership permissions for the userna1 user using the following command: fixperms userna1
  21. Now that you have your website data copied over, and the MySQL database imported you’ll want to modify your database credentials in the ~userna1/public_html/addondomain.com/wp-config.php script or any other database configuration scripts you found to use the userna1 cPanel username instead of the userna2 one. That way when you get rid of the userna2 account the database will continue to function as its own separate entity.
  22. Finally you can log into WHM once more to remove the old standalone userna2 account.
  23. In the top-left Find box, type in terminate, then click on Terminate an Account.
    whm-click-on-terminate-an-account

     
  24. Click on the AddonDomain-temp.com domain, then click on Terminate at the bottom of the page.

If you followed all of those steps you should have now successfully merged your AddonDomain.com site from the userna2 cPanel account, into the userna1 one. You could simply keep repeating this process again and again to get multiple cPanel accounts all merged down into one.

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!