How to install Drupal 9 using Nginx and encrypt SSL on Debian 10

How to install Drupal 9 using Nginx and encrypt SSL on Debian 10

Drupal is a well-known open source content management system based on PHP. It is provided free of charge and is issued under the GNU General Public License. Drupal can be used on websites of all sizes, from huge international websites to personal blogs and corporate or government websites.

The core part of drupal is called “Drupal core”, which contains the basic content management system, user management, menu management, layout customization and system management. Drupal Core can be extended through plugins. Until now, the Drupal community has provided more than 31.000 modules for Drupal.

In this tutorial, we will show you how to install Drupal 9 on Debian Buster 10. We will run Drupal under the LEMP stack (Linux, Nginx, MySQL/MariaDB, and PHP-FPM) and use SSL Letsencrypt to secure the installation. .


For this guide, we will test the Drupal installation on the latest version of Debian Buster 10, which has 2GB RAM, 50GB free disk space, and 2 CPUs. In addition, we need root sudo privileges to install new software packages and edit certain system software configurations.

What will we do?

  • Install Nginx Web Server
  • Install and configure PHP-FPM
  • Install and configure MariaDB
  • Generate SSL Letsencrypt
  • Setting up Nginx Virtualhost for Drupal 9
  • Download Drupal 9 source code
  • After Drupal 9 is installed

Step 1-Install Nginx web server

First, we will install the Nginx web server on our Debian server.

Use the following apt command to update the available repositories on the system and upgrade all packages to the latest version.

                        sudo apt updatesudo apt upgrade

Next, use the following command to install the Nginx web server software package.

                        sudo apt install nginx -y

After completing all installations, start the Nginx service and add it to the system boot.

                        systemctl start nginxsystemctl enable nginx

The Nginx service is up and running, please check with the following command.

                        systemctl status nginx

Here are the results you will get.

As a result, the Nginx service is up and running on Debian Buster 10.

In this step, we will install and configure PHP-FPM 7.3 for Drupal on Debian 10.

Use the following apt command to install PHP and PHP-FPM software package 7.3.

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

After completing all installations, go to the’/etc/php/7.3′ directory and use the vim editor to edit the configuration’php.ini’.

                        cd /etc/php/7.3/fpm/vim php.ini

Uncomment and change the detailed information configuration as shown below.

                        date.timezone = Asia/Singaporememory_limit = 256Mupload_max_filesize = 64Mmax_execution_time = 600cgi.fix_pathinfo = 0

Save and close.

Next, restart the PHP-FPM service and add it to the system boot.

                        systemctl restart php7.3-fpmsystemctl enable php7.3-fpm

The PHP-FPM service is up and running. By default, it runs under the sock file

Start php-fpm service

Use the following command to check the PHP-FPM service.

                        ss -plnt | grep phpsystemctl status php7.3-fpm

Here are the results you will get.

Check php-fpm service and sock file

As a result, PHP-FPM installation and configuration of Drupal 9 was completed on Debian Buster 10.

After installing the PHP and PHP-FPM packages, we will install the MariaDB database and create a new database for Drupal 9.

Use the following apt command to install the MariaDB package.

                        sudo apt install mariadb-server mariadb-client

After that, start the MariaDB service and add it to the system boot.

                        systemctl start mysqlsystemctl enable mysql

As a result, the MariaDB database has been installed on the Debian server.

Set MySQL root password

Next, we will use the “mysql_secure_installation” command to set the password for the default MariaDB root user, as shown below.


Enter the default root password, then enter ‘ ÿ ‘Means all options.

                        Enter current password for root (enter for none): OK, successfully used password, moving on...Set a root password? [Y/n] YRemove anonymous users? [Y/n] YDisallow root login remotely? [Y/n] YRemove test database and access to it? [Y/n] YReload privilege tables now? [Y/n] Y

And MariaDB root password has been configured.

Next, we need to access the MySQL Shell and create a new database and user for our Drupal installation.

Log in to the MySQL Shell using the default root user and your password, as shown below.

                        mysql -u root -p

Create a new database named “drupaldb” and create a user “drupaluser” with the password “”[email protected]Use the following MySQL query.

                        create database drupaldb;create user [email protected] identified by '[email protected]';grant all privileges on drupaldb.* to [email protected] identified by '[email protected]';flush privileges;

enter” Export Or press’ Ctrl + d ‘Button to exit MySQL Shell.

Create a Drupal database

As a result, a new database and users for Drupal installation have been created.

For this tutorial, we will use SSL Letsencrypt to protect the Drupal 9 installation. Therefore, please make sure that you have resolved the domain name to the server IP address.

To use SSL Letsencrypt, we need to use the certbot tool to generate an SSL certificate.

Use the following apt command to install the certbot tool.

                        sudo apt install certbot -y

After that, stop the Nginx service and use the following command to generate SSL Letsencrypt for your Drupal domain name.

                        systemctl stop nginxcertbot certonly --rsa-key-size 2048 --standalone --agree-tos --no-eff-email --email [email protected] -d

Make sure to use your own email address to make changes. After completing all the steps, your SSL certificate will be located in the “/etc/letsencrypt/live/” directory.

In this step, we will create a new Nginx virtual host configuration for Drupal.

Go to the etc/nginx/sites-available directory and use the vim editor to create a new virtual host configuration “drupal9”.

                        cd /etc/nginx/sites-available/vim drupal9

Change the domain name and path of the SSL Letsencrypt certificate yourself and paste it into it.

                        server {    server_name;    root /var/www/drupal9; ## <-- Your only path reference.    listen 80;    listen [::]:80;    listen 443 default ssl;    ssl_certificate      /etc/letsencrypt/live/;    ssl_certificate_key  /etc/letsencrypt/live/;    # Redirect HTTP to HTTPS    if ($scheme = http) {        return 301 https://$server_name$request_uri;    }    location = /favicon.ico {        log_not_found off;        access_log off;    }    location = /robots.txt {        allow all;        log_not_found off;        access_log off;    }    # Very rarely should these ever be accessed outside of your lan    location ~* .(txt|log)$ {        allow;        deny all;    }    location ~ ..*/.*.php$ {        return 403;    }    location ~ ^/sites/.*/private/ {        return 403;    }    # 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 @rewrite; # For Drupal <= 6        try_files $uri /index.php?$query_string; # For Drupal >= 7    }    location @rewrite {        rewrite ^/(.*)$ /index.php?q=$1;    }    # In Drupal 8, we must also match new paths where the '.php' appears in the middle,    # such as update.php/selection. The rule we use is strict, and only allows this pattern    # with the update.php front controller.  This allows legacy path aliases in the form of    # blog/index.php/legacy-path to continue to route to Drupal nodes. If you do not have    # any paths like that, then you might prefer to use a laxer rule, such as:    #   location ~ .php(/|$) {    # The laxer rule will continue to work if Drupal uses this new URL pattern with front    # controllers other than update.php in a future release.    location ~ '.php$|^/update.php' {        fastcgi_split_path_info ^(.+?.php)(|/.*)$;        #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini        include fastcgi_params;        include snippets/fastcgi-php.conf;        fastcgi_param SCRIPT_FILENAME $request_filename;        fastcgi_intercept_errors on;        fastcgi_pass unix:/run/php/php7.3-fpm.sock;    }    # Fighting with Styles? This little gem is amazing.    # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6    location ~ ^/sites/.*/files/styles/ { # For Drpal >= 7        try_files $uri @rewrite;    }    location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {        expires max;        log_not_found off;    }}

Save and close.

Next, activate Nginx virtual host configuration for Drupal.

                        ln -s /etc/nginx/sites-available/drupal9 /etc/nginx/sites-enabled/

Now test the Nginx configuration and make sure there are no errors, then restart the Nginx service.

                        nginx -tsystemctl restart nginx

As a result, the configuration of Drupal’s Nginx virtual host has been completed.

Setting up Nginx virtual host for Drupal

Step 6-Download Drupal

In this step, we will download the latest Drupal version 9 and install it to the “/var/www” directory.

Now go to the “/var/www” directory and use the wget command to download the Drupal source code as shown below.

                        cd /var/www/wget -q -O drupal-latest.tar.gz

Extract the drupal source code and rename the directory to “drupal9”.

                        tar -xf drupal-latest.tar.gzmv drupal-9*/ drupal9/

After that, change the ownership of the Drupal installation directory to the user’www-data’.

                        chown -R www-data:www-data /var/www/drupal9

As a result, the Drupal installation directory is located in the “/var/www/drupal9” directory.

Download Drupal 9 source code

Step 7-Drupal Post installation

Open your web browser and type your Drupal URL in the address bar to install.

You will then be redirected to a secure HTTPS connection.

Now, choose the default language for your Drupal installation. The default language is “ English language ‘.

Drupal set language

Choose your preferred language and click “ Save and continue ‘Button.

Select your Drupal installation configuration file and click “ Save and continue ‘. If you are installing Drupal for the first time, please select “ standard Installation configuration file.

Drupal installation type

For MySQL database configuration, please enter the details database created at the top and click “ Save and continue ‘Button.

Drupal installation database

You will get the following Drupal installation process.

Drupal installation process

After completing all installations, configure your site name, administrator user, password, email, etc.

Drupal site configuration

Click “ Save and continue ‘Button.

You will now be redirected to the Drupal default index page as shown below.

Drupal homepage

Click ‘ configuration On the menu, you will get the Drupal Admin configuration information center.

Drupal administrator dashboard

As a result, the installation of Drupal 9 using LEMP Stack on Debian Buster 10 has been successfully completed.


Related Posts