- New Group Policy settings in Windows 11 23H2 - Mon, Nov 20 2023
- Windows Server 2025 will support SMB over QUIC in all editions - Fri, Nov 17 2023
- Switch between Windows Terminal and the legacy console - Thu, Nov 16 2023
To run a LAMP stack under Windows, Linux can, of course, be installed on a virtual machine. In addition, there are ports for Apache, PHP, and MySQL or MariaDB for Windows, so that they can also be set up there using XAMPP, for example.
Advantages of LAMP in WSL
Compared to Linux in a VM, WSL2 offers much tighter integration with Windows 10, enabling you to start Windows applications from bash or navigate through the Linux file system with the Explorer.
It is also interesting to note that Linux services can be accessed from Windows via localhost, for example, if you run a web application on Linux and want to display it in the browser on Windows.
The Windows ports of the LAMP components are not ideal if you develop a web application locally, but the production environment runs on Linux. Again, WSL2 is a good compromise because it provides native Linux in the familiar Windows environment.
Setup under Ubuntu
Microsoft offers several Linux distributions for WSL2, which can be installed via the Microsoft Store once the subsystem has been activated as a Windows feature (see Install Subsystem for Linux 2 (WSL 2) on Windows 10 2004).
This guide shows you how to set up a LAMP stack using Ubuntu, which is currently available in versions 18.04 and 20.04. After starting the program for the first time and specifying the root password, enter these commands to install the latest updates:
sudo apt updatesudo apt upgrade
Then you can start installing Apache, MySQL, and PHP.
Installation of lamp-server
Some instructions on the web pass the names of all components to apt-get. It is easier to use the lamp-server meta package, even if you don't have control over the installation down to the last detail:
sudo apt-get install lamp-server^
The caret after the lamp server is required because it marks a meta package.
While the entire process runs without interruption under Ubuntu 18.04, version 20.04 fails to install MySQL 8.0 (Ubuntu 18.04 uses MySQL 5.7 by default). The following error message appears:
Errors were encountered while processing: mysql-server-8.0E: Sub-process /usr/bin/dpkg returned an error code (1)
Several forums discuss this problem, but at the moment there seems to be no solution. The only way around it on this version of Ubuntu is to remove the installed MySQL components and then set up MariaDB as an alternative:
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-* mysql client-core-* sudo apt install mariadb-server
If you start the Apache server immediately after a successful installation, it will issue the following warning:
(92)Protocol not available: AH00076: Failed to enable APR_TCP_DEFER_ACCEPT
Therefore, you should first open the configuration file with
sudo vi /etc/apache2/apache2.conf
Then, insert the following lines:
AcceptFilter http noneAcceptFilter https none
Now start Apache with
sudo service apache2 start
The first time you launch the HTTP server, the Windows firewall appears, in which you have to allow apache2 to connect to the network.
Checking the functionality of PHP
In the next step, it is recommended to test the correct function of PHP (Ubuntu 20.04 uses PHP 7.4 by default, Ubuntu 18.04 version 7.2). To do this, create a file with the name phpinfo.php under /var/www/html and add the following content:
The information about the installed PHP should be displayed here:
MySQL also requires customization before the initial start to avoid a warning from the wsl-integration.sh script. It ensures that the account under which the database runs is assigned a home directory:
sudo usermod -d /var/lib/mysql/ mysql
Depending on the security requirements of the development environment, you can execute the security script by issuing the command
Then you start MySQL with
sudo service mysql start
A popular tool for managing the database is phpMyAdmin. You can install it and some of the PHP modules it requires with this command:
Subscribe to 4sysops newsletter!
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
Subsequently, you can start the tool using: