Steps to Install Apache, MySQL and PHP in WSL 2 -Windows 10

As we know the Windows Subsystem for Linux 2 has its own Linux Kernel which makes it run various kinds of open source programs efficiently. Therefore, here we are with a tutorial to learn how to install LAMP stack (Apache, MySQL, and PHP including PhpMyAdmin) on WSL 2.

LAMP stack which is also known as a Linux web server stack to run various web apps, CMS such as WordPress and more. Of course, if you are already using XAMPP on Windows 10, then there is a provision to change the default ports of Apache, PHP, and MySQL or MariaDB so that the LAMP on WSL 2 and one on XAMP can run together without interfering in each other’s services.

Why you should start using Apache web server or LAMP on WSL 2 instead of a Virtual machine?

The biggest reason to run the LAMP server on WSL 2 rather than using Virtual Machine on VirtualBox or VMware Player is the performance. As Windows Subsystem for Linux is tightly integrated into Windows 10 environment, thus the performance which we can get there will be much better than running some Linux VM. Furthermore, after the latest Windows update, now we can explore the Linux filesystem directly using the Windows explorer, even running of GUI applications on WSL 2 is possible.

Another thing is WSL uses the Windows localhost or the same IP address which the system has, thus it easy to access the created webserver and web apps using the system browser, without much hassle.

Install LAMP server on WSL 2 or 1- Windows 10 subsystem for Linux

The popular distribution available on Microsoft Store to download and use as WSL 1 or 2 is of course Ubuntu 18.04 or Ubuntu 20.04 LTS. You can choose any of them. However, before moving further make sure you already have installed WSL 1 to enable WSL 2. The steps given below will work for both versions.

Check out these two tutorials, if you haven’t had a Subsystem.

Run WSL Ubuntu 18.04 or 20.04 distro

Those are using it the first time, to run bash after installing, simply go to the Windows search box and type Ubuntu, as its icon appears, click that to run.

Run WIndows 10 Ubuntu bash

 

Update system

After starting the program first time, it will be a good idea first we update its repo and packages, for that run the following two commands:

sudo apt update

sudo apt upgrade

Install Apache. MySQL and PHP – Lamp Server

Now, to install the Lamp server, we can use the below given single command on WSL Linux instead of issuing one by one for each service to get configured on the system.

sudo apt install lamp-server^

The above command will show the packages are going to install for Apache, MySQL, and PHP, accept them and let the system install the same.

Start Apache and MySQL services

Once the installation is completed, start the Apache and MySQL service using the below commands:

sudo service apache2 start

Secure and start MySQL:

sudo usermod -d /var/lib/mysql/ mysql

sudo mysql_secure_installation

sudo service mysql start

To check Apache is running perfectly, open your browser and type: http://localhost

Install PhpMyAdmin

If you want to manage your MySQL created database efficiently then also install the open-source PHPMyAdmin for easy web database management user interface.

sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl

When it asks you to configure the database, then follow the guided wizard. Here a few screenshots to give you a quick idea.

Configure Database for PhpMyAdmin min Connect to Database min Select Apache server min Set password min phpmyadmin min

 

 

Leave a Reply

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