The Subsystem for Linux 2 (WSL2) includes its own Linux kernel and is able to run numerous programs natively for the open-source OS. It therefore makes sense to use this environment for web development and to install Apache, MySQL, and PHP.

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
The newly installed Ubuntu prompts you to check the system for available updates

The newly installed Ubuntu prompts you to check the system for available updates

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.

Installing the meta package for the LAMP server

Installing the meta package for the LAMP server

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)

If you use the distribution of Ubuntu 20.04 in WSL2 the installation of MySQL 8.0 fails

If you use the distribution of Ubuntu 20.04 in WSL2 the installation of MySQL 8.0 fails

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

Customizing Apache ^

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

The first time it is started the web server issues a warning that can be removed by adjusting the configuration

The first time it is started the web server issues a warning that can be removed by adjusting the configuration

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
Adjusting the configuration for Apache to avoid the warning at startup

Adjusting the configuration for Apache to avoid the warning at startup

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:

<?phpphpinfo();?>

The information about the installed PHP should be displayed here:

http://localhost/phpinfo.php

Output information about PHP to check its functionality

Output information about PHP to check its functionality

Configuring MySQL ^

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
Configure the home directory for the account under which MySQL is running

Configure the home directory for the account under which MySQL is running

Depending on the security requirements of the development environment, you can execute the security script by issuing the command

sudo mysql_secure_installation

Then you start MySQL with

sudo service mysql start

Installing phpMyAdmin ^

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
Installing phpMyAdmin including some PHP modules

Installing phpMyAdmin including some PHP modules

Subsequently, you can start the tool using:

http://localhost/phpmyadmin

+4
avataravatar
0 Comments

Leave a reply

Please enclose code in pre tags

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2021

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account