How to Install the LEMP Stack on Windows WSL
The LEMP stack (a bundle of Linux, Nginx, MySQL, and PHP) lets you host and test dynamic websites right on your Windows 11 PC using the Windows Subsystem for Linux (WSL). (Windows 10 reached end of support on October 14, 2025.)
Running this web server setup inside Ubuntu 24.04 LTS gives you a real Linux environment without needing a separate computer or a dual-boot setup. You get the speed and tools of a Linux web server while staying on your familiar Windows desktop.
To install the LEMP stack on Windows WSL, first install Ubuntu 24.04 LTS by running wsl –install in an administrator terminal and restarting when prompted. Then update Ubuntu and install Nginx, MariaDB or MySQL, and PHP-FPM with apt. Nginx, MariaDB and PHP-FPM run inside Ubuntu, so you test sites at localhost.
What is LEMP?
LEMP stands for Linux (Ubuntu), Nginx HTTP Server, MariaDB or MySQL Database Server, and PHP Scripting Language. These free, open-source programs work together to power websites and content management systems like WordPress.
Why Install LEMP on Windows?
Installing the LEMP stack in WSL lets you run Linux web development tools on your Windows computer without dual-booting. It gives you a reliable local setup to build and test websites before you put them on a real server.
WSL 2 runs significantly faster than the original WSL architecture. It runs a complete Linux operating system inside Windows.
What You Need
You need a current version of Windows 11 (24H2 or 25H2). WSL works on both Home and Pro editions, so you don’t need Pro for this guide.
Two things must be in place before WSL 2 will work:
- Hardware virtualization must be enabled in your BIOS/UEFI. To check, open Task Manager , go to the Performance tab, select CPU, and look for “Virtualization: Enabled”. If it says Disabled, turn on the virtualization option (often called Intel VT-x, AMD-V or SVM Mode) in your BIOS/UEFI settings.
- You must restart Windows after enabling the WSL features. Until you restart, WSL 2 won’t start.
The quickest way to get going on current Windows 11 is a single command. Open a terminal as administrator and run wsl –install. This one command turns on the required Windows features, installs WSL 2 and installs Ubuntu as the default distribution. It replaces the DISM commands, the Microsoft Store download and the default-version setting in the next sections. Restart when prompted, then launch Ubuntu and create your username and password. After that you can skip ahead to updating Ubuntu.
The manual steps below still work. Use them if you prefer to control each stage or if the single command fails on your machine.
Current WSL distributions, including Ubuntu 24.04, enable systemd by default. That means you can manage services with systemctl, for example sudo systemctl status nginx. The WSL virtual machine shuts down when you close all terminals for a while or run a WSL shutdown. After a restart, Nginx, MariaDB and PHP-FPM may not be running. If a page won’t load, check the service status and start the service again. You’ll see the control commands for each service later in this guide.
Step 1Enable WSL in Windows
Enabling the Windows Subsystem for Linux (WSL) lets your Windows computer run a full Linux environment alongside your regular apps. You must turn on this built-in feature before you can install any Linux distributions or set up your web development tools. This section is the manual route, so skip it if you already ran the single install command.
- Click Start and type “PowerShell”.
- Right-click Windows PowerShell and choose Run as administrator. Click Yes if Windows asks for permission. The window title should now start with “Administrator”.

- Copy and paste this command into the PowerShell window and press Enter:
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
The Virtual Machine Platform feature gives WSL 2 the core components it needs to run Linux distributions. You must turn it on before you can install Ubuntu. This feature is separate from Hyper-V, and Windows 11 Home can use it.
- Stay in the same administrator PowerShell window.
- Run this command and wait for the success message:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestartIf you’re on a Windows 10 version older than 2004, use this command instead. It doesn’t apply to Windows 11:
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart- Restart your computer. The restart is required: the new features don’t take effect until Windows reboots, and WSL 2 won’t run without it.
- After the restart, open PowerShell as administrator again.
- Run the command wsl –set-default-version 2 to make WSL 2 your default version. Every distribution you install from now on will use WSL 2.
If you get a message that WSL 2 requires an update or that virtualization isn’t enabled, go back to the BIOS/UEFI check above.
wsl --set-default-version 2Step 3Install Ubuntu on 🪟 Windows 10
Ubuntu is the Linux environment that will run your web server. It gives you terminal tools like Bash and Apt, which make downloading and managing server software straightforward. If you used the single install command, Ubuntu is already installed and you can launch it from the Start menu .
Get Ubuntu 24.04 LTS – Microsoft Store (or run: wsl –install -d Ubuntu)
Ubuntu gives you access to essential terminal tools like Bash, SSH, and Apt.

- Open the Ubuntu page in the Microsoft Store using the link above.
- Click the Get button. The download typically takes about 5 minutes. When it finishes, the button changes so you can open the app.
- Launch Ubuntu from the Start menu . The first launch takes a minute or two while it unpacks.
- When prompted, create a username and password. You need them to log in and to run administrative commands in Ubuntu. The password doesn’t show characters as you type, which is normal.
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 22.04 LTS (GNU/Linux 5.15.90.1-microsoft-standard-WSL2 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 --upgradableUbuntu 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
Updating your Linux packages makes sure Ubuntu has the latest security patches and bug fixes before you install server software. The “L” in LEMP stands for Linux. You’ve installed Ubuntu, so the next job is bringing it up to date.
- Open your Ubuntu terminal.
- Run these commands. The update can take a few minutes the first time:
sudo apt update
sudo apt upgrade
sudo apt autoremoveThe sudo command runs things with administrator access. Ubuntu will ask for the password you created earlier, and you’ll need to enter it again after a period of inactivity.
Step 5Install Nginx Web Server
Nginx is the high-performance web server that provides the “E” in LEMP (pronounced “engine x”). It handles incoming web traffic and serves your website files from your local Windows computer.
- In the Ubuntu terminal, install Nginx with sudo apt install nginx. Type y and press Enter if Apt asks you to confirm.
- Run these commands to install Nginx:
When you install Nginx, it becomes a web server that can display web pages on your computer. For example, Nginx can serve a basic HTML file located at `/var/www/html/index.html` to anyone who visits your IP address.
Use these commands to control Nginx. With systemd enabled, you can also use sudo systemctl start nginx or sudo systemctl status nginx. If you restart WSL and Nginx isn't running, start it again with one of these.
sudo service nginx stop
sudo service nginx start
sudo service nginx restartTo check that Nginx is working, open your web browser and go to:
http://localhostYou should see a test page that says "Welcome to nginx!" If the page doesn't load, check that Nginx is running with the control commands above.

Step 6Install MariaDB Database Server
MariaDB is the database server that stores your website data, and it provides the "M" in LEMP. It manages everything from user accounts to site content so your dynamic web applications can save and retrieve information. MariaDB is a free, open-source database known for its speed and security, and most Linux systems use it as a drop-in replacement for MySQL.
Run these commands to install MariaDB:
sudo apt-get install mariadb-server mariadb-clientWhen the install finishes, your computer has a database system that can store information for websites.
Use these commands to control MariaDB. As with Nginx, if the database isn't running after a WSL restart, start it again with sudo systemctl start mariadb.
sudo service mysql stop
sudo service mysql start
sudo service mysql restartNext, secure your database by setting a root 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 that 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.6.12-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.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 provides the "P" in LEMP. It's the programming language that makes websites dynamic, and PHP-FPM is the service that processes your PHP code and hands the results back to Nginx. PHP also talks to MariaDB, so it connects 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 php-mbstring php-xmlrpc php-gd php-xml php-cli php-zipWhen it finishes, your web server can run websites that use PHP code.
Use these commands to control PHP. PHP-FPM is also a service, so after a WSL restart it may need to be started again with systemctl, just like Nginx and MariaDB.
sudo service php8.3-fpm stop
sudo service php8.3-fpm start
sudo service php8.3-fpm restartTo check that PHP is installed, run:
php -vYou should see something like this:
PHP 8.3.6 (cli) (built: Mar 19 2025 10:08:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
with Zend OPcache v8.3.6, Copyright (c), by Zend TechnologiesStep 8Test PHP with Nginx
Testing PHP with Nginx confirms that your web server and scripting language are talking to each other. A simple test file lets you verify that the local environment works before you start building your site.
Delete it as soon as you've finished testing. Don't leave it in place, and never copy it to a live server.
- Run this command to create a PHP test file:
sudo nano /var/www/html/phpinfo.php- Type this content into the file:
<?php phpinfo( ); ?>- Save the file by pressing Ctrl+X, then Y, then Enter.
Before you edit the Nginx settings, make a backup of the default site file, /etc/nginx/sites-available/default. Copy it to a new name such as default.bak with the cp command. If a typo stops Nginx from starting, copy the backup back over the original to undo your changes.
- Edit the Nginx settings with this command:
sudo nano /etc/nginx/sites-available/default- Find and uncomment these lines by removing the # symbols. Make sure the PHP version in the socket path matches the version you installed:
# 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/php8.3-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 {
# deny all;
#}
}- Save the file, then restart Nginx:
sudo service nginx restart- Open your web browser and go to http://localhost/phpinfo.php:
The PHP information page confirms that PHP and Nginx are now working together correctly. You can verify this by opening the page in your web browser, which displays details about your PHP installation.
You should see the PHP information page with the PHP version and a table of settings. If you get a 404 error or a download prompt instead, recheck the lines you uncommented and make sure Nginx and PHP-FPM are both running.
Once the page loads, delete phpinfo.php. On Ubuntu, Nginx serves files from /var/www/html by default, so remove the file from wherever you created it, for example with sudo rm followed by the file's full path.

Summary
Setting up the full LEMP stack on Windows using WSL 2 and Ubuntu gives you a powerful, local Linux environment for web development. You now have Nginx serving web pages, MariaDB managing databases, and PHP running dynamic site code.
- Enabled WSL 2 on Windows
- Installed Ubuntu 24.04 LTS 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 the tools you need to build and test websites locally before putting them on the internet.
If you run into problems, check the troubleshooting commands earlier in this guide. If a page stops loading after a restart, check first that Nginx, MariaDB and PHP-FPM are running.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!