WordPress Development for Windows with WSL (part 3): Migrating a WordPress site from WAMP/XAMPP to Ubuntu on WSL

Home / Web development / WordPress Development for Windows with WSL (part 3): Migrating a WordPress site from WAMP/XAMPP to Ubuntu on WSL

If you've made it this far, you've already completed the first two chapters on WordPress for Windows development guide with WSL. If you haven't done it yet, you're already late.

Let's take a recap of where we are:

  1. We have WSL installed and running
  2. We have installed an Apache server with PHP and MySQL/MariaDB.
  3. We have a WordPress site running on WAMP/XAMPP

Now it's time to migrate our sites from WAMP/XAMPP to the Ubuntu distribution, so let's get to it.

Migrate files

The first aspect we are going to look at is the migration of the code base of your WordPress site, that is, the PHP, Js, CSS, images, etc. files.

The most sensible thing to do at this point is to move the files to the folder you want within your WSL file system. To do this, follow the steps below:

  1. From the Ubuntu console, locate where your WAMP/XAMPP web site is and enter that directory. Remember that Windows drives are in /mnt/. For example, in my case the site was at /mnt/c/xampp/htdocs/www.
  2. Move the files to the desired Ubuntu folder. In this example we are going to move the files to /var/www/html/
cd /carpeta_donde_estan_tus_archivos/
sudo mv * /var/www/html/carpeta_de_destino/

Migrate the database

The easiest option to migrate the database is to log in through PHPMyAdmin and export the database. Once we have the SQL file, to simplify things, move your SQL file to the folder where your WordPress site is installed.

Then we can use WP-CLI to create the database and import our SQL file into the MySQL/MariaDB server we have in Ubuntu. If you want to import the database NOW, you must first create the database with MySQL:

mysql –u root –p

> CREATE DATABASE new_db_name;

> exit;

Subsequently, import the database with:

mysql –u username –p new_db_name < dump_file.sql

To do this with WP-CLI, first follow the steps in the next chapter: WordPress development for Windows with WSL (part 4): Integration of PHPStorm, Git, xDebug and WP-CLI

Then check that the database server access configuration you have in your wp-config.php corresponds to the correct Ubuntu configuration (username, password and server). In my case, in XAMPP I had the root user without password, but in Ubuntu it does have a password.

Once you have set the values in the wp-config.php file, you just need to access the folder where this file is located and launch the following WP-CLI commands:

wp db create
wp db import nombre_de_tu_base_de_datos.sql

Create a Virtual Host

In order to have different developments in their corresponding local domains, the most usual is to have different Virtual Hosts. In my case, for the site I'm migrating I have a Virtual Host in XAMPP with the following configuration:

    DocumentRoot /var/www/html/
    ServerName test-host.example.com
    ErrorLog "logs/test-host.example.com-error.log"
    CustomLog "logs/test-host.example.com-access.log" common

The only thing we would have to do at this point is to move this configuration to our Apache server in Ubuntu. To do this, from the Ubuntu console, we are going to create a new Virtual Host with the corresponding configuration. To do this, launch the following commands:

cd /etc/apache2/sites-available/
sudo cp 000-default.conf my-site.conf

We have already created the configuration file my-site.confso we just need to edit it with vim o nano and set up the DocumentRoot with the corresponding path to the XAMPP folder:

    DocumentRoot /var/www/html/
    ServerName test-host.example.com
    ErrorLog ${APACHE_LOG_DIR}/test-host.example.com.error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined                                 

After saving the file, we have to activate the new configuration with the following commands:

sudo a2ensite my-site.conf
sudo service apache2 reload

To test that everything is in order, turn OFF your WAMP/XAMPP server and visit the domain you have configured in your browser.

DISCLAIMER: something may fail, it may not work the first time, you may despair. Here is a checklist of possible points of failure that you can check:

  • Check that the Ubuntu servers are up. Remember, both the Apache and MySQL servers must be up for everything to work.
  • Check that the WAMP/XAMPP Apache and MySQL servers are turned off. If you have them mounted as Windows services, make sure those services are stopped.
  • Check your hosts file. At C:/Windows/system32/drivers/etc we found the file of hostsin which you should check that the domain you want to use is listed there and pointing to

In WSL2 it is important to add also the host resolution by IPV4:	test-host.example.com	
::1		test-host.example.com
  • Check your VirtualHost file. You may receive a 403 error code when visiting the web site. Add the following lines to your VirtualHost file:

	DocumentRoot /var/www/html/
        	DirectoryIndex index.php
	        AllowOverride All
        	Order allow,deny
	        Allow from all
	        Require all granted

If none of this works, and you keep running into problems, just remember: Google is your friend.

Continue reading the WordPress for Windows development guide with WSL and its chapter 4: WordPress Development for Windows with WSL (part 4): Git, PHPStorm, xDebug and WP-CLI Integration

<i class="fa fa-angle-up" aria-hidden="true"></i>