For those in the website game, sometimes you may need to migrate a website from one server to another. Whether you are switching hosting providers or upgrading your current hosting plan, you can migrate your website easily using cPanel.
For the purposes of this article, I am going to assume you are moving your website to a completely new server. Since this is this has slightly more steps to moving your website.
Also for clarification, when I refer to the “old server” that is the server that your website is already setup on. The “new server” refers to the server you are trying to migrate your website to. I am also assuming you have already paid your new hosting provider and have access to the cPanel.
Steps to Migrate Your Website:
- Backup your website files from your old server
- Export your MySQL databases
- Upload your website files to the new server
- Create your MySQL user accounts and databases
- Import your MySQL databases
- Update your database connection scripts
- Update your website name servers to point to the new server
Step 1: Backup your website files from your old server
To get started, login to your cPanel account on your old server. Open the File Manager application. Browse to the location of your website. If the website is your primary domain then you find it in the public_html directory, like so:
If the website is an addon domain, then you will find the website files inside of the directory you set at the website root. Likely within a folder inside of public_html, like this:
Once you are inside of the correct website folder on the old server, you need to create a backup of your website files by clicking “Select All” then “Compress”.
On the bottom of the popup window, you will see the location of the zip archive you are creating. Click the “Compress File(s)” button.
Download this zip archive and save it to a safe place for later.
Step 2: Export your MySQL databases
After you have created a zip archive backup of your website files, next you will need to create a backup of your MySQL database. Browse back to the cPanel home page on your old server. Locate the phpMyAdmin application and open it.
On the left side of phpMyAdmin, select the database that goes with the website you want to move to the new server. After you select the database, open the “Export” tool inside of phpMyAdmin.
After you have the Export tool open, you can simply click the “Go” button. On the save file dialog, select the location you want to save your MySQL database back to. I recommend the same place you have your website files backup to from Step 1 above.
Note: The file name you choose is not important for this database backup. Just ensure you keep the .sql file extension.
If you would like to learn more about phpMyAdmin and how to manage your website’s database using it, please checkout my other articles on phpMyAdmin.
Step 3: Upload your website files to the new server
At this point you should not need your older server any more. So we will be working on our new server. Login to the new server’s cPanel and open the File Manager application.
Browse over to the public_html directory on the new server and upload your zip archive we created in Step 1. Once uploaded, select the zip file and click the Extract button. Simply extract all the files into the public_html directory.
After your files have been extracted, you can delete the zip file you uploaded off of the new server. You shouldn’t need it any more. However, I recommend keeping the website backup file on your computer just in case.
Step 4: Create your MySQL user accounts and databases
Before you can access your website database on the new server, you may need to manually create the MySQL database. Also a MySQL user account to access your database.
From the cPanel home page, open the MySQL Databases application. From this page, you can modify and manage all of your MySQL databases and MySQL user accounts.
To setup the MySQL database on the new server, we will have to perform a few steps:
- Create a MySQL user account
- Create the MySQL database
- Add the user to the database
Step 4.1: Create a MySQL User account
Browse to the MySQL Users section to create a new MySQL user account.
Enter your desired username and password. Be sure to use a secure password. I recommend using the built in password generator in cPanel. Save your username and password in a safe place for later. We will need it to configure the database connection scripts later.
Note: Your MySQL account username will likely have a prefix on it. The prefix is usually your hosting account’s username. Be sure to use the ENTIRE username as your MySQL user account.
Step 4.2: Create the MySQL database
To create a new MySQL database, locate the Create New Database section. Simply enter a name for your database. That’s it. But be sure to note the prefix that will be automatically added to it, just like for the user account before.
Step 4.3 Add the user to the database
Now that we have a MySQL database and user account, we have to give the user the permission to access the database itself. To do this, locate the Add User to Database section.
On the drop down menu labeled User, select the username that you created earlier. Then on the dropdown menu labeled Database, select the database name you created earlier. Now click Add.
On the next page, you can select the specific permission your user account will have for this specific database. I recommend all permissions EXCEPT the execute permission. Once satisfied, click the Make Changes button to update the permissions.
Step 5: Import your MySQL databases
Now that out database is setup, we can import your MySQL database backup from earlier. From the cPanel home page of the new server, open the phpMyAdmin application. Very similar to how we created the database backup earlier, we are going to import the backup file directly into the database
Select the correct database for your website. Then click on the Import tab. From here, browse your computer to upload the database backup we created earlier. Upload this .SQL file and your database should be completely setup.
Step 6: Update your database connection scripts
With your website’s database restored, you need to update any and all of the database connection scripts. Since I am migrating a WordPress website to a new server in this example, I will update the wp-config.php file.
Open the File Manager application on the new server, then browse to the website’s installation directory. Likely the public_html directory. Locate and open the WordPress configuration file named wp-config.php by selecting the file and clicking the Edit button at the top.
In side the wp-config.php file, update the database connection settings for the new MySQL database and user account you created on the new server. In the picture above, the connection settings are from line 22-28. When you are done editing, save the file and close the editor.
Step 7: Update your website name servers to point to the new server
With all the other steps completed successfully, you have successfully setup your new web server to operate your website. The last step is to update your domain’s name servers to point to the new hosting service.
If your domain is already registered through a separate registrar company, then go to there website and login. Browse to the settings page for your domain. Find the settings for “name servers” and enter in the correct name server’s provided by your new server’s hosting company.
Once your name server has been updated on your domain registrar, it could take up to 24 hours for all of the global DNS records to update. And in turn, for your website to start functioning on the new server. It can take a shorter time, it just depends. But you can use a free tool like DNSChecker.org to check the status of your name server updates.
Migrate Your Website to New Server? Done.
Once your DNS settings have been fully updated globally, you will have completed all the steps needed to fully migrate your website from one server to another using cPanel!