How to Install the LEMP Stack on Windows WSL
You install the LEMP stack on Windows WSL by setting up Linux, Nginx, MySQL, and PHP within your Windows Subsystem for Linux environment.
LEMP is a popular web server stack, meaning it’s a group of software components that work together to power dynamic websites and applications. This tutorial specifically guides you through installing LEMP using Ubuntu 22.04 LTS on Windows 10 or 11.
This setup allows you to run robust web server technology directly on your Windows PC, leveraging the power of Linux distributions.
Install Ubuntu from the Microsoft Store, enable WSL and Virtual Machine Platform features in PowerShell, and set WSL 2 as the default. Run the command dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart in an administrator PowerShell.
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?
You can install the LEMP stack on Windows WSL to run Linux tools directly on your Windows PC. This lets web developers test websites in a Linux setup without leaving Windows, making it super handy.
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 1Enable WSL in Windows
To get the LEMP stack on Windows WSL working, you first need to turn on the Windows Subsystem for Linux. This feature lets Windows run Linux environments right alongside your Windows programs.
First, open PowerShell as an administrator. Click on Start and type “PowerShell.”
Right-click Windows PowerShell and choose “Run as administrator.”

Copy and paste this command into PowerShell:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestartYou should see a success message like this:
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 2Enable Virtual Machine Platform
For the LEMP stack on Windows WSL to run smoothly, you must turn on the Virtual Machine Platform feature. This is needed for WSL 2 to properly run Linux inside Windows.
WSL 2 needs the Virtual Machine Platform feature turned on. This is different from Hyper-V. Run this command in the same PowerShell window:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestartIf you’re on a Windows 10 version older than 2004, use this command instead:
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestartAfter 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:
wsl --set-default-version 2Step 3Install Ubuntu on 🪟 Windows 10
Now that WSL 2 is ready on your Windows computer, the next step for your LEMP stack is to install Ubuntu. You can get this popular Linux operating system straight from the Microsoft Store.
Get Ubuntu 20.04 LTS – Microsoft Store
Ubuntu 20.04 LTS gives you access to Ubuntu’s terminal and command line tools, such as bash (a command interpreter), ssh (for secure remote login), git (for version control), and apt (a package manager).

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:
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 --upgradableGreat! Ubuntu is now installed. If you have trouble, try these commands:
wsl --set-default-version 1
bcdedit /set hypervisorlaunchtype auto startNow you’re ready to install the rest of LEMP.
Step 4Update Ubuntu Linux
After installing Ubuntu for your LEMP stack on Windows WSL, it’s important to update your Linux system. This makes sure you have the newest software and security fixes installed.
The “L” in LEMP stands for Linux. You’ve installed Ubuntu, which is a popular Linux distribution (a version of an operating system), and now it’s time to update it to the latest version.
Run these commands:
sudo apt update
sudo apt upgrade
sudo apt autoremoveThe sudo command runs things with administrator access. Ubuntu will ask for your password.
Step 5Install Nginx Web Server
The ‘Nginx’ part of the LEMP stack is a fast web server. Installing it on your Windows WSL Ubuntu system lets you host websites right from your computer.
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:
sudo apt update
sudo apt install nginxWhat happens when you install Nginx? It becomes a web server that can display web pages on your computer.
Use these commands to control Nginx:
sudo service nginx stop
sudo service nginx start
sudo service nginx restartTo check if Nginx is working, open your web browser and go to:
http://localhostYou should see a test page that says “Welcome to nginx!”

Step 6Install MariaDB Database Server
To finish setting up the LEMP stack on Windows WSL, you need a database. Installing MariaDB on Ubuntu gives you a dependable and quick way to save your website’s data.
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:
sudo apt-get install mariadb-server mariadb-clientWhat happens when you install MariaDB? Your computer now has a database system that can store information for websites.
Use these commands to control MariaDB:
sudo service mysql stop
sudo service mysql start
sudo service mysql restartNext, secure your database by adding a password. Run this command:
sudo mysql_secure_installationAnswer the questions like this:
Enter current password for root (enter for none): 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:
sudo mysql -u root -pType your root password when asked. If you see this, MariaDB is installed correctly:
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 7Install PHP-FPM and Modules
PHP is the scripting language that makes websites dynamic. Installing PHP-FPM and its needed modules is a key step in setting up your LEMP stack on Windows WSL.
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:
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-zipWhat happens when you install PHP? Your web server can now run websites that use PHP code.
Use these commands to control PHP:
sudo service php7.4-fpm stop
sudo service php7.4-fpm start
sudo service php7.4-fpm restartTo check if PHP is installed, run:
php -vYou should see something like this:
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 TechnologiesStep 8Test PHP with Nginx
After installing all the parts for the LEMP stack on Windows WSL, you should test that PHP works correctly with Nginx. You can do this by making a simple test file.
Now let’s create a test file to make sure PHP and Nginx work together.
Run this command to create a PHP test file:
sudo nano /var/www/html/phpinfo.phpType this content:
<?php phpinfo( ); ?>Save the file by pressing Ctrl+X, then Y, then Enter.
Next, edit the Nginx settings. Run this command:
sudo nano /etc/nginx/sites-available/defaultFind and uncomment these lines (remove the # symbols):
# 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:
sudo service nginx restartOpen your web browser and go to:
http://localhost/phpinfo.phpYou should see the PHP information page. This proves that PHP and Nginx are working together!

Summary
You’ve now successfully set up the full LEMP stack on Windows 10 using WSL 2 and Ubuntu. This gives you a powerful Linux setup for web development right on your Windows computer.
- 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!
How to install WSL file in Windows?
And run the command wsl-to. This lists all the Windows subsystem for Linux distros. I can in install directly from the command.
Was this guide helpful?
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.
No comments yet — be the first to share your thoughts!