The following assumes that you will be working as root via SSH. Knownhost uses port 2200 by default for SSH. Use the following syntax to log in as root via SSH, but replace IP.IP.IP.IP with your server's actual IP:
ssh root@IP.IP.IP.IP -p2200
If you've not already created the new cPanel account/domain that you'd like to use, do this first. You can use the 1)whmapi or the 2) wwwacct script to do this rather easily. The whmapi takes many possible parameters, but the following example only uses the required parameters for the sake of brevity.
whmapi1 createacct username=username domain=example.com
The output will contain the account's password (created by the panel) and other details that were set by the panel based on configured defaults. If you want to make other changes, you can do so afterwards via WHM's Modify an Account interface.
If using the wwwacct script, it uses the following syntax:
/usr/local/cpanel/scripts/wwwacct domain user pass
uapi --user=username SubDomain addsubdomain domain=subdomain rootdomain=example.com
You'll need to know the first site's username and document root to proceed.
To find the site's owner, use this command where domain.tld is replaced with your site:
To find the documentroot of the site, use this command, replacing username with the username you just found and domain.tld with the domain:
grep documentroot /var/cpanel/userdata/username/domain.tld
Now that we have created an account and have identified the site's document roots, we can use the following sequence of commands to create a copy of a site's files/directories at a different site's document root and update the ownership accordingly (these commands should be adjusted accordingly for your specific site's document roots and usernames!):
cp -a /home/old/public_html/* /home/new/public_html/ cp -a /home/old/public_html/.htaccess /home/new/public_html/.htaccess chown -R new.new /home/new/public_html/
First, you may need to know the database's name. You can get it like so:
grep DB_NAME /home/old/public_html/wp-config.php
Now that you know the database name, you can make a backup of it using the following command:
mysqldump old_website > old_website.sql
Make a new database user, username, and password in new's cPanel. You can do this via cPanel's MySQL Databases interface, or you can use the uapi commands via the root ssh shell like so:
uapi --user=new Mysql create_database name=new_db uapi --user=new Mysql create_user name=new_admin password=p455w0rd uapi --user=new Mysql set_privileges_on_database user=new_admin database=new_db privileges=ALL
Use the following command to do this:
mysql new_db < old_website.sql
You will need to update the wp-config.php file to use the new database details:
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'cPuser_db'); /** MySQL database username */ define('DB_USER', 'cPuser_dbuser'); /** MySQL database password */ define('DB_PASSWORD', 'password');
You will find useful commands online often to update the siteurl and home values in the wp_options table, but the following should take care of these and so much more.
Let's use WP-CLI's search-replace tool to first perform a dry-run and see how many replacements of the old domain with the new domain will occur. Make absolutely certain that you are in the new document root when you run this command!
I would then review the output from the following, which would show all findings of the old url that would be replaced with the new url when using wp-cli:
su -s /bin/bash -c "/usr/local/cpanel/3rdparty/bin/wp search-replace old.com new.com --dry-run" new
Above, new represents the new cPanel user's username.
Run the following to proceed with replacing the old url with the new url in the newly created database containing the import of the sql backup I old from the old site.
su -s /bin/bash -c "/usr/local/cpanel/3rdparty/bin/wp search-replace old.com new.com --skip-columns=guid" new
Now, WordPress warns against changing the 4)GUID. This mainly applies to RSS feeds and feed-readers. These feeds are enabled by default. If you have users that use a RSS feed for getting updates from your site, if we change the GUID to the new URL, they will be flooded with old posts as if they were new. This is why WordPress warns against changing the GUID column.
Depending on how many there are, you may just do this manually, or write a sed command to accomplish it like so:
sed -i.bak 's/old.com/new.com/g' .htaccess
The command above should make a backup .htaccess before applying the changes. The backup .htaccess will have .bak appended to it like so:
Lastly, I would make a backup of the old account before deleting it just in case.
wp search-replace foo bar --export=database.sql
Using this command could combine steps noted above (particularly steps 6 and 8), further speeding up and simplifying the process.
If you have any questions about this process, or require assistance, please provide the link to this wiki article, the source and desired destination domains and usernames, and your support request to your KnownHost support team. :)