The ULTIMATE guide to setup Windows Subsystem for Linux (WSL) with Ubuntu, Apache2, MySQL and PHP

By Dillon Smart · · · 2 Comments

Ubuntu

Windows is now good for development! Yes! All thanks to Windows Subsystem for Linux (WSL). No more WAMP or Xampp, WSL can do everything you need. In this ultimate guide to setup Windows Subsystem for Linux with Ubuntu, Apache2, MySQL, and PHP we will cover:

What is Windows Subsystem for Linux?

Windows Subsystem for Linux is a compatibility layer for running Linux binary executables on Windows 10. WSL was created by Microsoft for developers and allows those who need to use Bash, common Linux tools, and other Linux-first tools on Windows.

WSL provides a terminal running Bash shell, where Linux commands and tools can be executed. Packages and applications can be installed just as they would on any Linux machine, using package managers such as APT.

From the terminal, users can access both the Linux file system and the Windows file system, which can be found in the /mnt directory.

Setting up Windows Subsystem for Linux with Ubuntu

First things first, we need to enable WSL on our machine. Open PowerShell as administrator and run:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Now its time to install the OS you want to run. In this example we will install Ubuntu from the Windows Store, however, you can install other distros directly from the Windows store.

In the Windows Store, search for Ubuntu, and once installed, open it. A console window will open which will initialize the instillation. This may take a few minutes. After installation has been completed, you will be asked to set the default user and password.

Once completed, search in the Cortana search bar for Bash.exe. You will be straight into the user directory.

Alternatively, you can download Windows Terminal, from which you can open Ubuntu.

Install a LAMP server (Linux, Apache2, MySQL, PHP)

For our server, we will be using Apache2 and MySQL. Before we install lamp-server we need to run the following:

sudo apt-get update && sudo apt-get upgrade

Then run:

sudo apt-get install lamp-server^

Now we need to make some changes to the apache2.conf file. To open and edit the file run:

nano /etc/apache2/apache2.conf

You shouldn’t need to use sudo for the moment, however, if the above doesn’t work then append the command with sudo.
Now add the following 2 lines to the file.

Servername localhost
AcceptFilter http none

Now start Apache2 using the following command:

sudo service apache2 start

To start MySQL run:

sudo mysql start

Linking your directory in windows with your server directory

Now that we have the basics set up and running, we can link our working directory within Windows with your WSL Apache server. If you have used different local environment setups then this step will be familiar to you, but what this does is take a directory where you have all your projects within Windows, and makes them accessible to your server directory (linking the directories).

Example:

Create a directory within your User/Documents folder named projects (notice lower case).

Next, open your terminal or Bash.exe and run the following:

cd /
sudo ln -s /mnt/c/Users/windows-user-name-here/Documents/projects /var/www/html

All done! Now you can create new directories and files within your projects folder, make changes to files as you usually would using your favorite IDE or text editor, and run them in your browser by visiting localhost, all of which is severed from your Apache2 server on WSL.

Apache2LinuxMySQLPHPUbuntuWindowsWindows Subsystem for Linux

2 Comments

IKnowThatNow

[…] For help setting up WSL for web developers, check out The ULTIMATE guide to setup Windows Subsystem for Linux (WSL) with Ubuntu, Apache2, MySQL and PHP […]

I Know That Now

[…] In this post we will show you how to change PHP version on Ubuntu, Linux. This also works on WSL. Follow this guide to setup Windows Sub System for Linux. […]

Was this helpful? Leave a comment!

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

PHP Numeric Literal Separator

Updated 14th December 2023

First introduced in PHP 7.4, the Numeric Literal Separator in PHP makes large integers within your code easy to read. Naturally, we find it easier to read number which are grouped, for example, 1,650,000. Using the numeric literal separator in PHP Since PHP 7.4, we can now use numbers like this: Adding an underscore between

How to use Microsoft Graph API with Laravel

Updated 1st January 2024

Microsoft Graph is a gateway to data and intelligence within Microsoft 365. Microsoft Graph is great to build apps for organizations and consumers using the vast amount of data stored in Microsoft 365. In this post, we are going to integrate with Microsoft Graph API in Laravel to get all users assigned to your tenant.

Laravel php artisan make:auth command not defined

Updated 11th August 2022

Laravel 6.0 LTS came with a lot of changes to the framework, apart from moving the the new Semantic Versioning, Laravels famous php artisan make:auth command was dropped. php artisan make:auth Before the Laravel make:auth command would create all the Migrations, Models, Controllers and Routes needed to easily setup an authenticatable application in seconds. However,