Valid for VPS+, VPS, Cloud Servers, migrated Cloud Servers, Dedicated Servers, and Bare Metal Servers managed in the Cloud Panel.

In this article, you will learn how to:

  • identify the required website data and the configuration files in Apache and Nginx
  • back up the MySQL database in use
  • save the website files and the exported MySQL database locally on your computer
  • install required applications such as Apache, Nginx, MySQL/MariaDB, PHP, Plesk, and WordPress
  • import the website files
  • migrate a WordPress blog

Please Note

If you are manually migrating your server data to a new server, you must migrate your domains and email accounts before the migration. Additionally, you must update the DNS settings after transferring your domains. Failure to do so may result in data loss.

Notes

  • The successful migration of a website requires careful planning and execution.
  • Before the migration, check which security settings and configurations need to be applied on the new server. Carry out these settings as part of the migration process. This applies to both the installed operating system and the installed applications.
  • After the migration, ensure that the functionality of your websites, applications, and scripts is thoroughly tested. You should therefore allow sufficient time for testing and for rectifying any errors.
  • If necessary, inform your users of any planned downtime.
  • Please note that website migration is not included in our support services. If necessary, please contact a web developer to find out the best way to migrate your website. If you wish to use the services of a website developer, please search our Partner Network for a suitable specialist.
  • After the migration, allow sufficient time for testing and troubleshooting before going live.

Identify website files

To identify the required website files, complete the following:

Apache

  • Establish an SSH connection to the server you have been using and log in as an administrator. You can find instructions in the following article: Connecting to a Linux server via SSH

  • To search for text containing your domain name in all files within the /etc/apache2/sites-enabled directory and its subdirectories, replace the placeholder in the command below. Then enter the command.

    [root@localhost ~]# grep -Ril "DOMAINNAME" /etc/apache2/sites-enabled

    Example:

    [root@localhost ~]# grep -Ril "example.com" /etc/apache2/sites-enabled

    The file path for your website’s configuration file will then be displayed. Example:

    /etc/apache2/sites-enabled/example.com.conf

  • Open the file using the vi editor. To do this, adapt the command below and then enter it:

    [root@localhost ~]# vi /etc/PATH_TO_FILE/FILENAME.conf

    Example:

    [root@localhost ~]# vi /etc/apache2/sites-enabled/example.com.conf

  • Make a note of the path to the website files, which is listed on the DocumentRoot line. In the example below, this is the directory /var/www/html.

    [root@localhost ~]# vi /etc/apache2/sites-enabled/example.com.conf

    <VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog ${APACHE LOG DIR}/error.log
    CustomLog ${APACHE LOG DIR}/access.log combined

  • Press the [ESC] key.
  • To exit vi and save the file, enter the command :wq and then press Enter.

Nginx

  • Establish an SSH connection to the server you have been using and log in as an administrator. You can find instructions in the following article: Connecting to a Linux server via SSH
  • Open the Nginx configuration directory.

    [root@localhost ~]# cd /etc/nginx

  • Open the main Nginx configuration file using the vi editor. This is usually the file nginx.conf. To do this, adapt the command below and then enter it:

    [root@localhost ~]# vi /etc/nginx/nginx.conf

  • Search the main configuration file for lines containing include. Then check which other configuration files or directories are being loaded (e.g., sites-enabled/*).
  • Make a note of the required configuration files or directories and their paths.
  • To find the root directive that specifies the path to the website files, enter the following command:

    [root@localhost ~]# grep -R 'root' /etc/nginx/


    This command searches all files under /etc/nginx for the string ‘root’. The output shows you the files and the corresponding lines where the root directive is set.

    The output from grep may contain several lines if, for example, Nginx is hosting multiple websites (server blocks). Each line shows the path to the configuration file and the line in which the root directive is set. Example:

    /etc/nginx/sites-available/example.com: root /var/www/example.com/html;

    In this example, the path /var/www/example.com/html is used as the root directory for the example.com website.

  • Make a note of the path to the root directory.
  • Check the contents of the root directory. To view the contents, enter the following command:

    [root@localhost ~]# ls -l /PATH

    Example:

    [root@localhost ~]# ls -l /PATH

Back up the MySQL database

To migrate the MySQL database for your website, you will need to know the login details for the MySQL database. You will also need the following information:

  • Port
  • Host
  • Database name

If you already know the MySQL database login details, you can skip this section.

Finding your login details

The following explains where to find your MySQL login details:

WordPress

In WordPress, you can find the MySQL login details in the wp-config.php file. This is located in the root directory of your WordPress installation.

Typical paths look like this, for example:
 

/var/www/html/wp-config.php


or

/var/www/example.com/wp-config.php

Example:

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

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

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

/** MySQL hostname */
define('DB_HOST', 'db123456789.hosting-data.io');

/** WordPress database table prefix
$table_prefix = 'abcd';

Websites without a CMS

For websites that access a database directly and do not use a CMS, the storage of login details depends on the individual configuration. The login details are often stored in configuration files used by the relevant scripts. To find the login details in this case, you will need to search the PHP, Python, Java, or other backend files for database connection parameters.

Export the MySQL database

To back up a MySQL database, use the mysqldump tool, which is included with most MySQL installations. Replace the placeholders in the command below and then enter the command.

mysqldump --no-tablespaces --port PORTNUMBER --host=HOSTNAME --user=USERNAME --password=PASSWORD DATABASE_NAME | gzip > /root/dbdump.sql.gz


Once you have entered the command, the database will be exported to the root directory. The file name will be dbdump.sql.gz. This is a compressed file.

Notes

  • You will need root privileges to export a MySQL database.

  • If your filenames, passwords, or usernames contain special characters, you must enclose them in single quotes (') in the mysqldump or mysql command. Example: mysqldump […] --password='%gCjmnrmLk!xnSefw'

Save the website files and the exported MySQL database locally

Save a copy of the website files and the exported MySQL database on a local computer. You can use the FileZilla program for this. FileZilla is available for computers running Windows, macOS, and Linux.

You can download the latest installation file for your operating system from the following page:

https://filezilla-project.org/download.php?type=client

To connect to your server using FileZilla and download the copy of the website files and the exported MySQL database to a local computer, complete the following:

  • In the Host field, enter the server’s IP address.
  • In the Username field, enter the user name root.
  • In the Password field, enter the password you defined.
  • In the Port field, enter port 22.
  • Click Quickconnect.

    The connection to the server is established. The left-hand pane displays the directories located on your client. The right-hand pane displays the directories located on your server.
  • Create a directory on your local computer.
  • Open the root directory of your web server.
  • Select the root directory on your server and then copy it using drag-and-drop into the desired directory on your local computer.
  • Also, copy the required configuration files or directories using drag-and-drop into the desired directory on your local computer.
  • Open the root directory.
  • Select the exported database. The file name is dbdump.sql.gz. Then copy the file using drag-and-drop into the desired directory on your local computer.

Install applications on the new server

Before you import the website files and the exported database, you must install the applications on your new server that you were using on your previous server.

Caution

Please check the system requirements before installation. You should also check the software manufacturers’ websites for any potential compatibility issues.

Installing Apache, MySQL/MariaDB, and PHP

You can find instructions on how to install Apache, MySQL/MariaDB and PHP in the following articles:

Installing the LAMP stack on a server running CentOS Stream 9

Installing the LAMP stack on a server running Ubuntu

Install Nginx

Instructions on how to install Nginx are set out in the following article:

Installing NGINX Open Source

Install Plesk

You can find instructions on how to install Plesk in the following articles:

Installing Plesk (Linux VPS)

Installing Plesk (Windows VPS)

Install WordPress

You can find instructions on how to install WordPress in the WordPress documentation. This can be found on the following page: https://developer.wordpress.org/advanced-administration/

Securing the operating system and applications

Configure all the necessary security settings and configurations for the new server. This applies to both the operating system and the applications installed on the server. For information on some essential security measures, please refer to the following article: Important security information for your Linux server (Part 2 of 2)

Import the website files

Apache

  • Establish an SSH connection to your new server and log in as the administrator.
  • Also open FileZilla.
  • Using FileZilla, drag and drop the backed-up data and configuration files into the relevant directories on your new server.
  • Adjust the file permissions so that the web server has access. Example:

    [root@localhost ~]# chown -R www-data:www-data /var/www/html

  • Check the configuration files, as well as any paths and settings that were specific to the old server environment, and adjust them if necessary.
  • To restart Apache, return to the program you used to establish the SSH connection and enter the following command:

    [root@localhost ~]# systemctl restart apache2

  • Check the scripts you are using and adjust them if necessary.
  • Test the website and the configuration.


Nginx

  • Establish an SSH connection to your new server and log in as the administrator.
  • Also open FileZilla.
  • Use FileZilla to drag and drop the backed-up data and configuration files into the relevant directories on your new server.
  • Check the configuration files, as well as the paths and settings that were specific to the old server environment, and adjust them if necessary.
  • To restart Nginx, return to the program you used to establish the SSH connection and enter the following command:

    [root@localhost ~]# sudo systemctl restart nginx

  • Check the scripts you are using and adjust them if necessary.
  • Test the website and the configuration.


Import the MySQL database

  • Open FileZilla.
  • Copy the exported database into the relevant directory on your new server using drag-and-drop.
  • Switch to the program you used to establish the SSH connection.
  • Open the directory containing the exported database.
  • To restore your data, run the mysql command as shown below. Replace the placeholders in capital letters with the login details for the database into which you wish to restore the data.

    gunzip -c FILE_NAME | mysql --user=USERNAME --password=PASSWORD DATABASE

  • Check the security settings of your MySQL database.

Move a WordPress blog

You can find instructions on how to migrate your WordPress blog on the following page:

WordPress migration: Guide to moving your blog to a new server