How to Install the LEMP Stack on Windows WSL
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.”

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 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:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestartIf you’re using Windows 10 version older than 2004, use this 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 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.

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 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:
sudo apt update
sudo apt upgrade
sudo apt autoremoveThe 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:
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 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:
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): 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:
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 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:
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 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:
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 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?
How do I enable WSL on Windows 10?
What are the system requirements to run WSL 2?
How can I set WSL 2 as the default version?
Can I run multiple Linux distributions on WSL?
Was this guide helpful?
Leave a Reply Cancel reply