How to Install LAMP with WSL on Windows 11

template 1599663 640
template 1599663 640

This brief tutorial shows students and new users how to install the LAMP stack in Windows 11 using Windows Subsystem for Linux 2 (WSL2).

You can now install and run Linux servers and services on directly from a Windows desktop or server via Windows Subsystem for Linux (WSL) without installing third-party apps or using virtual machines. In 2017, Microsoft released WSL and WSL2 which lets developers run a GNU/Linux environment, including most command-line tools, utilities, and applications directly in Windows without setting up a virtual machine or dual-boot.

WSL2 is the new and improved version that comes with a performance boost, and full system call compatibility, and it is built with a new architecture that delivers features that make WSL an amazing way to run a Linux environment in Windows.

If you need to run the LAMP stack to run servers and services built for Linux, you can do it directly from Windows 11. The steps below show you how to install and configure it all without too much fuss. WSL and 2 are a bit different than Windows 10, but we show you how to do that.

To install and run the LAMP stack on Windows 11 you must first install and enable WSL.

Install Windows Subsystem for Linux in Windows 11

To enable WSL in Windows, you will want to open the Command Prompt as administrator. Click on Start then begin typing Command Prompt.

Next, right-click Command Prompt app and choose to Run as administrator.

When the console opens, run the commands below to install Windows Subsystem for Linux (WSL):

wsl --install

Wait for WSL to be installed.

After installing, you should get a success message similar to the lines below:

Installing: Virtual Machine Platform
Virtual Machine Platform has been installed.
Installing: Windows Subsystem for Linux
Windows Subsystem for Linux has been installed.
Downloading: WSL Kernel
Installing: WSL Kernel
WSL Kernel has been installed.
Downloading: GUI App Support
Installing: GUI App Support
GUI App Support has been installed.
Downloading: Ubuntu
The requested operation is successful. Changes will not be effective until the system is rebooted.

Restart your computer.

WSL should be installed and ready to use. When you want to update, simply run the commands below:

wsl --update

Install Specific Linux distro on Windows 11

Now that WSL is installed, you can install your own Linux distro. To list the available distributions to install, simply run the commands below:

wsl --list --online

You should then see all available distributions that can be installed on WSL.

Ubuntu          Ubuntu
Debian          Debian GNU/Linux
kali-linux      Kali Linux Rolling
openSUSE-42     openSUSE Leap 42
SLES-12         SUSE Linux Enterprise Server v12
Ubuntu-16.04    Ubuntu 16.04 LTS
Ubuntu-18.04    Ubuntu 18.04 LTS
Ubuntu-20.04    Ubuntu 20.04 LTS

To install a Linux distribution from the list above, simply run the commands below using the distribution name. For example, to install Ubuntu 20.04, run the commands below:

wsl --install -d ubuntu-20.04

You should then get a message that the distribution is installed.

Downloading: Ubuntu 20.04 LTS
Installing: Ubuntu 20.04 LTS
Ubuntu 20.04 LTS has been installed.
Launching Ubuntu 20.04 LTS.

After installing, you should get a Ubuntu command console with setup details.

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:
Enter new UNIX username: Richard
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 LTS (GNU/Linux 4.4.0-22000-Microsoft x86_64)

Some troubleshooting commands to run when you run into issues.

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

Now that Ubuntu Linux is installed and ready to use, continue below to install the LAMP stack on Windows 11. First, install Apache HTTP Server.

Install Apache HTTP Server

Apache is a core component of the LAMP stack, and one of the most popular open-source web servers available today.

To install Apache on Ubuntu, run the commands below:

sudo apt update
sudo apt install apache2

After installing Apache, the commands below can be used to stop and start Apache services.

sudo service apache2 stop
sudo service apache2 start

To test whether Apache is installed and functioning, open your web browser and browse to the server’s IP address or hostname.


If you see the above page in your browser, then Apache is working as expected.

Install MariaDB Server

MySQL or MariaDB is another core component of the LAMP stack.

A truly open-source database server that you can use with your open-source project is the MariaDB database server. It is fast, secure and the default server for almost all Linux servers.

To install MariaDB, run the commands below:

sudo apt install mariadb-server mariadb-client

After installing MariaDB, the commands below can stop, start and enable the MariaDB service to start up when the server boots.

sudo service mysql stop
sudo service mysql start

Next, run the commands below to secure the database server with a root password if you were not prompted to do so during the installation.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat 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 verify and validate that MariaDB is installed and working, log in to the database console using the commands below:

sudo mysql -u root -p

type the root password when prompted.

mariadb welcome

The server was successfully installed if you see a similar screen as shown above.

Install PHP and Related Modules

PHP is a script that glues all the LAMP components together and requires for PHP-based apps. Run the commands below to install PHP and related modules to support most PHP-based apps.

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-zip

After installing PHP, go and configure some basic settings that may be required for your PHP project to function properly.

For this tutorial, PHP 7.4 was installed. Based on your environment, another version of PHP might be installed. So verify that.

sudo nano /etc/php/7.4/apache2/php.ini

Below are good settings to configure for most PHP apps.

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

That should get PHP 7.4 installed with some basic settings to allow many PHP apps to run and function.

After setting up PHP, restart Apache services to the settings to apply.

sudo service apache2 stop
sudo service apache2 start

That’s it! You’ve learned how to install the LAMP stack on Windows 11 with WSL support.


This post showed you how to install the LAMP stack with WSL 2 on Windows 11. If you find any error, please use the comment form below to report.

Posted by
Richard W

I love computers; maybe way too much. What I learned I try to share at


  1. I’m running WSL2 on a Windows 11 PC. I’m always running into this error when I try to initialize MySQL after installing it:
    Error 2002 can’t connect to local mysql server through socket ‘/var/run/mysqld/mysqld.sock

    1. try install windows 11, not upgraded from 10

  2. The file ‘sudo nano /etc/php/7.4/apache2/php.ini’ doesn’t exist. Nor does the directory /etc/php/7.4/apache2.

    I do see a php.ini file at /etc/php/7.4/cli/php.ini though. Should I edit that file instead?

    1. Localhost displays my index file, but not PHP code within it.

      1. Had to uninstall PHP, and re-install using ‘sudo apt-get install php’. Works perfectly now.

  3. Where/how do you put your actual php and html files to use with this? Is there a folder on the main drive that contains the code? Is there a www or htdocs folder somewhere?

  4. Why I must set “sudo” when connecting to mysql. Like sudo mysql -u root -p
    When I don’t sudo command, i get an error
    => ERROR 2002 (HY000): Can’t connect to local server through socket ‘/run/mysqld/mysqld.sock’ (13)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: