Along with WordPress, Drupal is another popular CMS with greater flexibility. Drupal 10 was released on Dec 2022, and it continues to be THE CMS if you plan on some complicated customized work on your website. In this article, we’ll go over step-by-step instructions to install Drupal 10 with Nginx on the latest Ubuntu 22.04 LTS.

1. Prerequisite to Install Drupal 10

I assume you have installed Nginx and properly installed the SSL certificate for your domain. Use the following command to make sure Nginx is properly running.

sudo systemctl status nginx

2. Install PHP

Like WordPress, Drupal is written in PHP. So you’ll need to install PHP, PHP-FPM and related libraries in order for Drupal to run. Use the following apt command to install them.

sudo apt update

sudo apt install php php-mysql
sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip

As of Mar 2023, the above command will install php8.1 on Ubuntu 22.04. Make sure php-fpm is properly running using systemctl.

sudo systemctl status php8.1-fpm

If you are still not sure which version was installed, use the following command to find out.

sudo systemctl status php* | grep fpm.service

3. Install PHP Composer

Some installation guide starts with downloading the Drupal zip file. It’s not wrong, but the Drupal team recommends installing Drupal through composer if possible. According to Concept: Methods for Downloading and Installing the Core Software, “If you are building a site that might use modules with complicated dependencies, you should use Composer to download the core software, because Composer will manage the dependencies properly. “

Use the following lines to download PHP composer.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

Now, you shall have composer.phar in your current directory. Then move it to the bin directory, so we can access it later.

sudo mv composer.phar /usr/local/bin/composer

If you would like to know more details about the composer, please refer to getcomposer.org.

4. Install Drupal and Dependencies

Install 7zip or unzip, as they will speed up the installation process.

sudo apt install 7zip unzip

Go to the directory, where you place the website content. Let’s assume it’s under /var/www/. Please check your Nginx’s default user. It’s usually www-data if you have not changed it.

cd /var/www/youdomain.com
sudo -u www-data composer create-project drupal/recommended-project drupal

You shall be able to see the following output if everything works as expected.

Congratulations, you’ve installed the Drupal codebase
from the drupal/recommended-project template!

Now, let’s take a look at what we have under the directory drupal.

ubuntu@myhost:/var/www/websters.co/drupal# ls
composer.json  composer.lock  vendor  web

We’ve got vendor and web directory and composer files. The directory web will be the root of your site. Let’s take a look at it.

ubuntu@myhost:/var/www/yourdomain.com/drupal/web$ ls
INSTALL.txt  autoload.php  example.gitignore  modules   robots.txt  themes      web.config
README.md    core          index.php          profiles  sites       update.php

It has index.php, robots.txt, and other standard files as in a standard web root directory.

5. Configure Nginx for Drupal

The official Nginx Drupal Recipe shows some age as Drupal 7 and 8 were mentioned there. It’s still a very good source of reference. There are essentially a few things you have to change to bridge Nginx with php-fpm for Drupal. Instead of fastcgi config in the Nginx Drupal Recipe, we’ll just use Nginx default configuration in snippets/fastcgi-php.conf.

server {
        root /var/www/websters.co/drupal/web/;

        index index.php;

        # change =404 in try_files to pass the argument to index.php
        # either $args or ?$query_string is fine, as they are the same
        location / {

                try_files $uri $uri/ /index.php?$args;

        # uncomment those lines shipped with recent Nginx default config
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

                # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/run/php/php8.1-fpm.sock;

After modifying the Nginx configuration, you’ll always need to restart the Nginx server.

sudo systemctl restart nginx

6. Install and Configure a Database

Drupal needs a database to store its data, and drupal.org recommend MySQL, MariaDB, or Percona Server. In this tutorial, we’ll use mariadb.

sudo apt install mariadb-server mariadb-client
sudo systemctl status mariadb

It’s a good practice to use the following command to make the installation secure, although it’s not mandatory.


Follow the prompt, and you may choose a root password, remove anonymous users and test the database, etc.

After you verify MariaDB is installed and running successfully, log in it using the password.

$ mysql -u root -p

Then you are under MariaDB’s prompt. Use the following commands to create a database and username for Drupal. But remember to change the username and password to yours.

MariaDB [(none)]> CREATE DATABASE db_dp_yourdomain DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
MariaDB [(none)]> CREATE USER 'dpuser'@'localhost' IDENTIFIED BY 'pwd20230314';

MariaDB [(none)]> GRANT ALL ON db_dp_yourdomain.* TO 'dpuser'@'localhost';

Then, we need to grant the privilege.


Of course, you can show databases and users to make sure they are there.

MariaDB [(none)]> SHOW DATABASES;

MariaDB [(none)]> SELECT user FROM mysql.user;

You can also verify the user has privileges over the database.

MariaDB [(none)]> SELECT * FROM mysql.db WHERE Db = 'db_dp_yourdomain'\G;

Finally, we can exit MariaDB.

MariaDB [(none)]> Exit;

7. Install Drupal 10 Site

Finally here comes the grand finale. In your browser, type in https://www.yourdomain.com. It’ll redirect to install.php.

Initial Drupal Site Installation Screen
Initial Drupal Site Installation Screen

Continue to choose the standard installation.

Installation Profile

Similarly, in the “Set up database” give the database, username, and password you just created. If you running the database on the localhost and default port, you do not need to change ‘Advanced Options’.

Database Configuration

Supply site name and site email in “Configure Site”. If you do not have a nice name yet, just put a placeholder and you can always change it in your settings later. Please also write down the username and password somewhere else for your site maintenance account.

configure site
Configure Site

Finally, you are ready to see your Drupal site.

8. Conclusion

Obviously, it’s not trivial to install Drupal 10 in your own environment. But since you choose Drupal, you expect to have some customization to your website, right? Knowing the installation process is the first step in enabling you to make your dream website.

What’s the issue you have faced during installation? Please add a comment below.

One thought on “How to Install Drupal 10 with Nginx on Ubuntu 22.04”
  1. Your nginx configuration will not work if you hit /update.php. Read the following:

    # 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;

    Reference: https://www.howtoforge.com/tutorial/debian-nginx-drupal/

Leave a Reply

Your email address will not be published. Required fields are marked *