LinuxTutorialsUbuntu

How To Install WordPress on Windows 10 WSL

Install WordPress on Windows 10 WSL

In this tutorial, we will show you how to install WordPress on Windows 10 WSL. For those of you who didn’t know, WordPress is the most popular content management system. You can host about anything on WordPress- from simple portfolio websites, company landing pages, and blogs to full-fledged eCommerce websites. It guarantees flexibility, robustness, and security, which are key for the success of any website.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of WSL 2 on Windows 10. You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.

Requirements

  • Windows 10 May 2020 (2004), Windows 10 May 2019 (1903), or Windows 10 November 2019 (1909) or later.
  • A computer with Hyper-V Virtualization support.

Install WordPress on Windows 10 WSL

Step 1. Enable the Windows Subsystem for Linux 2.

You must first enable the “Windows Subsystem for Linux” optional feature before installing any Linux distributions on Windows. Now run the following command below to enable it:

Open PowerShell as Administrator and run:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Step 2. Enable Virtual Machine Feature.

Before installing WSL 2, you must enable the Virtual Machine Platform optional feature. Your machine will require virtualization capabilities to use this feature.

To enable Virtual Machine Platform on Windows 10 (2004) open PowerShell as Administrator and run:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Step 3. Set WSL 2 as your default version.

We set WSL 2 as default. Now open PowerShell as Administrator and run this command to set WSL 2 as the default version of WSL:

wsl --set-default-version 2

Step 4. Installing Ubuntu Linux Distribution.

With WSL and the necessary virtualization tech all in place, all that is left for you to do is pick and install a Linux distro from the Microsoft Store. Several different distros are available, including OpenSUSE, Pengwin, Fedora Remix, and Alpine Linux.

To install Ubuntu on Windows 10 open the Microsoft Store app, search for “Ubuntu 20.04”, and hit the “Get” button:

Install WSL on Windows 10

Step 5. Installing Nginx on Windows WSL.

To install Nginx HTTP on your Ubuntu server, run the commands below:

sudo apt update
sudo apt install nginx

After successfully installed, run the commands below to stop and start Nginx services:

sudo service nginx stop
sudo service nginx start

Next, verify that the webserver is running and accessible by accessing your server’s IP address:

http://localhost

Install WordPress on Windows 10 WSL

Step 6. Installing MariaDB on Windows WSL.

Run the following command to install MariaDB:

sudo apt install mariadb-server mariadb-client

Once is done, run the commands below to stop, start and enable the MariaDB service to always start up with the server boots:

sudo service mysql stop
sudo service mysql start

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. You should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB.

mysql_secure_installation

Configure it like this:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

Log in to the database console using the commands below:

mysql -u root -p

Next, create a WordPress database:

CREATE DATABASE wpdb;
CREATE USER 'wpdbuser'@'localhost' IDENTIFIED BY 'your_strong_passwd';
GRANT ALL ON wpdb.* TO 'wpdbuser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Step 7. Installing PHP on Windows 10 WSL.

Now run the commands below to install PHP and modules to support WordPress:

sudo apt install php-fpm php-common php-mysql php-gmp php-curl php-intl php-mbstring php-xmlrpc php-gd php-xml php-cli php-zip

Next, run the command below to stop and start PHP7.4 services:

sudo service php7.4-fpm stop
sudo service php7.4-fpm start

Step 8. Installing WordPress on Windows 10 WSL.

Run the commands below to download the latest version of WordPress from the official website:

wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
sudo mv wordpress /var/www/wordpress

We will change the permissions directory:

sudo chown -R www-data:www-data /var/www/wordpress/
sudo chmod -R 755 /var/www/wordpress/

WordPress configurations are saved inside the wp-config.php file. A new WordPress installation comes with a sample config file that we can copy to the wp-config.php file. Enter the following command to copy this file:

mv /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php

Next, open the wp-config.php file in the nano editor using the following command:

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

Add the following line:

define(‘DB_NAME’, ‘wpdb’);
define(DB_USER’, ‘wpdbuser’);
define(DB_PASSWORD’, ‘your-strong-password’);

Step 9. Configure Nginx VirtualHost.

To configure Nginx for WordPress site, create a new configuration file named WordPress in the /etc/nginx/sites-available/ directory by running the commands below:

sudo nano /etc/nginx/sites-available/wordpress

Add the following line:

server {
    listen 80;
    listen [::]:80;
    root /var/www/wordpress;
    index  index.php index.html index.htm;
    server_name  your-domain.com www.your-domain.com;

    client_max_body_size 100M;
    autoindex off;
    
    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
    }
}

Save the file and exit, Also restart Nginx services:

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo service nginx restart

Step 10. Accessing WordPress Web Interface.

Once successfully complete installation, open your favorite web browser and browse to the server domain name:

http://your-domain.com

Congratulations! You have successfully installed WordPress on WSL 2. Thanks for using this tutorial for installing the latest stable version of the WordPress on Windows Subsystem for Linux 2 (WSL 2) on the Ubuntu 20.04 LTS  (Focal Fossa) system. For additional help or useful information, we recommend you check the official Ubuntu website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button