Manually Migrate Websites to a New Server (Linux)
Please use the “Print” function at the bottom of the page to create a PDF.
This article describes how to:
- Determine the required website data and the configuration files in Apache and Nginx
- Back up the MySQL database used
- Save the website files and the exported MySQL database locally on your computer
- Install applications such as Apache, Nginx, MySQL/MariaDB, PHP, Plesk and WordPress
- Import the website files
- Move a WordPress blog
Warning
If you migrate your server data manually to a new server, you must migrate your domains and email inboxes before the migration. You must also adjust the DNS settings after migrating your domains. Otherwise there is a risk of data loss.
You can find detailed instructions on how to manually migrate your server data to a current VPS in the following article:
Manually migrating server data to a current VPS
Tips
- The successful migration of a website requires careful planning and implementation.
- Before the migration, check which security settings and configurations need to be made on the new server. Make these settings as part of the migration. This applies to both the installed operating system and the installed applications.
- After the migration, make sure that the functionality of your websites, applications and scripts is carefully checked. Plan enough time for testing and troubleshooting.
- Inform your users of any planned downtimes.
- Please note that the migration of websites is not included in our scope of support. If necessary, please contact a web developer to find out how best to migrate your website. If you would like to utilise the services of a website developer, please search our partner network for a suitable professional.
Determine Website Files
To determine the required website files, proceed as follows:
Apache
Establish an SSH connection to your previously used server and log in as administrator.
To search for text containing the name of your domain in all files in 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 the configuration file of your website is then displayed. Example:
/etc/apache2/sites-enabled/example.com.conf
Open the file with the vi editor. To do this, adapt the command below and then enter it:
[root@localhost ~]# vi /etc/PFAD/PFAD/DATEINAME.conf
Example:[root@localhost ~]# vi /etc/apache2/sites-enabled/example.com.conf
Note the path to the website files listed in 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 your previously used server and log in as administrator.
Open the Nginx configuration directory.
[root@localhost ~]# cd /etc/nginx
Open the main Nginx configuration file with the vi editor. This is usually the nginx.conf file. 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 that contain include. Then check which other configuration files or directories are 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 below /etc/nginx for the character string root. The output shows you the files and the associated lines in which the root directive is set.
The output of grep can contain several lines if Nginx hosts several websites (server blocks), for example. Each line shows the path of 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.
- Note the path of the root directory.
Check the contents of the root directory. To display the contents, enter the following command:
[root@localhost ~]# ls -l /PFAD
Example:
[root@localhost ~]# ls -l /var/www/example.com/html
Back up MySQL Database
To migrate the MySQL database for your website, you need to know the access data for the MySQL database. You will also need the following information:
- Port
- Host
- Name of the database
If you know the access data for the MySQL database, you can skip this section.
Determine access data
The following explains where you can find the MySQL access data:
WordPress
In WordPress, you can find the MySQL access data 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
/** 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 CMS
For websites that access a database directly and do not use a CMS, the storage of access data depends on the individual configuration. The access data is often stored in configuration files that are used by the respective scripts. To find the access data in this case, you must search for database connection parameters in the PHP, Python, Java or other backend files.
Export MySQL Database
To back up a MySQL database, use the mysqldump tool, which is supplied with most MySQL installations. Replace the placeholders in the command below and then enter the command.
mysqldump --no-tablespaces --port PORTNUMMER --host=HOSTNAME --user=USERNAME --password=PASSWORD DATABASENAME | gzip > /root/dbdump.sql.gz
After entering the command, the database is exported to the root directory. The file name is dbdump.sql.gz.
Hint
If your file names, passwords or user names contain special characters, you must enclose them in single inverted commas (') in the mysqldump or mysql command.
Example: mysqldump [...] --password='%gCjmnrmLk!xnSefw'
Save Website Files and the Exported Mysql Database Locally
Save the copy of the website files and the exported MySQL database on a local computer. You can use the FileZilla programme for this. FileZilla is available for computers with Windows, MacOS and Linux operating systems.
You can download the latest installation file for your operating system from the following page:
https://filezilla-project.org/download.php?type=client
To establish a connection to your server with FileZilla and download the copy of the website files and the exported MySQL database to a local computer, proceed as follows:
- Start FileZilla.
- Enter the IP address of the server in the Server field.
- Enter the user name root in the User field.
- In the Password field, enter the password that you have set.
- Enter port 22 in the Port field.
- Click on Connect.
The connection to the server is established. The directories located on your client are displayed in the area on the left. The directories located on your server are displayed in the area on the right. - 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 to the desired directory on your local computer using drag-and-drop.
- Also copy the required configuration files or directories to the desired directory on your local computer using drag-and-drop.
- Open the root directory.
- Select the exported database. The file name is dbdump.sql.gz. Then copy the file to the desired directory on your local computer using drag-and-drop.
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 also use on your previous server.
Caution
Check the necessary system requirements before installation. You can also find out about any compatibility problems on the software manufacturer's website.
Installing Apache, MySQL/MariaDB and PHP
You can find instructions on how to install Apache, MySQL/MariaDB and PHP in the following articles:
Installing Nginx
Instructions on how to install Nginx are listed in the following article:
Installing Plesk
You can find instructions on how to install Plesk in the following articles:
Installing WordPress
You can find instructions on how to install WordPress on a server in the WordPress documentation. This can be found on the following page:
Secure Operating System and Application
Customise all required security settings and configurations of the new server. This applies to both the installed operating system and the installed applications.
Information on some fundamentally important security measures can be found in the following article:
Important security information for your Linux server (part 2 of 2)
Importing the Website Files
Apache
- Establish an SSH connection to your new server and log in as administrator.
- Also open Filezilla.
- Copy the backed up data and configuration files with FileZilla using drag-and-drop into the corresponding 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 Apache, switch to the programme with which you established the SSH connection and enter the following command:
[root@localhost ~]# sudo /etc/init.d/apache2 restart
- 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 administrator.
- Also open Filezilla.
- Copy the backed up data and configuration files with FileZilla using drag-and-drop into the corresponding directories on your new server.
- Check the configuration files as well as the paths and settings that were aligned to the old server environment and adjust them if necessary.
To restart Nginx, switch to the programme with which you established 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 MySQL database
- Open FileZilla.
- Copy the exported database to the corresponding directory on your new server using drag-and-drop.
- Switch to the programme you used to establish the SSH connection.
- Open the directory in which the exported database is located.
To restore your data, execute the mysql command according to the scheme below. Replace the placeholders written in capital letters with the access data of the database in which you want to restore the data.
gunzip -c FILENAME | mysql --user=USERNAME --password=PASSWORD DATABASE
- Check the security settings of your MySQL database.
Move WordPress Blog
You can find instructions on how to migrate your WordPress blog on the following page: