[WSL] PHP Development Environment by “Windows Subsystem for Linux” (Part 1)

This article requires Windows 10 (Build Version 1709 [The Fall Creators Update]) or above to work.

Although WSL exists since Version 1607 [Anniversary Update], it’s harder to setup and more buggy.

In this tutorial we will setup this development environment in WSL (In Part 1)
Apache 2.4
MySQL 5.7
PHP 7.2 (Run as FPM)
phpMyAdmin
Composer

With those tools under Windows 10 (In Part 2)
PHPStorm
Bash and Linux CLI tools
PHP Deployer

A. Installation

1. Enable “Windows Subsystem for Linux”

Start > Search “Turn Windows features on or off”
The result should show up after typing first two words

Check “Windows Subsystem for Linux”, Click “OK”, Reboot

2. Install Ubuntu 18.04 on WIndows

Start > Search”Microsoft Store”, open it and search for “Ubuntu 18.04”
Install and launch it first time, it takes some time to initialize.
Enter desired username and password for the Linux subsystem.

3. Start enjoying your Linux subsystem!

B. Install and Configure Packages

Part B works exactly the same way as Ubuntu 18.04.
If you are familiar with Ubuntu 18.04, you may skip this part and use your own method for installation.

1. Update all installed packages
Let’s do a apt dist-upgrade first

2. Install Apache, PHP, MySQL, git

3. Configure PHP

Enable PHP FPM for Apache

Increase PHP resources limits for development

4. Configure Apache2

Enable rewrite module

Enable .htaccess in all directories

5. Configure MySQL

Remove test user and databases

It will make several changes to MySQL login crediitcal
(Press ENTER multiple time until finish if you don’t care)

Enable MySQL root password login
MySQL 5.7 under Ubuntu 18.04 do not allow password login for security reason,
But it doesn’t matter much in our development machine, so we change it in order to use phpMyAdmin.

6. Install and enable phpMyAdmin (From git)

7.  Install composer (From official installer)

8. Start everything!

Yes, something unusual start appear from here.
Service under WSL do not start automatically, after installation or after reboot.

You may also encounter “Invalid argument: AH00076: Failed to enable APR_TCP_DEFER_ACCEPT” when starting Apache2.
It doesn’t harm anything, we will remove that later, however.

9. Basic installation complete

You now have PHP, Apache, MySQL working, and phpMyAdmin under http://127.0.0.1/phpMyAdmin
All ports listened by applications inside WSL are accessible in Windows.

In next part we will go though the special attributes and gotchas of the Linux subsystem.
Make it share files and play nice with your favorite Windows tools and IDEs!

 

 

 

Leave a Reply

Your email address will not be published.

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