Pre-requisites:

  • WSL2 on Windows 10 or 11

On Linux sub-system:

  • Apache2
  • Mariadb / mysql
  • phpmyadmin

Here’s a step-by-step guide for starting a new WordPress website in your locahost environment in Windows 10/11 using WSL2.


STEP 1: Open WSL bash terminal

Quickest way to do this is hit Win/Start key > type “bash” > enter

STEP 2: Create new website directory

Enter the following:

(replacing <<newsite>> with whatever name you choose)

mkdir /var/www/<<newsite>>

STEP 3: Get latest wordpress

If you don’t already have a folder containing a version of wordpress you want to use, you’ll want to get the latest wordpress and extract it to a local folder (which will come in handy for future use)

If you don’t already have wget on your WSL, install it:

sudo apt install wget

Now, you need to enter the directory where you want your wordpress folder to reside. This can be wherever you want, but for convenience and easy copying to any new site you create, I would suggest /var/www/ is a good location:

cd /var/www/

Now, you can download the latest tar.gz archive from the WordPress server:

wget http://wordpress.org/latest.tar.gz

… and then extract the archive:

tar xfz latest.tar.gz

you will now have a folder named wordpress in your current location, containing all the files needed for a complete WordPress installation.

(If you want to keep things tidy and don’t feel you will need the original .tar.gz worpress archive you downloaded, feel free to delete it by entering: rm latest.tar.gz )

STEP 4: Copy WordPress files

Assuming you are in /var/www you can now copy your wordpress folder to your new site folder:

(replacing <<newsite>> with whatever name you chose in Step.2)

cp ./wordpress/. ./<<newsite>>

You should now have all the files you need for setting up a WordPress website on your localhost server, however they will not work without a database, so onwards to…

STEP 5: Create a new database

It is entirely possible to create a new database (and user) for your WordPress site without leaving the terminal using mariadb or mysql, however phpmyadmin is a little bit more user-friendly and graphically interactive, so we’ll use that.

Leave a Reply

Your email address will not be published. Required fields are marked *