How to Install Drupal on Windows 11 WSL

template 1599667 640

This brief tutorial shows students and new users how to install Drupal content management system on Windows 11 using Windows Subsystem for Linux (WSL).

You can now install and run Drupal CMS directly from Windows 11 via Windows Subsystem for Linux (WSL) without installing third party apps or using a virtual machine. Back in 2017, Microsoft released WSL and later WSL2 that lets developers run a GNU/Linux environment, including most command-line tools, utilities, and applications directly in Windows without setting up a virtual machine or dual-boot.

WSL2 is the new and improved version comes with performance boost, full system call compatibility, and built with a new architecture and that delivers features that make WSL an amazing way to run a Linux environment in Windows.

The new Windows 11 will come with many new features and enhancements that will work great for some while adding some learning challenges for others. Some things and settings have changed so much that folks will have to learn new ways to work with and manage Windows 11.

With Windows 11, installing WSL is a bit different than in Windows 10. However, the steps below is going to show you how to do that.

To install and run Drupal on Windows 11 you must first install and enable WSL.

Install Windows Subsystem for Linux in Windows 11

To enable WSL in Windows, you will want to open the Command Prompt as administrator. Click on Start then begin typing Command Prompt.

Next, right-click Command Prompt app and choose to Run as administrator.

windows 11 command prompt administrator

When the console opens, run the commands below to install Windows Subsystem for Linux (WSL):

wsl --install

Wait for WSL to be installed.

After installing, you should get a success message similar to the lines below:

Installing: Virtual Machine Platform
Virtual Machine Platform has been installed.
Installing: Windows Subsystem for Linux
Windows Subsystem for Linux has been installed.
Downloading: WSL Kernel
Installing: WSL Kernel
WSL Kernel has been installed.
Downloading: GUI App Support
Installing: GUI App Support
GUI App Support has been installed.
Downloading: Ubuntu
The requested operation is successful. Changes will not be effective until the system is rebooted.

Restart your computer.

WSL should be installed and ready to use. When you want to update, simply run the commands below:

wsl --update

Install Specific Linux distro on Windows 11

Now that WSL is installed, you can now install Linux distro of your choice. To list the available distributions to install, simply run the commands below:

wsl --list --online

You should then see all available distributions that can be installed on WSL.

NAME            FRIENDLY NAME
Ubuntu          Ubuntu
Debian          Debian GNU/Linux
kali-linux      Kali Linux Rolling
openSUSE-42     openSUSE Leap 42
SLES-12         SUSE Linux Enterprise Server v12
Ubuntu-16.04    Ubuntu 16.04 LTS
Ubuntu-18.04    Ubuntu 18.04 LTS
Ubuntu-20.04    Ubuntu 20.04 LTS

To install a Linux distribution from the list above, simply run the commands below using the distribution name. For example, to install Ubuntu 20.04, run the commands below:

wsl --install -d ubuntu-20.04

You should then get a message that the distribution is installed.

Downloading: Ubuntu 20.04 LTS
Installing: Ubuntu 20.04 LTS
Ubuntu 20.04 LTS has been installed.
Launching Ubuntu 20.04 LTS.

After installing, you should get a Ubuntu command console with setup details.

Installing, this may take a few minutes.
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: Richard
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 20.04 LTS (GNU/Linux 4.4.0-22000-Microsoft x86_64)

Some troubleshooting commands to run when you run into issues.

wsl --set-default-version 1
bcdedit /set hypervisorlaunchtype auto start

Now that Ubuntu Linux is installed and ready to use, continue below to install the LEMP server to run Drupal on. First, install Nginx HTTP Server.

Install Nginx HTTP Server

Drupal requires a web server to function, and Nginx is one of the most popular opensource web server available today.

To install Nginx on Ubuntu, run the commands below:

sudo apt update
sudo apt install nginx

After installing Nginx, the commands below can be used to stop and start Nginx services.

sudo service nginx stop
sudo service nginx start

To test whether Nginx is installed and functioning, open your web browser and browse to the server’s IP address or hostname.

http://localhost

windows wsl ubuntu nginx install

If you see the above page in your browser, then Nginx is working as expected.

Install MariaDB Server

You’ll also need a database server to run Drupal. A database server is where Drupal content get stored.

A true open source database server that you can use with Drupal is MariaDB database server. It is fast, secure and the default server for almost all Linux servers.

To install MariaDB, run the commands below:

sudo apt install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.

sudo service mysql stop
sudo service mysql start

Next, run the commands below to secure the database server with a root password if you were not prompted to do so during the installation.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

To verify and validate that MariaDB is installed and working, login to the database console using the commands below:

sudo mysql -u root -p

type the root password when prompted.

mariadb welcome

If you see a similar screen as shown above, then the server was successfully installed.

Install PHP and Related Modules

Drupal is a PHP based application, and PHP is required to run it. Run the commands below to install PHP and related modules to support Drupal.

sudo apt install php-fpm php-common php-mysql php-gmp php-curl php-intl php-mbstring php-xmlrpc php-gd php-xml php-cli php-zip

After installing PHP, go and configure some basic settings that may be required for Drupal to function properly.

For this tutorial, PHP 7.4 was installed. Based on your environment, another version of PHP might be installed. So verify that.

sudo nano /etc/php/7.4/fpm/php.ini

Below are good settings to configure for most Drupal websites.

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

That should get PHP 7.4 installed with some basic settings to allow Drupal to function.

After setting up PHP, the command below can be used to stop and start PHP7.4 services.

sudo service php7.4-fpm stop
sudo service php7.4-fpm start

Create Drupal Database

When all the servers installed above, it’s now time to begin setting up Drupal environment. First, run the steps below to create a blank database for Drupal to use.

Logon to MariaDB database console using the commands below:

sudo mysql -u root -p

Then create a database called drupaldb

CREATE DATABASE drupaldb;

Next, create a database user called drupaldbuser and set password

CREATE USER 'drupaldbuser'@'localhost' IDENTIFIED BY 'new_password_here';

Then grant the user full access to the database.

GRANT ALL ON drupaldb.* TO 'drupaldbuser'@'localhost' WITH GRANT OPTION;

Finally, save your changes and exit.

FLUSH PRIVILEGES;
EXIT;

Download Drupal

At this point, Drupal is ready to be downloaded and installed. Use the commands below to download the latest version of Drupal.

To get Drupal latest release you may want to use GitHub repository… Install Composer, Curl and other dependencies to get started…

sudo apt install curl git
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

After installing curl and Composer above, change into the Nginx root directory and download Drupal packages from Github… Always replace the branch number with the latest branch.

To view Drupal releases, see this page.

cd /var/www/
sudo git clone --branch 9.1.9 https://git.drupal.org/project/drupal.git
cd /var/www/drupal
sudo composer install

Then run command below to allow www-data user to own the Drupal directory.

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

Configure Nginx VirtualHost

Below is where you configure Nginx VirtualHost file for the Drupal site you’re creating. This file defines how client requests are handled and processed.

Run the commands below to create a new VirtualHost file called Drupal in the /etc/nginx/sites-available/ directory.

sudo nano /etc/nginx/sites-available/drupal

A very good configuration settings for most Drupal site on Nginx server is below. This configuration should work great.

Copy the content below and save into the file created above.

server {
    listen 80;
    listen [::]:80;
    root /var/www/drupal;
    index  index.php index.html index.htm;
    server_name  example.com www.example.com;

    client_max_body_size 100M;
    autoindex off;

    location ~ \.*/.*\.php$ {
        return 403;
    }

    location ~ ^/sites/.*/private/ {
        return 403;
    }

    # Block access to scripts in site files directory
    location ~ ^/sites/[^/]+/files/.*\.php$ {
        deny all;
    }

    # Block access to "hidden" files and directories whose names begin with a
    # period. This includes directories used by version control systems such
    # as Subversion or Git to store control files.
    location ~ (^|/)\. {
        return 403;
    }

    location / {
        try_files $uri /index.php?$query_string;
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    # Don't allow direct access to PHP files in the vendor directory.
    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }


    location ~ '\.php$|^/update.php' {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # Fighting with Styles? This little gem is amazing.
    # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }

    # Handle private files through Drupal. Private file's path can come
    # with a language prefix.
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }
}

Save the file and exit.

After saving the file above, run the commands below to enable the new site, then restart Nginx server.

sudo ln -s /etc/nginx/sites-available/drupal /etc/nginx/sites-enabled/
sudo service nginx restart

At this stage, Drupal is ready and can be launched by going to the server’s IP or hostname.

http://example.com

That should bring up Drupal setup wizard.

drupal windows wsl install

Type in the database connection and continue

drupal windows wsl database connection

Create Drupal admin account and password, save and continue.

drupal windows wsl admin account

Login with account above and you’re done.

drupal windows wsl dashboard

That’s it!

Conclusion:

This post showed you how to install Drupal on Windows 10 with Ubuntu. If you find any error above, please use the comment form below to report.

Leave a Reply

Your email address will not be published. Required fields are marked *

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