Scotts Web Dev Banner
Did you notice... every article on this site has an associated video? Consider subscribing to Scotts Web Dev on YouTube! :)

How To Install Apache, MySQL, & PHP on Windows Subsystem for Linux (WSL)

In this video, part 2 of the series of setting up a development environment on Windows Subsytem for Linux (WSL), I show you how to install a LAMP server. This means installing Apache, MySQL, & PHP. If you have not watched part 1 yet, see how to install Windows Subsystem for Linux (WSL).

Update your packages and upgrade them

Before we get started, we need to update our package list and upgrade our packages.

sudo apt update
sudo apt upgrade

How to install Apache on WSL

Up first, we install our web server, Apache.

sudo apt install apache2

Several times throughout this article, it will prompt us to press y to accept the amount of disk space we need for the software. Press y and then enter, if you agree to it of course.

How to start Apache and install it as a system service

Start apache

sudo service apache2 start

Install it as a system service so that it starts when your Linux system starts.

sudo systemctl enable apache2

How to install MySQL on WSL

Up next we install MySQL.

sudo apt install mysql-server

After this installs, we need to secure our MySQL installation. Do this by running the following command and following the prompts:

sudo mysql_secure_installation

How to set MySQL root password on WSL

Next, we’ll want to set the root password for MySQL. We could do this later, but we will go ahead and get it out of the way now.

sudo mysql

Then, run the following queries, replacing “YOUR PASSWORD HERE” with your actual password.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOURPASSWORDHERE'; 
FLUSH PRIVILEGES;
exit;

How to Install PHP on WSL

Completing our LAMP stack, we are going to install PHP.

sudo apt install php libapache2-mod-php php-mysql

Restart Apache

sudo service apache2

Test it out!

Your web files will be located in /var/www/html The default apache index is in there. You can view your local webserver by going to http://localhost in your browser.

Please note that this is not https:// (SSL) and we will learn how to do that in a future video in this series.

Test PHP is working

Create a index.php file in /var/www/html/. You can do this through your code editor or vim or however you want. It’s cool to note that by using Windows Subsystem for Linux, you can view your linux files in Windows explorer.

File contents will be:

<?php

phpinfo();

Save it and view http://localhost/index.php in your browser.

Coming up next in this series…

In the next videos we will cover installing phpmyadmin, ssl (so we can use https://) and setting up apache virtual hosts.

Thanks for watching!

If this video was helpful to you, please consider subscribing to my YouTube channel and liking the videos.

Thank you!