Drupal

How To Install Drupal with Nginx on a VPS Running Ubuntu 24.04

Welcome to the Greenhost.Cloud blog! If you’re looking to host a website using Drupal, a powerful content management system, on a virtual private server (VPS) running Ubuntu 24.04, you’ve come to the right place. In this guide, we’ll walk you through the process step-by-step, ensuring that you’ll have your Drupal site up and running quickly.

Prerequisites

Before we get started, make sure you have:

  1. A VPS running Ubuntu 24.04.
  2. Root access to your server via SSH.
  3. A domain name pointed to your server’s IP address (optional but recommended).
  4. Basic knowledge of terminal commands.

Step 1: Update Your Server

First, log in to your VPS using SSH:

ssh your_user@your_server_ip

Once logged in, ensure your package list and installed packages are up to date:

sudo apt update
sudo apt upgrade -y

Step 2: Install Required Software

To run Drupal, you need to install Nginx, PHP, and MySQL (or MariaDB). Let’s get started.

Install Nginx

sudo apt install nginx -y

Install MySQL (or MariaDB)

sudo apt install mysql-server -y

After installation, secure your MySQL setup:

sudo mysql_secure_installation

Follow the on-screen instructions to set up a root password and make other security improvements.

Install PHP and Required Extensions

Drupal requires PHP and some extensions. You can install PHP along with the required extensions by running:

sudo apt install php php-fpm php-mysql php-xml php-mbstring php-zip php-gd -y

Step 3: Configure MySQL Database for Drupal

Log in to your MySQL shell:

sudo mysql -u root -p

Then run the following commands to create a database and user for your Drupal installation:

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

Make sure to replace your_password with a strong password of your choice.

Step 4: Download and Install Drupal

Navigate to a directory where you want to download Drupal (e.g., /var/www/html/):

cd /var/www/html/

Download the latest version of Drupal:

wget https://www.drupal.org/download-latest/tar.gz

Extract the downloaded file:

tar -xvzf tar.gz

Now, remove the downloaded tar file:

rm tar.gz

Set the Correct Permissions

Change the ownership of the extracted Drupal directory:

sudo chown -R www-data:www-data /var/www/html/drupal-*

Set permissions:

sudo find /var/www/html/drupal-* -type d -exec chmod 755 {} \;
sudo find /var/www/html/drupal-* -type f -exec chmod 644 {} \;

Step 5: Configure Nginx

Create a new Nginx server block for Drupal:

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

Add the following configuration (make sure to replace your_domain.com with your actual domain):

server {
    listen 80;
    server_name your_domain.com www.your_domain.com;

    root /var/www/html/drupal-*;
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

Step 6: Enable the Nginx Configuration

Enable your new site and restart Nginx:

sudo ln -s /etc/nginx/sites-available/drupal /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Step 7: Run the Drupal Installation Wizard

Now, open your web browser and go to http://your_domain.com. You should see the Drupal installation wizard. Follow the prompts to set up your site. Enter your database details when prompted:

  • Database name: drupal_db
  • Database username: drupal_user
  • Database password: your_password

After the setup is complete, you can proceed to configure your Drupal settings.

Conclusion

Congratulations! You have successfully installed Drupal with Nginx on a VPS running Ubuntu 24.04. Now you can start building your website with Drupal’s powerful content management features.