Windows

How to Install the LEMP Stack on Windows WSL

Richard
Written by
Richard
May 31, 2021 Updated Apr 1, 2026 8 min read

This tutorial shows you how to install the LEMP stack on Windows 10 WSL (Windows Subsystem for Linux) 2 with Ubuntu OS. Don’t worry if that sounds technical—we’ll break it down into simple steps.

What is LEMP?

LEMP is short for Linux (Ubuntu), Nginx [engine x] HTTP Server, MariaDB or MySQL Database Server, and PHP Scripting Language. These are free, open-source programs that work together. They power many websites and content management systems (CMS) like WordPress today.

Why Install LEMP on Windows?

Installing LEMP on Windows WSL lets you use Linux tools on your Windows computer. This is especially helpful for web developers who need to test websites on a Linux system without leaving Windows.

WSL 2 is the newest version. It runs faster and works better than the old version. It lets you run a complete Linux operating system inside Windows.

What You Need

You’ll need Windows 10 version 2004 or newer. If you have that, you’re ready to start.

Step 1: Enable WSL in Windows

⚠️ Admin privileges required

First, open PowerShell as an administrator. Click on Start and type “PowerShell.”

Right-click Windows PowerShell and choose “Run as administrator.”

PowerShell terminal opened as administrator for WSL setup

Copy and paste this command into PowerShell:

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

You should see a success message like this:

💻Code
Deployment Image Servicing and Management tool
Version: 10.0.19041.844

Image Version: 10.0.19042.844

Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.

Step 2: Enable Virtual Machine Platform

⚠️ Admin privileges required

WSL 2 needs the Virtual Machine Platform feature turned on. This is different from Hyper-V. Run this command in the same PowerShell window:

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

If you’re using Windows 10 version older than 2004, use this instead:

💻Code
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart

After running the command, restart your computer. This lets all the changes take effect.

After restarting, open PowerShell as administrator again. Run this command to set WSL 2 as your default version:

💻Code
wsl --set-default-version 2

Step 3: Install Ubuntu on Windows 10

Now that WSL 2 is ready, you need to install Ubuntu. Click the link below to download Ubuntu 20.04 from the Windows Store.

Get Ubuntu 20.04 LTS – Microsoft Store

Ubuntu 20.04 LTS gives you Ubuntu’s terminal and command line tools like bash, ssh, git, apt, and more.

Installing Ubuntu on Windows WSL for LEMP stack

Click the “Get” button and wait for it to install. When done, you can launch Ubuntu from WSL.

When you first launch Ubuntu, it will ask you to create a username and password. Here’s an example:

💻Code
Installing, this may take a few minutes.
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: user1
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 4.4.0-19041-Microsoft x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Apr 12 17:57:37 CDT 2021

  System load:    0.52      Processes:             7
  Usage of /home: unknown   Users logged in:       0
  Memory usage:   26%       IPv4 address for eth0: 192.168.1.100
  Swap usage:     0%

1 update can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable

Great! Ubuntu is now installed. If you have trouble, try these commands:

💻Code
wsl --set-default-version 1
bcdedit /set hypervisorlaunchtype auto start

Now you’re ready to install the rest of LEMP.

Step 4: Update Ubuntu Linux

⚠️ Admin privileges required (use sudo)

The “L” in LEMP stands for Linux. You’ve installed Ubuntu, which is a type of Linux. Now let’s update it to the latest version.

Run these commands:

🐧Bash / Shell
sudo apt update
sudo apt upgrade
sudo apt autoremove

The sudo command runs things with administrator access. Ubuntu will ask for your password.

Step 5: Install Nginx Web Server

⚠️ Admin privileges required (use sudo)

The “E” in LEMP stands for Nginx [engine x]. Nginx is a fast, popular web server that powers many websites.

Run these commands to install Nginx:

🐧Bash / Shell
sudo apt update
sudo apt install nginx

What happens when you install Nginx? It becomes a web server that can display web pages on your computer.

Use these commands to control Nginx:

🐧Bash / Shell
sudo service nginx stop
sudo service nginx start
sudo service nginx restart

To check if Nginx is working, open your web browser and go to:

💻Code
http://localhost

You should see a test page that says “Welcome to nginx!”

Windows WSL with Ubuntu during LEMP installation process

Step 6: Install MariaDB Database Server

⚠️ Admin privileges required (use sudo)

The “M” in LEMP stands for MySQL or MariaDB. These are database servers that store data for your websites.

MariaDB is a free, open-source database that’s fast and secure. Most Linux systems use it.

Run these commands to install MariaDB:

🐧Bash / Shell
sudo apt-get install mariadb-server mariadb-client

What happens when you install MariaDB? Your computer now has a database system that can store information for websites.

Use these commands to control MariaDB:

🐧Bash / Shell
sudo service mysql stop
sudo service mysql start
sudo service mysql restart

Next, secure your database by adding a password. Run this command:

🐧Bash / Shell
sudo mysql_secure_installation

Answer the questions like this:

Enter current password for root (enter for none): Just press Enter

Set root password? [Y/n]: Y

New password: Type a strong password

Re-enter new password: Type it again

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

To check if MariaDB is working, log into the database. Run this command:

🐧Bash / Shell
sudo mysql -u root -p

Type your root password when asked. If you see this, MariaDB is installed correctly:

💻Code
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 46
Server version: 10.3.29-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

Type exit to leave the database.

Step 7: Install PHP-FPM and Modules

⚠️ Admin privileges required (use sudo)

The “P” in LEMP stands for PHP. PHP is a programming language that makes websites work. It connects all the parts of LEMP together.

Run this command to install PHP and helpful add-ons:

🐧Bash / Shell
sudo apt install php-fpm php-common php-mysql php-gmp php-curl php-intl php7.4-mbstring php-xmlrpc php-gd php-xml php-cli php-zip

What happens when you install PHP? Your web server can now run websites that use PHP code.

Use these commands to control PHP:

🐧Bash / Shell
sudo service php7.4-fpm stop
sudo service php7.4-fpm start
sudo service php7.4-fpm restart

To check if PHP is installed, run:

🐘PHP
php -v

You should see something like this:

🐘PHP
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Step 8: Test PHP with Nginx

⚠️ Admin privileges required (use sudo)

Now let’s create a test file to make sure PHP and Nginx work together.

Run this command to create a PHP test file:

🐧Bash / Shell
sudo nano /var/www/html/phpinfo.php

Type this content:

🐘PHP
<?php phpinfo( ); ?>

Save the file by pressing Ctrl+X, then Y, then Enter.

Next, edit the Nginx settings. Run this command:

🐧Bash / Shell
sudo nano /etc/nginx/sites-available/default

Find and uncomment these lines (remove the # symbols):

🐘PHP
# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        location ~ .php$ {
               include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
}

Save the file. Then restart Nginx:

🐧Bash / Shell
sudo service nginx restart

Open your web browser and go to:

🐘PHP
http://localhost/phpinfo.php

You should see the PHP information page. This proves that PHP and Nginx are working together!

Configuring PHP setup in Ubuntu for LEMP on WSL

Summary

You’ve successfully installed the complete LEMP stack on Windows 10 using WSL 2 and Ubuntu. Here’s what you did:

  • Enabled WSL 2 on Windows
  • Installed Ubuntu 20.04 inside WSL
  • Installed Nginx web server
  • Installed MariaDB database
  • Installed PHP scripting language
  • Tested that everything works together

Your Windows computer now has a complete Linux environment with all the tools needed to build and test websites. You can use this setup to develop websites locally before putting them on the internet.

If you run into any problems, check the troubleshooting commands earlier in this guide. Good luck with your web development!

Frequently Asked Questions

What is the LEMP stack and why should I use it?

LEMP stands for Linux, Nginx, MariaDB/MySQL, and PHP. It's a powerful combination of open-source software that allows you to run web applications and content management systems efficiently on a Linux environment, which can be easily set up on Windows using WSL.

How do I enable WSL on Windows 10?

To enable WSL, open PowerShell as an administrator and run the command 'dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart'. After executing the command, restart your computer to apply the changes.

What are the system requirements to run WSL 2?

To run WSL 2, you need Windows 10 version 2004 or higher, with the Virtual Machine Platform feature enabled. Additionally, your system should support virtualization in the BIOS settings.

How can I set WSL 2 as the default version?

After enabling WSL and restarting your computer, open PowerShell as an administrator and run the command 'wsl --set-default-version 2'. This will configure WSL 2 as your default version for any new Linux installations.

Can I run multiple Linux distributions on WSL?

Yes, you can install and run multiple Linux distributions on WSL. Each distribution can be managed separately, allowing you to use different environments for various projects or purposes.

Was this guide helpful?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

Leave a Reply

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

Exit mobile version