This project is intended to guide the developer through the installation, configuration and workflow optimization of a LAMP Stack that is targeted on Windows 11 (and also on Windows 10, see below), with WSL2 and Ubuntu 24.04, with a LAMP Stack implemented via native systemd services instead of containers/virtualization.
In a hurry? Skip to the Automated Installation instructions!
During my years of on-field experience, I've created my own workflow that allows a developer to:
Anyways, this guide is not intended to force you to use native WSL Ubuntu systemd services. If you want to use Docker, you can (see here). The automated installer will ask you if you want to install Docker, and if you agree, it will install Docker Desktop for Windows, and you'll be able to use Docker as you would, with all the benefits of using it inside the WSL2 subsystem. In fact, as stated on the official Docker Documentation:
Docker Desktop WSL 2 backend on Windows Windows Subsystem for Linux (WSL) 2 is a full Linux kernel built by Microsoft, which lets Linux distributions run without managing virtual machines. With Docker Desktop running on WSL2, users can leverage Linux workspaces and avoid maintaining both Linux and Windows build scripts. In addition, WSL2 provides improvements to file system sharing and boot time. Docker Desktop uses the dynamic memory allocation feature in WSL2 to improve the resource consumption. This means Docker Desktop only uses the required amount of CPU and memory resources it needs, while allowing CPU and memory-intensive tasks such as building a container, to run much faster. Additionally, with WSL2, the time required to start a Docker daemon after a cold start is significantly faster.
Docker Desktop for Windows can be installed at any time. If you enable WSL2 after having Docker Desktop installed, you can still use Docker Desktop with WSL2, as it will automatically detect the WSL2 VM and use it as the backend (not personally tested, maybe it's only a matter of enabling the Use WSL 2 based engine option in the General settings of Docker Desktop).
TL;DR : PHP 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3 and 8.4, Apache 2.4, MariaDB 11.4, PostgreSQL 16
The LAMP Stack will be configured in this way:
ppa:ondrej/php
PHP repo, that allows to install PHP versions from 5.6 from up to 8.4 (at the time of writing)ppa:ondrej/apache2
Apache repomfonte/hte-cli
tool to handle Apache Virtualhosts. This tool can be used to create, delete and list virtualhosts that are specifically optimized for local/test development.MariaDB 11.4
(EOL 29 May 2029) and optimize Mysql so that it will not create headaches (see here)PostgreSQL 16
(EOL 09 Nov 2028) as an alternative to MariaDB, if the developer wants to use itYes, you can. The automated installer will ask you if you want to install Docker. If you agree, it will install Docker Desktop for Windows, and you'll be able to use Docker as you would on a Linux machine.
As both the LAMP Stack and Docker installations are optional, you can decide whether to:
Installation instructions are the same for both Windows 11 and Windows 10.
Specifically, For Windows 10, it is required to have a minimum version 1903, and build 18362 or later. Check your Windows version by pressing the Windows logo key + R, type winver
, and press OK. You should see a number greater than 1903.18362. If that's the case, then this script will work (tested!)
If you want to automatically install everything, open a PowerShell
window with elevated privileges (Run as Admin)
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force; $desktopPath = [Environment]::GetFolderPath('Desktop'); $url = 'https://raw.githubusercontent.com/mauriziofonte/win11-wsl2-ubuntu22-setup/main/install/win11.ps1'; $outputPath = Join-Path -Path $desktopPath -ChildPath 'install-ubuntu22-wsl2.ps1'; (New-Object System.Net.WebClient).DownloadFile($url, $outputPath); & $outputPath
The Automated Installer will do everything for you. Here's a comprehensive list of all the steps that the installer will do:
-SkipWindowsVersionCheck
if you want to run it on Windows 10 aswell).Tips:
-SkipWindowsVersionCheck
at the end of the one-liner install-DryRun
at the end of the one-liner installThe automated install Powershell script will execute a specific Bash Script that takes care of configuring the Ubuntu machine, after the WSL2 VM has been installed.
Anyway, if you already have a working Ubuntu/Debian WSL2 VM, in order to install and configure the LAMP Stack, you can run the following command in the terminal:
wget -qO- https://raw.githubusercontent.com/mauriziofonte/win11-wsl2-ubuntu22-setup/main/install/lamp-stack.sh | bash
The same command can be lauched on a Ubuntu/Debian VM hosted on a Cloud Service, but, you'll need to adjust the Apache Configuration so that:
/etc/apache2/ports.conf
)/etc/apache2/envvars
)Manual installation instuctions are provided in two languages:
To completely remove Ubuntu 24.04 from your computer, open a PowerShell
window and run:
wsl --unregister Ubuntu-24.04
If you used the automated install method, you'll also need to remove a specific HKCU Registry Key. To do so, open a PowerShell
window with elevated privileges (Run as Admin) and run:
Remove-Item -Path "HKCU:\Software\WSL2Setup" -Force -ErrorAction SilentlyContinue | Out-Null
The Ubuntu image will grow fast as you install packages and create files, and Windows will not shrink it automatically. This will lead, over time, to a huge VHDX file that will take up a lot of space on your hard drive, even if the actual space used by the Ubuntu installation is much smaller.
In order to keep things clean & tidy, you can use this utility: wsl2-compact
I suggest to use the installation option 1: As a PowerShell module. This will allow you to run the wslcompact
command from the PowerShell window, and it will also allow you to run the wslcompact
command from the Windows Terminal.
Attention: always refer to the latest version of the README file of the
wsl2-compact
repository, as the installation method may change over time.
Currently, the sole maintainer is @mauriziofonte - more maintainers are quite welcome, as the guides are lenghty, and the automated installer is quite complex!
Released under MIT License. Refer to LICENSE file.
The information provided in this repository is for general informational purposes only. All information is provided in good faith, however I make no representation or warranty of any kind, express or implied, regarding the accuracy, adequacy, validity, reliability, availability, or completeness of any information on this repository.
UNDER NO CIRCUMSTANCE SHALL I HAVE ANY LIABILITY TO YOU FOR ANY LOSS OR DAMAGE OF ANY KIND INCURRED AS A RESULT OF THE USE OF THE INFORMATIONS, GUIDES, HOW-TOS, AND SCRIPTS PROVIDED IN THIS REPOSITORY OR RELIANCE ON ANY INFORMATION PROVIDED ON THIS REPOSITORY. YOUR USE OF THIS WORK AND YOUR RELIANCE ON ANY INFORMATION IS SOLELY AT YOUR OWN RISK.
This repository contains links to other websites or content belonging to or originating from third parties or links to websites and features in banners or other advertising. Such external links are not investigated, monitored, or checked for accuracy, adequacy, validity, reliability, availability, or completeness.