This post shows how to install Drupal on Windows 10 WSL (Windows Subsystem for Linux) with Nginx HTTP server on Ubuntu 18.04 | 20.04.
Drupal is a free, open-source and powerful web content management platform. It comes with great standard features, such as easy content authoring, reliable performance and excellent security. Drupal is written in PHP programming language and distributed under the GNU General Public License.
For more details about Drupal, please check its official website.
With the help of WSL, you can easily install full Linux operating system in your Windows 10 system. You just need to enable WSL (Windows Subsystem for Linux) in your Windows, install a Linux OS, install and run Drupal.
How to Install Drupal on Windows 10 WSL
Simply follow below steps to install Drupal on Windows 10 WSL with Nginx :
Step 1 : Enable WSL in Windows 10
First of all, you will need to enable WSL in your Windows system. To enable it, simply open PowerShell terminal as administrator.
Click on Start icon -> search for PowerShell -> right-click Windows PowerShell app -> choose to run as administrator.
Next, run the command below in the Windows PowerShell console as show below:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
The command above will display a successful message similar as below:
Deployment Image Servicing and Management tool
Version: 10.0.19041.844
Image Version: 10.0.19042.985
Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.
Step 2 : Enable Virtual Machine Platform
Run the commands below from the same PowerShell console to enable the Virtual Machine platform in your Windows system:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
If you have Windows 10 version lower than 2004 in your system, use the commands below:
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
Next, restart your computer for changes to apply. If you forget to start then the below command doesn’t work.
After restart of your computer, launch the PowerShell as administrator again and run the commands below to set WSL 2 as the default version of WSL:
wsl --set-default-version 2
Step 3 : Install Ubuntu in Windows 10
At this stage, WSL 2 is installed and ready to be used. So now you can easily install Linux operating system in your Windows 10 system.
Click the below button to download and install Ubuntu 20.04 LTS from Microsoft Windows store.
Click on the Get button to Download and Install Ubuntu. After installing Ubuntu, launch it from WSL environment.
After launching, it will install and prompt to create your account as show below :
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: studiesonline
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.2 LTS (GNU/Linux 4.4.0-19041-Microsoft x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Use some troubleshooting commands when you get issues above. Run the below troubleshooting commands and launch Ubuntu again:
wsl --set-default-version 1
bcdedit /set hypervisorlaunchtype auto start
Step 4 : Install Nginx HTTP Server
To install Nginx HTTP on your Ubuntu server, run the commands below.
sudo apt update
sudo apt install nginx
Next, run the commands below to stop and start Nginx services:
sudo service nginx stop
sudo service nginx start
For check if Nginx server is installed or not, simply open your browser and type server IP or hostname.
If browser show result similar like below then Nginx is installed and working properly.
http://localhost
Step 5 : Install MariaDB Server
You will also need a database server to run Drupal and store its content. MariaDB database server is an open source, fast and secure database server that you can use with Drupal.
To install MariaDB database server, simply run the commands below:
sudo apt update
sudo apt install mariadb-server mariadb-client
Next, run the commands below to stop, start and enable MariaDB service to always start up with the server boots:
sudo service mysql stop
sudo service mysql start
Now, run the commands below to secure MariaDB server by creating a root password and disallowing remote root access.
sudo mysql_secure_installation
When you run the above command, it will prompted to answer the questions as show below:
- 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
For check if MariaDB is installed and working, run the command below:
sudo mysql -u root -p
When prompted, type the root password.
Step 6 : Install PHP and Related Modules
Drupal is completely based on PHP programming language, so PHP is must required to run Drupal. To install PHP and related modules, run the command below:
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 the PHP and its related modules, run the command below to open PHP default config file and configure some basic settings:
sudo nano /etc/php/7.4/fpm/php.ini
Change the below setting in the configuration file and save it:
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
These above lines are good settings to configure for most Drupal sites.
Next, runt the command below to stop and start PHP7.4 services:
sudo service php7.4-fpm stop
sudo service php7.4-fpm start
Step 7 : Create Drupal Database
To create Drupal database, first you will need to create a blank database for Drupal. Simply run the command below to logon to MariaDB database server:
sudo mysql -u root -p
Next, create a database named drupaldb using command below:
CREATE DATABASE drupaldb;
Now, run the command below to create a database user named drupaldbuser :
CREATE USER 'drupaldbuser'@'localhost' IDENTIFIED BY 'your_new_password_here';
Grant the newly created database user to the database by using command below:
GRANT ALL ON drupaldb.* TO 'drupaldbuser'@'localhost' WITH GRANT OPTION;
Next, save your changes and exit:
FLUSH PRIVILEGES;
EXIT;
Step 8 : Download Drupal
To download the latest version of Drupal, you will need to install Composer, Curl and other dependencies to use GitHub repository:
sudo apt install curl git
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
After installing above dependencies , change the directory to the Nginx root directory and download Drupal packages from GitHub repository:
cd /var/www/
sudo git clone --branch 9.1.9 https://git.drupal.org/project/drupal.git
cd /var/www/drupal
sudo composer install
To check the Drupal latest stable releases, visit its official releases page.
After that, you will need to allow www-data user to own the Drupal directory by using command below:
sudo chown -R www-data:www-data /var/www/drupal/
sudo chmod -R 755 /var/www/drupal/
Step 9 : Configure Nginx For Drupal Site
To configure Nginx for Drupal site, create a new configuration file named drupal in the /etc/nginx/sites-available/ directory by running the commands below:
sudo nano /etc/nginx/sites-available/drupal
After create configuration file, copy and paste the below content into the configuration file and save it. Replace the highlighted line with your own domain name :
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.
Next, run the command below to enable the new site:
sudo ln -s /etc/nginx/sites-available/drupal /etc/nginx/sites-enabled/
Restart the Nginx using command below:
sudo service nginx restart
Step 10 : Launch Drupal
At this stage, Drupal is installed and ready to use. To launch it, open your favorite web browser and browse to the server domain name http://example.com.
http://example.com
It will open the Drupal setup wizard screen.
Next, provide the database information that created in above steps:
Next, create a Drupal admin account:
Finally, login with admin account created above and enjoy Drupal.
That’s all
If you face any error and issue in above steps , please use comment box below to report.
If our article helps you, please consider buying us a coffee
Thank you for your support.