How to Install the LAMP Stack on Windows WSL
Installing the LAMP stack on Windows 10 WSL 2 with Ubuntu creates a full Linux web development setup right inside Windows.
The LAMP stack stands for Linux, Apache web server, MariaDB (a type of database), and PHP (a programming language). This group of free software is essential for building websites that change and update content, like blogs or online stores.
Setting up LAMP on WSL 2 gives your web projects performance that’s almost as good as on a native Linux computer. You can build and test websites directly on your Windows machine without having to restart your computer into Linux.
This method is perfect if you need Linux tools for development or want to run web applications on your Windows PC effectively.
Install LAMP on Windows WSL by first enabling WSL and Virtual Machine Platform in Windows PowerShell as administrator. Then, install Ubuntu from the Microsoft Store, update it with `sudo apt update`, and install Apache, MariaDB, and PHP using `apt install`.
How to Install LAMP Stack on Windows WSL
Step 1Enable WSL in Windows
To run Linux tools on Windows, you first need to enable the Windows Subsystem for Linux (WSL). This lets you install and use Linux systems directly on your computer. You can turn on WSL by opening PowerShell as an administrator and running a simple command.
To enable WSL in Windows, open the PowerShell terminal as administrator. Click on Start, then type PowerShell.
Right-click the Windows PowerShell app and choose “Run as administrator”.

When the console opens, run this command:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestartYou should see a success message saying the operation completed successfully.
Step 2Enable Virtual Machine Platform
For the newer WSL 2 version to work, you must enable the Virtual Machine Platform feature in Windows. This is a necessary step done from the same administrator PowerShell window. Running a specific command activates this Windows feature, which is required for WSL 2.
The Windows 10 Virtual Machine Platform must be enabled for WSL 2 to function. Run the command `Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All` from the same PowerShell administrator console to enable this feature.
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestartIf you’re using Windows 10 version lower than 2004, use this command instead:
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestartAfter restarting, log back in and launch PowerShell as administrator. Then run this command to set WSL 2 as the default version:
wsl --set-default-version 2Step 3Install Ubuntu on 🪟 Windows 10
After setting up WSL 2, the next step for your LAMP stack on WSL is installing Ubuntu. Ubuntu is a popular Linux operating system you can easily get from the Windows Store. Installing Ubuntu 20.04 LTS from the Microsoft Store lets you start using Linux command line tools on Windows.
Get Ubuntu 20.04 LTS – Microsoft Store
Ubuntu 20.04 LTS on Windows lets you use the Ubuntu Terminal and run Linux command line tools like bash, ssh, git, apt, and many more.

Click the Get button and install it. After installing Ubuntu, you’ll be able to launch it from the Windows WSL environment.
When you launch Ubuntu, the Linux operating system, it will prompt you to create a user account. This user account setup process, which establishes your identity within Ubuntu, may take a few minutes to complete.
Here’s what you’ll see:
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/support
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 --upgradableThat’s it! If you run into issues, try these troubleshooting commands:
wsl --set-default-version 1
bcdedit /set hypervisorlaunchtype auto startNow you’re ready to install Apache, MariaDB, and PHP.
Step 4Prepare Ubuntu Linux
Ubuntu is now installed inside Windows WSL. Update it using these commands:
sudo apt update
sudo apt upgrade
sudo apt autoremoveThese commands help manage and update your Ubuntu operating system.
Step 5Install Apache HTTP Server
Installing the Apache web server is a key part of setting up your LAMP stack on WSL. You can add Apache to your Ubuntu system using its package manager with simple commands in the terminal. Running `sudo apt update` and `sudo apt install apache2` will get your web server ready for websites.
To install Apache on Ubuntu, run these commands:
sudo apt update
sudo apt install apache2After installing Apache2, use these commands to stop, start, and restart Apache:
sudo service apache2 stop
sudo service apache2 start
sudo service apache2 restartTo check that Apache is working, open your web browser and go to:
http://localhostYou should see a test page if everything works.

Step 6Install MariaDB Database Server
Next for your LAMP stack on WSL is installing MariaDB, a popular and secure database server. You can add MariaDB to your Ubuntu system using simple commands in the terminal. Running `sudo apt-get install mariadb-server mariadb-client` is essential for storing your website data.
To install MariaDB, run these commands:
sudo apt-get install mariadb-server mariadb-clientAfter installing MariaDB, use these commands to stop, start, and restart the database:
sudo service mysql stop
sudo service mysql start
sudo service mysql restartsudo 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: Enter your password
- Re-enter new password: Repeat your password
- 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 in using this command:
sudo mysql -u root -pType your root password when asked. You should see:
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)]>If you see this, MariaDB installed successfully.
Step 7Install PHP and Related Modules
To finish setting up your LAMP stack on WSL, you need to install PHP. PHP is the programming language that makes websites interactive. You’ll also install helpful PHP modules using a single command in your Ubuntu terminal. Running `sudo apt install php libapache2-mod-php php-common php-mysql php-gmp php-curl php-i` gets everything working.
To install PHP and useful modules, run this command:
sudo apt install php libapache2-mod-php php-common php-mysql php-gmp php-curl php-intl php7.4-mbstring php-xmlrpc php-gd php-xml php-cli php-zipTo check that PHP is installed, run:
php -vYou should see something like:
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 TechnologiesYou can also test PHP by creating a test file. Run this command:
sudo nano /var/www/html/phpinfo.phpType this content and save the file:
<?php phpinfo( ); ?>Restart Apache with:
sudo service apache2 restartThen open your browser and go to:
http://localhost/phpinfo.phpYou should see the PHP information page.

Summary
You have successfully installed the LAMP stack on Windows WSL. This setup includes Linux (Ubuntu), Apache web server, MariaDB database, and PHP. You’ve enabled WSL 2 on Windows, installed Ubuntu from the Store, and updated it. This gives you a complete environment for building and testing websites right on your PC.
- Enabled WSL 2 on Windows with PowerShell
- Installed Ubuntu 20.04 from the Windows Store
- Updated Ubuntu with the latest packages
- Installed Apache web server
- Installed MariaDB database server and secured it
- Installed PHP and important modules
Your LAMP stack is now ready to use for web development and testing on your local Windows machine. If you run into any issues, check the troubleshooting commands above or leave a comment below.
How to install something on WSL?
And D for distribution. And then the distribution. And in this case I want to go ahead and grab Debian. So let's hit Enter.
How to install lamp stack on almalinux 9?
Install Apache Web Server First, we will start by installing the Apache web server. To complete the installation, use the following command. Once the installation is complete, enable Apache (to start automatically upon system boot), start the web server and verify the status using the commands below.
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.
Thanks for this guide, this exactly what I was looking for.
One more thing: after installing php you will need to restart the apache2 service.
Excellent material, this and other online tutorials, where very detailed.
Good until the very end. Example.com? Are you serious? Exactly how does one set that up? It’s one thing to just install all of these components; anyone with 2 brain cells can figure that part out. Without initial setup that at least explains how to launch a PHP page on localhost and connect to the Database, what value does any of this have? Nothing. What a waste of time.