---
title: "Installing Drupal 9 on Windows Subsystem for Linux from Scratch"
description: "Have you ever tried installing Drupal on WSL? Let's see how! You can now learn how to install Drupal 9 on Windows Subsystem for Linux from scratch."
url: https://www.specbee.com/blogs/installing-drupal-9-on-windows-subsystem-for-linux-from-scratch
type: Article
author: "Saranya Ashok Kumar"
categories: "Code Corner"
published: 2023-01-16
updated: 2026-10-06
---

# Installing Drupal 9 on Windows Subsystem for Linux from Scratch

If you’re reading this, chances are you already know what Windows Subsystem for Linux is or maybe you’re already using it. But if you’re new to it, Windows Subsystem for Linux (WSL) is a Windows feature that lets you run a Linux distribution and use a BASH command line straight from your Windows machine!

Linux systems run Drupal very well. Read more to find out why use WSL after all, and a step-by-step guide on installing Drupal 9 on WSL from scratch.

## Why use Windows Subsystem for Linux?

Some of the many reasons why a lot of developers like using WSL are:

- Supports better performance speed when working on Javascript-based frameworks.
- Instead of translating a tutorial written for Linux users into equivalent commands for Windows, you prefer using BASH.
- Better alignment between your local dev environment and the Linux deployment environment.
- You don’t need a separate virtual machine or dual booting.
- You don’t need to maintain both Links and Windows build scripts while you leverage Linux workspaces.

### Let’s take one step at a time

### Step 1: Install WSL 

Before installing WSL, we need to make sure that WSL is enabled in the Windows Features: “Turn windows feature on/off”, as shown in the screenshot below.

 ![Turn Windows on](https://www.specbee.com/sites/default/files/styles/large/public/migrated/turn_windows_0.png.avif?itok=UdoBTdy5)

 

 ### Step 2: Install Ubuntu bash

Go to the Microsoft store and look for Linux. Here, I am using the Ubuntu app. Install and open the Ubuntu bash.

 ![Ubuntu](https://www.specbee.com/sites/default/files/styles/large/public/migrated/ubuntu_0.png.avif?itok=WJ0xpIae)

 

 ### Step 3: Set the login

Now let’s open Ubuntu bash. When you initialize it, it will ask you to create a username and a password. You can choose your own username and password here.

 ![Ubuntu bash](https://www.specbee.com/sites/default/files/styles/large/public/migrated/ubuntu_bash_0_0.png.avif?itok=KeufpopL)

 

 ### Step 4: Install PHP and its extensions

Run the below commands to install PHP and the required extensions for Drupal.

```php
$ sudo apt-get update
$ sudo apt-get install -y git php8.1 php8.1-curl php8.1-xml
php8.1-mbstring php8.1-gd php8.1-sqlite3 php8.1-mysql php8.1-cli
php-xml php8.1-gd libapache2-mod-php8.1 php8.1-mbstring
```

Now run “php -v” to confirm if the installation has been done successfully.

 ![Install php](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Install_php_0.png.avif?itok=jhfUg8xJ)

 

 ### Step 5: Install Composer

Use these commands to install composer on Ubuntu:

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

To make working with Composer easier, run the following command to move Composer into your global path:

```plaintext
$ sudo mv composer.phar /usr/local/bin/composer
```

Next, type composer to make sure you installed it successfully.

 ![Composer](https://www.specbee.com/sites/default/files/styles/large/public/migrated/composer_0.png.avif?itok=W_Sb550w)

 

 ### Step 6: Install Apache

Follow the below commands to install Apache:

```php
$ sudo apt update && sudo apt -y upgrade
$ sudo apt install -y apache2
$ sudo service apache2 restart
```

If you have wamp or xampp on your Windows machine, make sure you change the port number from Listen 80 to Listen 8080 in this file (/etc/apache2/ports.conf).

Now go to <http://localhost> (or) <http://localhost:8080> on your browser and make sure Apache is installed successfully.

 ![Localhost](https://www.specbee.com/sites/default/files/styles/large/public/migrated/localhost_0.png.avif?itok=LFPgr3kD)

 

 ### Step 7: Enable PDO

Next, you have to enable PDO (PHP Data Objects) support. Please follow the below commands:

```php
$ sudo apt-get install php8.1-mysql
```

- Go to **/etc/php/8.1/apache2/php.ini** file and uncomment "extension=pdo\_mysql.so" line.
- Restart Apache.

```php
$ sudo service apache2 restart
```

### Step 8: Activate clean URL's

To activate clean URL’s, use this command:

```php
$ sudo a2enmod rewrite
```

Go to **/etc/apache2/apache2.conf** file, edit as "Allowoverride All" for **/var/www/** directory, and restart apache.

 ![Activate clean URL](https://www.specbee.com/sites/default/files/styles/large/public/migrated/activate_url_0.png.avif?itok=IpcWzuW1)

 

 ### Step 9: Install MySQL

Next, you have to install MySQL server.
$ sudo apt install -y mysql-server mysql-client

Now Start MySQL
$ sudo service mysql start

Navigate to MySQL
$ sudo mysql

Alter root user password.
$ ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql\_native\_password BY '\*\*\*\*\*\*\*\*\*';

After you altered the password, you have to log in to MySQL by running the following:
$ sudo mysql -u root -p
Give password and login to the MySQL server.

Next, run the below command to improve the security of your DB.
$ sudo mysql\_secure\_installation

Provide values as you wish for each question. Make sure, you gave **“No”** for **“Disallow root login remotely?”**

 ![Security of your DB](https://www.specbee.com/sites/default/files/styles/large/public/migrated/security_db_0.png.avif?itok=zWZfB-Im)

 

 Now go to your MySQL and flush the privileges. Restart MySQL.
$ FLUSH PRIVILEGES;

### Step 10: Install Drupal 9

Navigate to the /var/www/html directory and download the latest version of Drupal 9 with Composer.

$ composer create-project drupal/recommended-project drupal-9.4.9

Now lets update the Drupal folder permissions for Apache:

$ sudo chown -R www-data:www-data /var/www/html/drupal-9.4.9
$ sudo chmod -R 755 /var/www/html/drupal-9.4.9

- To make sure the installation is perfect, its a good idea to restart the system once before installing Drupal.
- Create a new database for the Drupal installation.
- Go to http://localhost:8080/drupal-9.4.9/ and proceed with the Drupal installation.
- When you give data for the database form, make sure you gave a password for MySQL authentication.

## How to Access and Edit files from WSL

Now that you have set up WSL and installed Drupal 9, lets look at accessing your files from WSL.

Go to your File Explorer and type **\\\\wsl$** to navigate to your WSL folder. The Ubuntu folder is your WSL folder (as shown below).

 ![File Explorer](https://www.specbee.com/sites/default/files/styles/large/public/migrated/file_explorer_0.png.avif?itok=NCppEp79)

 

 **Now let's edit the WSL files**

Open Visual Studio code and download the WSL extension.

 ![Visual Studio WSL](https://www.specbee.com/sites/default/files/styles/large/public/migrated/wsl_0.png.avif?itok=g0aql31z)

 

 On Ubuntu bash, go to the Drupal folder and type **$ code**

 ![Drupal folder](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Drupal_folder_0.png.avif?itok=HswEaFkj)

 

 It will now open the folder on Visual Studio Code (*a Microsoft source-code editor*).

 ![Visual studio code](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Visual_studio_code_0.png.avif?itok=eHvKgyp5)

 

 Now, enable the edit permission:

$ sudo chown -Rv saranya drupal-9.4.8

 ![Edit Permission](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Edit_permission_0.png.avif?itok=LAQthjqg)

 

 And that’s it! As a result, whatever you update in VS Code will affect your website as well.

## Final Thoughts

I hope you liked what you learned today and maybe you will try installing Drupal 9 on WSL yourself sometime! Consider [subscribing to our weekly newsletter](https://specbee.us19.list-manage.com/subscribe?u=a3d560a1fc06522ef6c707339&id=689c8b7694) to receive our latest updates on Drupal and other trending tech topics. If you’re new to our site, Specbee is a leading [Drupal development company](https://www.specbee.com/services/drupal-web-development) and we offer a full stack of expert-led Drupal services. Looking to start a new Drupal project? [We’d love to talk!](https://www.specbee.com/contact)