Migrate a WordPress site from localhost to Ubuntu Server

Migrating your WordPress site from a local development environment to a live Ubuntu server can be a difficult task especially for beginners. However, with a clear understanding of the steps involved and the necessary tools the process can be streamlined.

In this article, we will cover you through the entire migration process from preparing your local site to configuring your Ubuntu server and finally launching your live website.

Prerequisites

Before we migrate WordPress localhost Ubuntu ensure you have the following:

  1. A fully functional WordPress site running on your local machine.
  2. A VPS or dedicated server running Ubuntu, with SSH access.
  3. SCP command for the smooth migration process.

Preparing Migration

Migrating a WordPress site from a localhost environment to a live Ubuntu server is an essential step for taking your website live.

Backup WordPress Site

Before making any changes ensure you have a complete backup of your WordPress site which includes:

  • Database backup: The database holds all the content settings and configurations of your site. Without it, your site would be just a collection of files without meaningful content. Backing up the database ensures you can restore your site’s content and structure in case anything goes wrong.
  • WordPress files backup: These files include themes, plugins, uploaded media, and WordPress core files. By backing up these files you ensure that the design functionality and appearance of your site are preserved.

This article assumes that you have installed WordPress locally on your Windows system. To set up WordPress locally you need to install XAMPP on Windows system. Navigate the XAMPP directory then the htdocs folder. Inside the folder your WordPress directory is present, copy the WordPress directory and save it on your desktop.

wordpress directory

To back up the WordPress database, navigate to your browser and type in the search bar localhost/phpmyadmin You can use the phpMyAdmin interface to export your localhost WordPress database. Select your database then click on the “Export” button.

wordpress phpmyadmin

Choose “Quick Export” and “SQL format”. Download the .SQL file and save it on your desktop.

Now create a wordpress_transfer folder and paste the WordPress folder and .SQL file inside the folder. Compress the folder like wordpress_transfer.zip.

wordpress transfer

Prepare Ubuntu Server

After taking a complete WordPress backup, log in to your Ubuntu server with the provided SSH credentials.

Update Server

Before proceeding to install WordPress localhost Ubuntu, update your Ubuntu system to ensure that all packages are up to date and compatible with the latest software versions. Execute the following command to update and upgrade your system:

sudo apt update && sudo apt upgrade
update and upgrade

Install Apache

Apache is one of the most popular web servers used to serve web content. It’s reliable and flexible, making it an excellent choice for hosting a WordPress site. To install Apache on Ubuntu, run the following command:

sudo apt install apache2
install apache

Install MySQL

MySQL is a powerful relational database management system that stores and retrieves your website’s data efficiently. WordPress relies on MySQL to manage its database operations. To install MySQL on Ubuntu, type the following command:

sudo apt install mysql-server
mysql server

Install PHP

PHP is the scripting language that WordPress is written in. By installing PHP and the necessary modules, you enable your server to process PHP scripts and interact with the MySQL database. You can type the following command:

sudo apt install php libapache2-mod-php php-mysql
install php

Configure Server Database

To recreate your local database on the server you need to set up a new database and user with the required permissions:

Login to MySQL with the following command:

sudo mysql -u root -p
mysql login

Create a database by typing the following syntax:

CREATE DATABASE your_database_name;
create wordpress database

Create a User and Grant Permissions:

CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'localhost';
FLUSH PRIVILEGES;

Creating a dedicated database and user ensures that your WordPress site has a secure and isolated environment to operate in. Granting the necessary permissions allows WordPress to interact with the database without unnecessary privileges.

Configure WordPress Files

Transferring your WordPress files from localhost to the server involves uploading and extracting them:

As above discussed we created a WordPress_transfer.zip file. Transfer the file with the SCP command:

scp wordpress_transfer.zip username@your_server_ip:/var/www/html
scp command

This command will upload the archive to /var/www/html directory on your Ubuntu Server.

Ubuntu server

After transferring extract the files on your server with the following command:

uzip wordpress_transfer.zip -C /var/www/html
unzip file

Compressing the files into an archive makes the upload process faster and more efficient. Extracting them on the server puts them in the right place for your web server to access.

Update wp-config.php

The wp-config.php file contains the configuration details needed for WordPress to connect to the database and work correctly:

Open wp-config.php in a text editor with the following command:

sudo nano /var/www/html/wordpress/wp-config.php

Update the database credentials:

define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_username');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');
wordpress database

Updating these details ensures WordPress can connect to the database you set up on the server making the transition seamless.

Set Up Permissions

Ensuring all files and directories have the correct permissions is vital for security and functionality:

sudo chown -R www-data:www-data /var/www/html/wordpress
sudo find /var/www/html/wordpress -type d -exec chmod 755 {} \; && sudo find /var/www/html/wordpress -type f -exec chmod 644 {} \;

Import Database

Now, you need to import the SQL file into the newly created database. Execute the following command to import the database.

mysql -u your_username -p wordpress < /path/to/database.sql
import sql file

This step inserts all the data and structure from your local database into the server’s database, making sure your site’s content and configuration are replicated exactly.

Finalize Migration

For Apache web servers, we need to create the virtual host. Execute the following command to create a new virtual host in your server.

sudo nano /etc/apache2/sites-available/example.conf

Change the following content in the file. Do not forget to replace the example data with the actual data depending on your site.

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName ultahosttest.com
    ServerAlias www.ultahosttest.com
    DocumentRoot /var/www/wordpress
    ErrorLog /var/log/apache2/example-error.log
    CustomLog /var/log/apache2/example-access.log combined
</VirtualHost>

Save the virtual host file. Then, execute the following command to enable the virtual hosts:

sudo service apache2 restart

It is important to note that your domain name points to the DNS of your Ubuntu server. Access your site via the server’s IP address or domain name to ensure everything works correctly.

Conclusion

Migrating a WordPress site from a localhost environment to an Ubuntu server requires a multi-step process. By following this comprehensive guide you ensure that all aspects of the migration are covered from preparing backups to configuring the server and finalizing the site settings.

Discover a seamless Ubuntu server that helps to install WordPress where reliability converges with security. Ultahost ensures efficient server management and dedicates resources to guarantee optimal speed and stability. Elevate your online presence with us.

FAQ

What does it mean to migrate a WordPress site?
Why should I migrate my WordPress site to an Ubuntu server?
What do I need to migrate WordPress to Ubuntu?
How do I move the WordPress database?
Will my website content be the same after migrating?
Can I use FTP to upload WordPress files to Ubuntu?
Do I need to change my WordPress settings after migration?

Related Post

No “Add New” button for themes an

The missing "Add New" button for themes or plugins is a...

How to Install and Setup WordPress Multisite

WordPress Multisite is a powerful feature that allows y...

How to Install TeamViewer on Ubuntu

TeamViewer is a popular remote desktop software that en...

How to Install PrestaShop on Ubuntu

PrestaShop is a popular, free, and open-source e-commer...

How to Install Apache on Ubuntu

Apache is a free and open-source web server the most po...

How to Install TYPO3 on Ubuntu 22.04

TYPO3 is a free and open-source content management syst...

Leave a Comment