How to Migrate Your Shared cPanel Hosting to a Vultr Cloud Server

Updated on July 25, 2024
How to Migrate Your Shared cPanel Hosting to a Vultr Cloud Server header image

cPanel is the most popular Linux control panel and a default option for most shared hosting providers. However, to switch from a shared hosting environment to cloud hosting with a Virtual Private Server (VPS), you must have some little know-how on working with the Linux console.

In this guide, you will migrate from a shared hosting environment using cPanel to a new cloud hosting environment running a Ubuntu 20.04 server. You can choose a different OS family from the Vultr customer portal depending on your preferences.

Furthermore, this article is divided into three optional sections based on your Linux experience.

Prerequisites

1. Create Server FTP Accounts

To transfer files directly from cPanel to the VPS server, you need to enable FTP on the server and create a new user account to transfer the files with. You can find a detailed vsFTPd installation guide here.

Well, install vstpd on the server.

$ sudo apt-get vsftpd

Now, edit the configuration file, and allow local users to log in on the server.

Using your favorite editor, edit the file /etc/vstpd.conf.

$ sudo nano /etc/vsftpd.conf

Find the lines below:

local_enable=YES
write_enable=YES

anonymous_enable=NO

Uncomment them by removing #, then save and close the file.

If you have no local user accounts on the server yet, create one and grant the user sudo rights.

# adduser example sudo

Enter the First Name, Last Name, and confirm with Y to create the user account.

Now, start the FTP server.

$ sudo service vsftpd start

Then, open port 22 on the firewall.

$ sudo ufw allow 22/tcp

Restart the firewall

$ sudo firewall reload

2. Log in to cPanel

Depending on your shared hosting provider, log in to your cPanel through port 2083 or add /cpanel to the end of your domain URL.

https://example.com/cpanel

3. Backup cPanel

It's important to back up your cPanel configuration as a way of keeping a copy of the website files, emails, DNS records, and databases before migrating to a new server.

Using the cPanel dashboard, make a full backup by selecting backup under the Files section.

Under Backup Destination, select SCP from the list of options. Enter your Vultr Server IP in the Remote Server field, FTP user, password, and port created on step 1, respectively, to generate the backup file.

Full cPanel backup

A connection is established to your server, and once the backup is complete, log in to your VPS server to locate the newly added backup-***_***.tar.gz file. By default, the file is uploaded to your account root directory ~, or the directory specified in the Remote Dir: field.

Now, extract files from the backup archive.

$ tar -xvf backup-***_***_example.tar.gz

Rename the extracted directory for easy identification.

$ mv backup-**_**_example/ cpanelfiles

Now, change to the directory, and list all files.

$ cd cpanelfiles/

$ ls

Output

drwx--x--x 16  4096 Dec 26 23:07 homedir/ **– contains all necessary webfiles**
-rw-------  1   14 Dec 26 23:07 homedir_paths
drwx------  2  4096 Dec 26 23:07 httpfiles/
drwx------  2  4096 Dec 26 23:07 ips/
drwx------  2  4096 Dec 26 23:07 locale/
drwx------  2  4096 Dec 26 23:07 logs/
drwx------  2  4096 Dec 26 23:07 meta/
drwx------  2  4096 Dec 26 23:07 mm/
drwx------  4  4096 Dec 26 23:07 mma/
drwx------  2  4096 Dec 26 23:07 mms/
drwx------  2  4096 Dec 26 23:07 mysql/ **-- contains all mysql database backup files**
drwx------  2  4096 Dec 26 23:07 mysql-timestamps/

Option 1: Install a Web Stack to Host Your Website

With all cPanel files transferred to the server, you can safely migrate your domain name by changing the nameservers to Vultr and setting up your hosting environment. The Apache, MySQL, PHP (LAMP) Stack is recommended for hosting the migrated files since several hidden files like .htaccess will remain unchanged.

If you are migrating WordPress website files, you can optionally choose to install (E)Nginx, MySQL, PHP (LEMP). But for purposes of this article, install LAMP on the server.

First, set the server's fully qualified domain name. For example, replace example.com with your actual domain.

$ sudo hostnamectl set-hostname example.com

Install Apache

Ubuntu

$ sudo apt install apache2

CentOS

$ sudo dnf install apache2

Allow Apache to start at boot time

$ sudo systemctl enable apache2

Start the Apache webserver

$ sudo systemctl start apache2

Install MySQL

$ sudo apt install mysql-server 

Secure the database server with a root password and remove insecure defaults.

$ myql_secure_installation

Enable MySQL to start at boot time.

$ sudo systemctl enable mysql

Start MySQL.

$ sudo systemctl start mysql

Now, log in to MySQL.

$ mysql -u root -p

Create a new database for your website.

mysql> CREATE DATABASE exampledb;

Create a new user with a secure password.

mysql> CREATE NEW USER exampleuser IDENTIFIED BY 'STRONG-PASSWORD';

Grant the user full permissions to the database.

mysql> GRANT FULL PRIVILEGES ON exampledb.* TO 'exampleuser'@'localhost';

Refresh MySQL rights.

mysql> FLUSH PRIVILEGES;

Exit the console.

mysql> EXIT

Install PHP.

$ sudo apt install php

Also, install necessary PHP modules.

$ sudo apt install php-xml php-gd php-mysql php-curl php-zip php-mbstring

Configure Apache

Create a new Apache virtual host configuration file.

$ sudo touch /etc/apache2/sites-available/example.com.conf

Now, using your favorite text editor, edit the file.

$ sudo nano /etc/apache2/sites-available/example.com.conf

Paste the following lines of code:

<VirtualHost *:80>
    ServerAdmin user@example.com
    ServerName  example.com

    # Index files and web root directory
    DirectoryIndex index.php index.html
    DocumentRoot /var/www/example.com/

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^index\.php$ - [L]
        RewriteCond $1 ^(index\.php)?$ [OR]
        RewriteCond $1 \.(gif|jpg|png|ico|css|js)$ [NC,OR]
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^(.*)$ - [S=1]
        RewriteRule . /index.php [L]
    </IfModule>
    # END wordpress

    Options FollowSymLinks
    Order allow,deny
    Allow from all
</VirtualHost>

Save and close the file

Test the configuration

$ sudo apachectl configtest

Enable the configuration file

$ sudo a2ensite example.com.conf

Restart Apache

$ sudo systemctl restart apache2

Now, copy your extracted cPanel website files to the new virtual host webroot directory. The homedir/ directory contains all necessary files, copy from your domain root or public_html/ whichever worked as your cPanel web files directory.

$ sudo cp cpanelfiles/homedir/public_html/* /var/www/example.com

Grant Apache ownership rights to the webroot directory

$ sudo chown -R www-data:www-data /var/www/example.com

Next, edit your website configuration file to include the new database name, username, and password.

$ sudo nano /var/www/example.com/wp-config.php

Find the lines below:

/** The name of the database for WordPress */
define( 'DB_NAME', 'exampledb’);

/** MySQL database username */
define( 'DB_USER', 'exampleuser' );

/** MySQL database password */
define( 'DB_PASSWORD', 'strong-password' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Change them to reflect your database name, username, and password.

Restore Databases

To restore your cPanel databases, switch to mysql/ within the extracted files directory, and locate the target .sql database file.

Change to the mysql directory.

$ cd /cpanelfiles/mysql

Restore your database.

$ mysql -u root exampledb < file.sql

Once complete, log in to the MySQL shell and check for new tables in the database.

$ mysql -u exampleuser

Confirm new database tables.

mysql> use exampledb;

mysql> select * from exampledb;

Exit the console.

mysql> EXIT

Configure the Firewall

Open Port 80 to allow HTTP traffic.

$ sudo ufw allow 80/tcp

Open Port 443 to allow HTTPS traffic.

$ sudo ufw allow 443/tcp

Check the current Firewall table.

$ sudo ufw status

Restart the firewall.

$ sudo ufw reload

Point your Domain Name to the New Vultr Cloud Server

First, log in to the Vultr customer Portal, add a new domain, and enter your Server IP in the Default IP Address field.

Add Vultr DNS

Then, log in to your domain registrar side, edit your domain, and point your nameservers to Vultr.

Save changes and test your new cloud server.

Test Your New Cloud Server

Your website is ready to use, the domain is pointed to your VPS server, and all necessary files are installed in the webroot directory. Test your server by visiting your domain name.

http://example.com

Depending on the DNS propagation period, which often takes between 3-12 hours to complete, your website should be able to load from the new VPS server. However, you can request a new SSL certificate since all domain requests point to the new server.

Enable HTTPS

Install Certbot.

$ sudo apt install python3-certbot-apache certbot

Request for a Free Let's Encrypt SSL certificate. Replace example.com with your domain name and user@example.com with your actual email address.

$ sudo certbot -d example.com -m user@example.com

Test auto-renewal.

$ sudo certbot renew –dry-run

Your website is now ready to serve HTTPS traffic. Test your server by visiting https://example.com to confirm the new changes.

Option 2: Migrate to a free Control Panel

cPanel is a paid Linux control panel. If you wish to migrate to a free control panel, there is a large pool of open-source variants to choose from. However, only a few accept cPanel backups. For detailed guides on how to install some of the free control panels, you can refer to the following:

For purposes of this article, we use Virtualmin since it supports direct restoration from cPanel backups.

Login to Your Virtualmin Dashboard

Expand Add Servers and select Migrate virtual server from the drop-down list of options on the left navigation bar.

Now, select local file from the source backup file field, then enter the backup file directory.

 /home/example/backup***_***.tar.gz

Next, under Backup file type, select cPanel backup, then choose work out from backup, if possible for the domain name, username, and administrator password fields, respectively.

Virtualmin cPanel restoration

Click Migrate Now to import your cPanel data to Virtualmin. Once complete, your server should be ready to use. Old domain name entries will be replaced with your current server options, so be sure to point your domain to the new Vultr nameservers.

Option 3: Migrate to Self-hosted cPanel

By default, cPanel is automatically licensed per month on Vultr, and you will not need any previous licenses to run. Once you spin your once-click server, log in to WHM to get started with the restoration process.

http://server-ip:2087

Using the WHM Interface, navigate to Transfers, and locate the Transfer and Restore a cPanel account option. Then, select the file from the server, or upload the cPanel backup file directly from your computer.

Next, select Replace All Matching A Records to remove and replace old cPanel records with new server records.

Click Restore to create a new cPanel account from the files, then restore all domains, web files, and mail accounts to the server.

Troubleshooting

If your cPanel account is limited to just a few features with the Backup and Backup Wizard options missing, you can still migrate your files from the server. To do this, create a new FTP account.

Using your cPanel dashboard, navigate to the Files section and click FTP Accounts. Then, create a new FTP account with a strong password and create your backup files.

cPanel files section

Partial Backup (Only Website Files, No Mail accounts)

Select 'File Manager' from the files section if you only plan to migrate your website files and associated databases.

Then, in the file manager window, locate your Website root files, then compress the directory to either .zip or tar.gz.

Compress cpanel web files

A new compressed file will be added to the directory. Now, identify your database name from the website files. If you are hosting a WordPress website, wp-config.php contains the database information you need. Take note of the database name and table prefix.

Backup Databases

Using the main cPanel dashboard, navigate to the Databases section and click phpMyAdmin.

Once redirected to phpMyAdmin, choose your target database, and export it to your computer. A new .sql file will be downloaded to your computer. Rename the file for easy identification.

phpMyAdmin

Depending on your website files size, it's recommended to upload the SQL file to the same directory as the compressed files for easy migration to the new server.

Migrate to the New Server

Once website files are compressed to a readable format, SSH and log in to the new server, then use curl to fetch files from the cPanel server.

Install Curl, if not already installed.

$ sudo apt install curl

Then, edit the following script with your domain name, cPanel FTP account, and password.

Fetch web files:

$ curl -u USERNAME:PASSWORD ftp://localhost/test_curl/filename.tar.gz

Fetch SQL database file:

$ curl -u USERNAME:PASSWORD ftp://localhost/test_curl/exampledb.sql

Replace filename.tar.gz with your actual compressed file and .sql with your renamed database file.

Once a connection is established, your files will be added to the new server. Extract the files, and follow steps from Option 1 of this article to set up your server.

Conclusion

Congratulations, you have successfully migrated from a shared environment using cPanel to a cloud hosting environment using Vultr. Once your domain fully propagates on the server, you can safely delete your shared hosting account without any downtime or disruption of user activity on your websites.