Table of Contents

Migrate a WordPress site from localhost to Ubuntu VPS

WordPress is not only a content material administration system. It grew to become greater than a content material administration system when sensible builders began making plugins and themes that we will use to create any sort of web site utilizing WordPress. It was first identified to create and handle blogs simply. However we will see these days the rise of E-commerce on WordPress. These days, persons are additionally creating enterprise or company web sites on WordPress. Nevertheless, All of the builders develop an internet site regionally on the pc. Then, they should migrate a WordPress website from localhost to VPS.

In case you are one such developer, you would possibly need to be taught how one can simply migrate a newly developed WordPress website from localhost to VPS. On this article, I’ll exhibit The right way to accomplish this job with out messing up a website or a server. Listed below are some conditions earlier than you get into the precise step-by-step information.


I assume you’ve a fundamental information of MySQL and Linux. We’re going to migrate a WordPress website to a stay server, It signifies that your VPS needs to be able to host an internet site. For those who haven’t put in LAMP or LEMP in your VPS but, Get a Linux VPS and Set up LAMP or Set up LEMP in your server.

You additionally want a root entry or sudo privilege on the server. It’s as a result of we’ll create a digital host on on our server. You possibly can comply with our following guides to be taught extra about Digital hosts.

  • The right way to handle Nginx digital hosts on Ubuntu
  • The right way to handle Apache digital hosts on Ubuntu

In case you have adopted our information to put in LAMP/LEMP stack and to handle digital hosts, you possibly can blindly comply with this information. In any other case, you may additionally should be sure to are working in response to your present configuration.

Step 1: Compress the WordPress information

WordPress is a mixture of information and a database. Recordsdata which means the WordPress codebase, your plugins, your themes and your media. Database is used to maintain monitor of all the things and to retailer your blogposts, theme configurations, consumer knowledge and rather more.

So, To begin with we’re going to compress WordPress information on localhost. You should utilize instruments like 7zip or zip or tar or something you want. Compress the entire WordPress set up listing.

Step 2: Export the Database

As I discussed within the earlier part, WordPress is made up with information and a database. The database is vital as a result of all of your posts, configuration and knowledge is saved within the database. Exporting the database may be difficult primarily based in your setting. In case you are utilizing Linux or MacOS, you need to use the next command in terminal to export your Database to an .sql file.

$ mysqldump -uDB_USERNAME -p DB_NAME > exported_DB_NAME.sql

You will get DB_USERNAME, DB_PASSWORD and DB_NAME from the wp-config.php file. As soon as it’s exported, we will transfer each the information and database to our distant server.

Step 3: Transfer/Copy/Add Recordsdata and Database to VPS

On this step, it’s important to add the compressed archive and the database to the VPS. You possibly can both use SFTP, or SCP or some other technique. Our purpose is to add each to the VPS.

Add it within the residence listing for now, don’t add any one in every of them the place they’re publicly uncovered.

In case you are utilizing Linux or MacOS, you need to use SCP which could be very straightforward to make use of. You possibly can merely execute the next instructions to shift your information kind localhost to some other machine.

$ scp /path/to/file consumer@server_ip:~

On this command, don’t forget to exchange the trail of the file and details about your VPS. You should utilize the identical command emigrate your compressed archive in addition to the database.

Step 4: Create and Import the Database on VPS

As now your database and information are on the VPS, The very first thing we’ll do is create a database and Import the exported .sql file into the database. To begin with, Allow us to create a database in MySQL. Execute the next command to login to MySQL as root.

$ mysql -uroot -p;

It should ask for a password, enter the proper MySQL root password after which execute the next queries to create a database together with a consumer in MySQL.

mysql> CREATE DATABASE wordpress;
mysql> CREATE USER 'wordpressUser'@'localhost' IDENTIFIED BY 'strong_password';
mysql> GRANT ALL PRIVILEGES ON wordpress.* to 'wordpressUser'@'localhost';

Don’t forget to exchange the Database title, Username and Password in these queries. As soon as your database is prepared, execute the exit command to exit the MySQL CLI. Now, Execute the next command to import the database.

$ mysql -uwordpressUser -p wordpress < /path/to/exported_DB_NAME.sql

Step 5: Create a listing, extract information and Replace Database Data

On this step, we’ll create a listing for our web site after which extract all our information inside that listing. Execute the next command to create a listing to your website contained in the /var/www listing.

$ sudo mkdir /var/www/instance.com

As soon as executed, Transfer your compressed archive inside this listing and extract all of the information inside this listing. We additionally should replace the database data contained in the wp-config.php file. Execute the next command to edit wp-config.php file.

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

Enter new values in DB_NAME, DB_USERNAME and DB_PASSWORD we set once we created a database on our VPS. Now, the very last thing now we have to do is to replace the file permissions. We’ll give possession to www-data so as to add media and replace theme instantly within the WordPress. Execute the next command to finish this job.

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

Now, there is just one step left. It’s to create and activate the digital host in response to your internet server.

Step 6: Create digital Host and Activate it (Apache)

In case you are utilizing Apache internet server, it’ll be straightforward for you as Apache offers in-build command to activate or deactivate the digital hosts. Execute the next command to create a brand new digital host in your Apache server.

$ sudo nano /and so forth/apache2/sites-available/instance.conf

And paste the next content material within the file. Don’t forget to exchange the instance knowledge with the precise knowledge relying in your website.

<VirtualHost *:80>
    ServerAdmin help@instance.com
    ServerName instance.com
    ServerAlias www.instance.com

    DocumentRoot /var/www/instance.com

    ErrorLog /var/log/apache2/instance-error.log
    CustomLog /var/log/apache2/instance-access.log mixed

As soon as executed, press CTRL+X adopted by Y adopted by Enter to avoid wasting the digital host file. Then, execute the next command to allow the digital hosts.

$ sudo a2ensite instance
$ sudo service apache2 restart

Now, your website is stay on the Web!

Step 6: Create Digital Host and Activate it (Nginx)

In case you are utilizing Nginx server, it’s important to manually create a symlink of the digital host to be able to activate it. Step one is to create a digital host. Execute the next command to create a brand new digital host in Nginx.

$ sudo nano /and so forth/nginx/sites-available/instance.conf

Now, Paste the next content material within the digital host file. Don’t forget to exchange the instance knowledge with the precise knowledge within the file, in any other case your website may not work.

    pay attention 80;
    server_name instance.com www.instance.com;
    root /var/www/instance.com;

    access_log /var/log/nginx/instance-access.log;
    error_log /var/log/nginx/instance-error.log

Now, execute the next instructions to create a symlink to activate the digital host. We additionally should restart the Nginx server to load the brand new configuration.

$ sudo ln -s /and so forth/nginx/sites-available/instance.conf /and so forth/nginx/sites-enabled/instance.conf
$ sudo service nginx restart

As soon as the Nginx server is restarted, your website can be stay on the Web.


Conclusion: For those who simply perceive how WordPress works, you possibly can migrate your WordPress website to some other working system or a server. The principle factor right here is emigrate the database and information safely to a brand new server after which join the identical database and information once more on the brand new server. You should utilize this technique emigrate your WordPress website from VPS to VPS too! You may also use WordPress plugins emigrate your WordPress website from one host to a different.

Please tell us you probably have any questions within the remark part given beneath. In case you are an current WebHostingPeople buyer, please contact our help if you would like us emigrate your WordPress web site for you.

Post Your Comment