How to install Drupal with Nginx on Ubuntu 24.04
Installing Drupal with Nginx on Ubuntu 24.04 helps you create a very fast and capable website.
Drupal is a free and open-source tool for building websites, and Nginx is a powerful web server that handles lots of visitors well. This setup uses the latest stable Drupal, version 10, on the fresh Ubuntu 24.04 LTS.
This combination is great for busy websites that need to load quickly and stay reliable. Nginx is known for its efficient way of managing many website visitors at once.
Install Nginx using `sudo apt install nginx`, then MariaDB with `sudo apt install mariadb-server`. Create a Drupal database and user in MariaDB, and install PHP-FPM using `apt install php-fpm`. Finally, configure Drupal and Nginx.
Install Nginx HTTP server on Ubuntu
Nginx is a web server that your Drupal site needs to work. Installing Nginx on Ubuntu is straightforward using a simple command in your terminal, which prepares your server to host your Drupal website. You can install the Nginx web server by running two commands in your Ubuntu terminal: first, update your package list, then install Nginx.
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.
Install MariaDB database server on Ubuntu Linux
Drupal needs a database to store all its information, and MariaDB is a great choice for this. You can easily install MariaDB on Ubuntu Linux using a simple command, setting up the database system your Drupal site will use. Open the Ubuntu terminal and run the commands below to install the MariaDB data.
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.
- How to install MariaDB on Ubuntu Linux
- MariaDB without password prompt
Create a Drupal database
After setting up MariaDB, you need to create a specific database for Drupal to hold all its content and data. This database will be named ‘drupaldb’, and we’ll also create a user named ‘drupaldbuser’ to manage it, ensuring Drupal has its own secure place for information. This database will store the Drupal application content and data.
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.
The drupaldbuser receives full control over the drupaldb database, allowing drupaldbuser to create, modify, and delete data within 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
Install PHP-FPM on Ubuntu Linux
Drupal is built with PHP, so you need to install PHP-FPM and its essential modules on your Ubuntu Linux system for it to run correctly. This command installs PHP-FPM along with necessary extensions like intl, mysql, and curl, which Drupal requires to function properly. Run the commands below to install PHP-FPM and related modules.
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
Download Drupal files
Now, let’s get the Drupal files onto your Ubuntu server and place them where Nginx can find them. This involves downloading the latest version of Drupal. The commands provided will create a Drupal folder in the Nginx root directory and download the necessary files. The command block below will download and create a new Drupal folder in the Nginx 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.
Permissions for Drupal's web root directory **must** be changed so the Nginx HTTP server can read and write files. Set ownership to the `www-data` user and group, the user Nginx typically runs as on Ubuntu 24.04, to grant the necessary access for Drupal to function correctly.
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.
Enable the Nginx server block for your Drupal site by running the command `sudo ln -s /etc/nginx/sites-available/drupal /etc/nginx/sites-enabled/` and then restart the Nginx server using `sudo systemctl restart nginx`. This ensures Nginx recognizes and serves your new Drupal installation.
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
Securing your Drupal site with HTTPS is crucial, and Let’s Encrypt offers free SSL/TLS certificates that work well with Nginx. This helps protect your website and its visitors. You can find detailed instructions on setting up these certificates for Nginx in the linked post. Please read the post below for additional resources on installing and creating Let’s Encrypt SSL certificate.
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.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!