Would you like to learn how to move your WordPress Website to a new Linux Server? In this tutorial, we are going to show you all the steps required to backup and move your Wordpress website to a new Ubuntu Linux server.
• Ubuntu version: 18.04
Hardware List:
The following section presents the list of equipment used to create this WordPress tutorial.
Every piece of hardware listed above can be found at Amazon website.
WordPress Playlist:
On this page, we offer quick access to a list of videos related to WordPress installation.
Don’t forget to subscribe to our youtube channel named FKIT.
WordPress Related Tutorial:
On this page, we offer quick access to a list of tutorials related to WordPress installation.
Tutorial – Backup your WordPress Website
First, you need to create a backup of your original WordPress website.
On the Linux console, use the following commands to create a backup of your WordPress database.
# mysqldump -u root -pYOUR_PASSWORD DATABASE_NAME > WORDPRESS-BACKUP.SQL
# mysqldump -u root -pkamisama123 wordpress > wordpress-backup.sql
Keep in mind that you need to replace the following strings on the command above:
• YOUR_PASSWORD – Replace this string for the MySQL root user password.
• DATABASE_NAME – Replace this string for the WordPress database name of your Website.
In our example, we used the MySQL root password kamisama123 to export our WordPress database.
Create a backup file containing all WordPress files from your website.
# tar -czvf wordpress-website-backup.tar.gz /var/www/html/wordpress
In our example, all files from the WordPress website are inside the following directory:
• /var/www/html/wordpress
Now, you need to transfer the WordPress database and file backup to the new Linux server.
The easiest way to do it is using the SSH SCP command.
# scp wordpress-backup.tar.gz wordpress.sql ubuntu@200.200.200.200:/tmp
In our example, the backup files were transferred to the directory /tmp of the new server 200.200.200.200.
We used an account named ubuntu to transfer the files to the new server.
Tutorial – Preparing the new WordPress Server
From now on, every single command should be entered on the new WordPress server.
First, we are going to configure the system to use the correct date and time using NTP.
On the Linux console, use the following commands to set the correct timezone.
# dpkg-reconfigure tzdata
Install the Ntpdate package and set the correct date and time immediately.
# apt-get update
# apt-get install ntpdate
# ntpdate pool.ntp.br
The Ntpdate command was used to set the correct date and time using the server: pool.ntp.br
Let’s install the NTP service.
# apt-get install ntp
NTP is the service that will keep our server updated.
Use the command date to check the date and time configured on your Ubuntu Linux.
# date
If the system shown the correct date and time, this means that you followed all the steps correctly.
Tutorial – MySQL on Ubuntu Linux
Now, we can proceed to the installation of the database service.
On the Linux console, use the following commands to install the required packages.
# apt-get update
# apt-get install mysql-server mysql-client
After finishing the installation, use the following command to access the MySQL database server.
# mysql -u root -p
Use the following SQL command to set a MySQL root user password.
In our example, the password set was kamisama123.
USE mysql;
UPDATE user SET authentication_string=password(‘kamisama123′) WHERE user=’root’;
FLUSH PRIVILEGES;
Use the following SQL command to create a database named wordpress.
Keep in mind that the database must have the same name it had on the older server.
In our example, the original database was named wordpress.
CREATE DATABASE wordpress CHARACTER SET UTF8 COLLATE UTF8_BIN;
Use the following SQL command to create a database user named wordpress.
CREATE USER ‘wordpress’@’%’ IDENTIFIED BY ‘kamisama123’;
Give the sql user named wordpress permission over the WordPress database.
GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpress’@’%’;
quit;
Import the original WordPress database.
The system will request you to enter the MySQL password.
# mysql -u wordpress -p wordpress < wordpress-backup.sql
You have finished the database installation.
You have imported the original WordPress database on the new MySQL Server.
Tutorial – Installing Apache on Linux
Now, we need to install the Apache web server and all the required software.
On the Linux console, use the following commands to install the required packages.
# apt-get install apache2 php7.2 php7.2-mysql libapache2-mod-php7.2 unzip
Use the following command to install the most used PHP modules.
Your new webserver must have the same PHP modules installed on the older WordPress server.
# apt-get install php7.2-xml php7.2-curl php7.2-gd php7.2-mbstring
# apt-get install php7.2-bz2 php7.2-zip php7.2-xml php7.2-curl
# apt-get install php7.2-json php7.2-opcache php7.2-readline
# service apache2 stop
# service apache2 start
# service apache2 status
Now, you should find the location of the php.ini file on your system.
After finding, you need to edit the php.ini file.
# updatedb
# locate php.ini
# vi /etc/php/7.2/apache2/php.ini
Keep in mind that your PHP version and the location of the file may not be the same of mine.
Here is the original file, before our configuration.
file_uploads = On
max_execution_time = 30
memory_limit = 128M
post_max_size = 8M
max_input_time = 60
; max_input_vars = 1000
Here is the new file with our configuration.
file_uploads = On
max_execution_time = 300
memory_limit = 256M
post_max_size = 32M
max_input_time = 60
max_input_vars = 4440
You should also restart apache manually and verify the service status.
# service apache2 stop
# service apache2 start
# service apache2 status
Here is an example of the Apache service status output.
● apache2.service – LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Mon 2018-04-23 00:02:09 -03; 1min 4s ago
Tutorial – Restoring the WordPress Installation on Ubuntu
Now, we need to restore the original WordPress files on the new web server.
Extract the WordPress backup from the TAR.GZ file and move it to the new web server.
# tar -zxvf wordpress-website-backup.tar.gz
# ls
wordpress
Move all the WordPress files to the root directory of your Apache installation.
Set the correct file permission on all moved files.
# mkdir /var/www/html/wordpress
# mv wordpress/* /var/www/html/wordpress
# chown www-data.www-data /var/www/html/wordpress/* -R
Edit the WordPress configuration file.
# cd /var/www/html/wordpress
# vi wp-config.php
Verify if the database connection is configured correctly.
define(‘DB_NAME’, ‘wordpress’);
define(‘DB_USER’, ‘wordpress’);
define(‘DB_PASSWORD’, ‘kamisama123’);
define(‘DB_HOST’, ‘localhost’);
define(‘DB_CHARSET’, ‘utf8’);
define(‘DB_COLLATE’, ”);
Open your browser and enter the IP address of your new web server plus /wordpress.
In our example, the following URL was entered in the Browser:
• http://35.162.85.57/wordpress
You original WordPress website should be presented on the new Web server.
On the WordPress dashboard, access the Settings menu and select the Permalinks option.
Click on the Save changes button.
You have finished the migration of your WordPress website.
Go to the Website home page and test the access to your posts and pages.
Make sure that everything is working.