This article explains how to install Drupal with Nginx support on Ubuntu 24.04.
Drupal, a popular content management system, and Nginx, a high-performance web server known for its scalability and speed, can be installed with Nginx support on Ubuntu. This installation allows you to take advantage of Nginx’s efficient handling of web requests, leading to improved performance and a significantly better user experience.
Moreover, Nginx’s ability to handle high traffic levels makes it an excellent choice for hosting Drupal websites that expect a lot of visitors. Combining Drupal with Nginx on Ubuntu not only enhances performance but also ensures a secure and reliable web environment, thereby adding value to your projects.
The steps below walk you through installing Drupal with Nginx support and Let’s Encrypt a free SSL certificate on Ubuntu.
Install Nginx HTTP server on Ubuntu
Drupal is a web application that requires a web server. For this post, we will install and use the Nginx HTTP server to run Drupal.
To do that, open the Ubuntu terminal and run the commands below to install the Nginx web server.
sudo apt update
sudo apt install nginx
Once Nginx is installed, the commands below can start, stop, and enable the Nginx web server to start automatically when your server boots up.
sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl enable nginx
You can test that the Nginx HTTP server is running by opening your web browser and browsing to the server’s localhost or IP address.
http://localhost

When you see the Welcome to nginx! page, it means the Nginx HTTP server is successfully installed.
Additional help on installing Nginx on Ubuntu is in the link below.
How to install Nginx on Ubuntu
Install MariaDB database server on Ubuntu Linux
The next component that is required to run Drupal is a database server. This post will install and use the MariaDB database server to run Drupal.
To install and use the MariaDB database server, use the instructions below.
Open the Ubuntu terminal and run the commands below to install the MariaDB database server.
sudo apt update sudo apt install mariadb-server
Once the MariaDB database server is installed, use the commands below to stop, start, and enable the MariaDB server to start automatically when the server boots.
sudo systemctl stop mariadb sudo systemctl start mariadb sudo systemctl enable mariadb
Run the following commands to validate and test if the MariaDB database server is installed successfully.
sudo mariadb
Once you run the commands above, it will log you onto the MariaDB console and display a message similar to the one below.
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 32 Server version: 10.11.2-MariaDB-1 Ubuntu 23.04 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
The message tells you that the server is installed successfully.
Additional help on installing MariaDB.
Create a Drupal database
After installing the MariaDB database server, you should create a blank database for the Drupal application on the server.
This database will store the Drupal application content and data.
We will create a database called drupaldb. We will also create a database user account called drupaldbuser.
Finally, we’ll grant the drupaldbuser full access to the drupaldb database.
All the database steps above can be done using the commands below:
But first, log on to the MariaDB database server:
sudo mariadb
Then run the commands below to complete the steps:
CREATE DATABASE drupaldb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER drupaldbuser@localhost IDENTIFIED BY 'type_your_password_here';
GRANT ALL ON drupaldb.* TO drupaldbuser@localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
Ensure to replace ‘type_your_password_here‘ with your password.
Install PHP-FPM on Ubuntu Linux
The last component you will need to run Drupal is PHP. The Drupal application is a PHP-based application. It supports the latest versions of PHP-FPM.
Run the commands below to install PHP-FPM and related modules.
sudo apt install php-fpm php-intl php-mysql php-curl php-cli php-zip php-gd php-common php-mbstring php-xml php-opcache php-readline php-sqlite3 php-zip php-apcu
Additional help on installing PHP
How to install PHP on Ubuntu Linux
Download Drupal files
We are ready to download and configure the Drupal files on Ubuntu Linux. Run the commands below to download and extract the Drupal files to the Nginx web server root directory.
The command block below will download and create a new Drupal folder in the Nginx root directory.
First, create a Drupal folder in the Nginx root directory.
Please change it to the /tmp directory and download Drupal files. Unzip the file and move the content into the created Drupal folder.
Finally, the permissions should be changed to allow the Nginx HTTP server to interact with the files.
sudo mkdir -p /var/www/drupal
cd /tmp/
wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
tar -xvf drupal.tar.gz
sudo mv drupal-*/* /var/www/drupal
sudo chown -R www-data:www-data /var/www/drupal/
sudo chmod -R 755 /var/www/drupal/
Once you have completed all the above steps, continue below to configure the Nginx web server to serve the Drupal content.
Run the commands below to create a Nginx server block file for Drupal.
sudo nano /etc/nginx/sites-available/drupal.conf
Then, copy and paste the content block below into the Nginx server block.
server {
listen 80;
server_name drupal.example.com;
root /var/www/drupal;
index index.php;
location / {
try_files $uri /index.php?$query_string;
}
location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}
location ~ '\.php$|^/update.php' {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* /sites/.*/files/styles/ {
try_files $uri @rewrite;
}
location ~ ^/sites/.*/files/ {
try_files $uri @rewrite;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}
}
Ensure the highlighted PHP version in the file matches the PHP version installed. When you’re done, save the file.
Then, run the commands below to enable the server block and restart the Nginx server.
sudo ln -s /etc/nginx/sites-available/drupal.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx
Setup Let’s Encrypt SSL/TLS for Drupal
You may want to install an SSL/TLS certificate to secure your Drupal site. Secure your Drupal installation with HTTPS from Let’s Encrypt.
Please read the post below for additional resources on installing and creating Let’s Encrypt SSL certificates for Nginx.
How to set up Let’s Encrypt SSL certificate for Nginx on Ubuntu Linux
After installing, the Nginx server block file /etc/nginx/sites-available/drupal.conf will automatically be configured with HTTPS, done by the Certbot Nginx plugin.
Once you have restarted the Nginx web server, open your browser and browse to the server hostname or IP address defined in the Nginx server block.
http://drupal.example.com
A new Drupal installation wizard will appear. Choose the site’s language and continue.

Next, select the installation profile.

Next, confirm all requirements are met and continue.
Then, type in the database name, username, and password created above.

Finally, set up your site name and create an admin account to login in.

Your new Drupal site should be created and ready to use.

That should do it!
Conclusion:
- Setting up a Drupal site with Nginx support on Ubuntu enhances performance and user experience.
- Nginx’s efficient web request handling and high traffic tolerance make it an excellent choice for hosting Drupal websites.
- The combination of Drupal with Nginx on Ubuntu ensures a secure and reliable web environment, adding value to your projects.
- Securing the Drupal installation with the Let’s Encrypt SSL/TLS certificate further enhances the website’s security and trustworthiness.
- The detailed steps in this article guide you through seamlessly installing and configuring each component, resulting in a fully functional Drupal site ready for use.
Leave a Reply