Merge multiple cPanel accounts into one account using SSHWritten by Jacob Nicholson
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.
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..
- Login to your server via SSH as the root user.
- You'll want to find the document root for our AddonDomain.com domain then change to that directory with these commands:
grep addondomain.com /etc/userdatadomains
Which should give back:
Next change to the directory in-between the =='s with:cd /home/userna2/public_html
- 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:
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.
- Now that we know the database name we can backup that database using the following command:
mysqldump userna2_wrdp1 > ~userna2/userna2_wrdp1.sql
- 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
- 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.
- In the top-left Find box type in modify, then click on Modify an Account.
- Select AddonDomain.com, then click on Modify.
- 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.
- Still in WHM in the top-left Find box type in List, and then click on List Accounts.
- Now click on the cPanel icon for the PrimaryDomain.com account with the username userna1.
- Under the Domains section, click on Addon Domains.
- 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.
- 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.
- Under the Databases section click on MySQL Database Wizard.
- 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.
- I'm also going to set my database username to userna1_wrdp2, give that user a password then click on Create User.
- Finally on the last step of the database wizard, click on ALL PRIVILEGES to check everything, then click on Next Step.
- 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.
- Now we want to correct all of the ownership permissions for the userna1 user using the following command:
- 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.
- Finally you can log into WHM once more to remove the old standalone userna2 account.
- In the top-left Find box, type in terminate, then click on Terminate an Account.
- 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.