Install Drupal with Nginx and PHP 8.5 on Ubuntu 26.04

Although Drupal has a much smaller market share than WordPress, it is still the preferred CMS for many enterprises and government organisations. Drupal is known for its flexibility, extensibility, developer focus architecture and granular control. Organisations such as Tesla, Pfizer, and numerous government agencies use Drupal for large-scale websites. With Drupal, you can customise almost every aspect of your website to suit your requirements. We will discuss how Drupal is different from WordPress later but in this post I will guide you to install Drupal with Nginx and PHP 8.5 on Ubuntu 26.04 with Let’s Encrypt SSL.

Let me make one thing very clear, If you’re launching a new project and deciding between WordPress and Drupal, Drupal is generally the better choice only if you have experienced developers who can build and maintain it. Otherwise, WordPress is usually easier to manage.

So let’s get going

Prerequisites

  • A server with Ubuntu 26.04 installed
  • A user with sudo privileges

Step 1 – Update the system

Like always, we will first update our system so that all the packages will be up to date

sudo apt update -y
sudo apt upgrade -y

Step 2 – Install Nginx

In this step, we’ll install Nginx, which will serve as the web server for Drupal.

sudo apt install nginx -y

Step 3 – Install and Setup MariaDB

Next step is to install and setup MariaDB for our database

sudo apt install mariadb-server mariadb-client -y

Now let’s setup MariaDB

sudo mariadb-secure-installation

Enter the given below details

Enter current password for root (enter for none): (Just hit enter key)
Switch to unix_socket authentication [Y/n]: (Press N and hit enter key)
Change the root password? [Y/n]: (Press Y and hit enter key)
Enter New Password:
Confirm New Password: 
Note:- Make sure to enter a strong and memorable password here

Remove anonymous users? [Y/n]: (Press Y and hit enter key)
Disallow root login remotely? [Y/n]: (Press Y and hit enter key)
Remove test database and access? [Y/n]: (Press Y and hit enter key)
Reload privilege tables now? [Y/n]: (Press Y and hit enter key)

Now let’s create database and a user who will have access to the database

sudo mysql -u root -p

Now enter the password you have set for root above

Execute the given below scripts one by one

CREATE DATABASE drupal_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'drupal_user'@'localhost' IDENTIFIED BY 'SecurePassword';
GRANT ALL PRIVILEGES ON drupal_db.* TO 'drupal_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Note:- Make sure to change the given below details as per your need and also keep a note of these details

“drupal_db” – This is the name of your Drupal database. You can change it as per your wish
“drupal_user” – This is the user name of your database user who will have access to your database. You can change it as per your wish
“SecurePassword” – This is database’s password. Change it to something stronger

With this, our database is ready.

Step 4 – Install PHP 8.5

Ubuntu 26.04 includes PHP 8.5 in its default repositories, so we only need to install the required PHP extensions.

sudo apt install php8.5-fpm php8.5-cli php8.5-mysql php8.5-gd php8.5-imagick php8.5-bcmath php8.5-curl php8.5-xml php8.5-mbstring php8.5-zip php8.5-opcache php8.5-intl -y

sudo systemctl restart php8.5-fpm

Step 5 – Download and Prepare Drupal

Now let’s download and prepare our Drupal configuration

cd /var/www/html/
sudo curl -sSL https://www.drupal.org/download-latest/tar.gz -o drupal.tar.gz
sudo tar -xzvf drupal.tar.gz
sudo mv drupal-* drupal

Now let’s assign correct permission to drupal folder

sudo mkdir -p /var/www/html/drupal/sites/default/files
sudo chown -R www-data:www-data /var/www/html/drupal/sites/default/files
sudo find /var/www/html/drupal -type d -exec chmod 755 {} \;
sudo find /var/www/html/drupal -type f -exec chmod 644 {} \;

Step 6 – Configure Nginx

Now let’s setup our Nginx. Let’s first create a configuration file and link it to sites-enabled folder

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

Copy and paste the following

server {
    listen 80;
    listen [::]:80;

    server_name your_domain.com www.your_domain.com;
    root /var/www/html/drupal;
    index index.php;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

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

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

    location ~ ^/sites/[^/]+/files/composer/ {
        return 403;
    }

    location ~* ^.+\.(markdown|md|txt|cfg|pl|py|sh|swp|bak|php~)$ {
        return 403;
    }

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

    location @rewrite {
        rewrite ^ /index.php;
    }

    location ~ \.php$|^/update\.php$ {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php/php8.5-fpm.sock;
    }

    location ~* ^/sites/.*/files/styles/ {
        try_files $uri @rewrite;
    }

    location ~* ^/system/files/ {
        try_files $uri @rewrite;
    }

    location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|eot|otf|woff|woff2)$ {
        expires max;
        access_log off;
    }
}

Note:- Make sure to change “your_domain” to your real domain name

Press Ctrl+X, then Y, and finally Enter.

Now let’s link our nginx configuration file to sites-enabled folder

sudo ln -s /etc/nginx/sites-available/drupal /etc/nginx/sites-enabled/
sudo unlink /etc/nginx/sites-enabled/default
sudo nginx -t

If the configuration is correct, Nginx will display messages indicating that the syntax test was successful.

sudo systemctl restart nginx

Step 7 – Setup Let’s Encrypt SSL

let’s secure our website with Let’s Encrypt SSL.

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d your_domain.com -d www.your_domain.com

Note: Make sure to change your_domain to your real domain name

Enter your email address when prompted and accept the terms and conditions shown with Y

Step 8 – Update firewall

Final step is to update our firewall to allow nginx traffic

sudo ufw allow OpenSSH
sudo ufw allow "Nginx Full"
sudo ufw enable

Step 9 – Complete Drupal Setup

Now let’s complete our Drupal setup with the web-based interface. On any browser, go to your_domain.com and follow the steps below

Choose language
Select Standard installation profile
Enter the database name, username, and password that you created in Step 3.

Database name: drupal_db
Database username: drupal_user
Database password: SecurePassword

Now enter the rest of the details like username, regional settings and site name and finalise the installation.

Conclusion

Congratulations! You have successfully installed Drupal with Nginx, PHP 8.5, MariaDB, and a free Let’s Encrypt SSL certificate on Ubuntu 26.04. Your server is now ready to host Drupal websites securely. From here, you can start installing themes, enabling modules, and configuring your site according to your requirements.

Leave a Comment

Sourabh Verma

Hi, I'm Sourabh Verma, an IT professional with 12+ years of experience. At BeginnersBox, I share practical, well-tested how-to guides on Windows, Linux, WordPress, web hosting, and other tech topics. My goal is to provide simple, reliable solutions that actually work. Hope you like my work. Thanks

Discover more from BeginnersBox

Subscribe now to keep reading and get access to the full archive.

Continue reading