Drupal 10 Development in Windows with WSL2

By alan.wallace, 9 October, 2023

For many, like myself, Windows is the preferred environment for development.  Software like Drupal, however, is much more easily managed in a Linux environment.  Fortunately, there's a solution.  

Windows Setup

This Setup applies to Windows 10

Install WSL 2

wsl --install

Install Ubuntu 22.04.6 from the Microsoft Store

It should prompt you for a username/password, and you're ready to go. I picked the username 'drupaldev' which will be reused through this post, but you can use whatever you like (just remember to user your username anywhere that drupaldev is referenced later on)

If it connects you to your distribution with root@<hostname>, we need to make the following change to run as the user we just created

Set up Docker Desktop

Download and install Docker Desktop. Make sure to install it with WSL support.

Ubuntu VM Setup

Edit /etc/wsl.conf and add:

[user]
default=drupaldev

Get Ubuntu Fully Up-to-Date

sudo apt update && sudo apt upgrade -y 

Install PHP 8.1

Add the PHP Repository so that we have access to 8.1

sudo add-apt-repository ppa:ondrej/php 
sudo apt update
sudo apt install php8.1 -y

Install PHP Extensions

sudo apt-get install php8.1-xml -y
sudo apt-get install php8.1-gd -y
sudo apt-get install php8.1-zip -y

Install NGINX

We are installing this to the local machine so that we can

sudo apt-get install nginx -y

Install Composer 

(This will install 2.6.5, which was the latest at the time of writing)

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');" 

 

Move Composer to a common bin directory

sudo mv composer.phar /usr/local/bin/composer

Install MySQL

Given that this blog is focused mostly around Microsoft Azure, I will be using MySQL proper instead of MariaDB as Azure will be discontinuing support for MariaDB in the not too distant future.

sudo apt install mysql-server -y
sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start
sudo mysql_secure_installation

Install the Azure CLI

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash