This note will give you a detailed overview of the process of installing the latest Drupal 11 with the LNMP stack on the Debian 12 OS.
Step 1. Update the System
sudo apt update
sudo apt upgrade
Step 2. Install PHP8.3
As the latest PHP8.3 release was not contained in the default Debian repository so far, we will add a PPA repository to install the needed dependencies.
sudo apt install software-properties-common lsb-release apt-transport-https ca-certificates -y
import repository GPG key
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
enable PPA repository
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
Confirm if the repository is functional, and check available PHP versions.
sudo apt update
sudo apt list -a php
Install PHP 8.3 and extra extensions that needed for Drupal
sudo apt install php8.3 php8.3-cli php8.3-common php8.3-imap php8.3-redis php8.3-snmp php8.3-xml
php8.3-mysqli php8.3-zip php8.3-mbstring php8.3-curl php8.3-gd libapache2-mod-php php8.3-fpm
Confirm PHP 8.3 was installed properly.
php -v
check and enable php8.3-fpm for Nginx
sudo nano /etc/php/8.3/fpm/pool.d/www.conf
sudo systemctl enable php8.3-fpm
sudo systemctl start php8.3-fpm
Step 3. Install and configure MariaDB database
sudo apt install mariadb-server -y
sudo systemctl start mariadb && sudo systemctl enable mariadb
sudo mysql_secure_installation
Step 4. Create database and user for Drupal
mysql -u root -p
CREATE USER 'dp'@'localhost' IDENTIFIED BY 'yourpassword';
CREATE DATABASE drupal;
GRANT ALL PRIVILEGES ON drupal.* TO 'dp'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 5. Download and prepare Drupal package
cd /var/www/html
sudo mkdir drupal
sudo wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
sudo tar xvf drupal.tar.gz
cd drupal-11.1.0
sudo mv -f * ../drupal
cd ..
Set the rights and permissions
sudo chown -R www-data:www-data drupal/
sudo find . -type d -exec chmod 755 {} \;
sudo find . -type f -exec chmod 644 {} \;
Step 6. Install Nginx & prepare SSL certificate
sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
cd /etc/nginx/
sudo mkdir ssl
transfer your domain's SSL certificate files to /etc/nginx/ssl/
Step 7. Create Nginx Virtual Host
cd sites-enabled
sudo nano default
Modify the default Nginx virtual host file, see the following example of Drupal's Nginx virtual host file
server {
listen 80;
server_name www.yourdomain.com;
if ($host != 'www.yourdomain.com'){
return 444;
}
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name www.yourdomain.com;
if ($host != 'www.yourdomain.com'){
return 444;
}
ssl on;
ssl_certificate /etc/nginx/ssl/yourdomain.com_bundle.crt;
ssl_certificate_key /etc/nginx/ssl/yourdomain.com.key;
root /var/www/html/drupal;
access_log /var/log/nginx/www.yourdomain.com.access.log;
error_log /var/log/nginx/www.yourdomain.com.error.log;
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 404;
}
location ~ ^/sites/.*/private/ {
return 404;
}
location ~ ^/sites/[^/]+/files/.*\.php$ {
deny all;
}
location ~ (^|/)\. {
return 404;
}
location / {
try_files $uri /index.php?$query_string;
}
location @rewrite {
rewrite ^ /index.php;
}
location ~ /vendor/.*\.php$ {
deny all;
return 404;
}
location ~ '\.php$|^/update.php' {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
try_files $fastcgi_script_name =404;
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
include fastcgi_params;
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}
location ~ ^(/[a-z\-]+)?/system/files/ {
try_files $uri /index.php?$query_string;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}
if ($request_uri ~* "^(.*/)index\.php/(.*)") {
return 307 $1$2;
}
}
Validate syntax of your Nginx virtual host file.
sudo nginx -t
restart Nginx
sudo systemctl restart nginx
Step 8. Complete the Drupal installation
Check firewall status, make sure TCP port 443 was allowed.
sudo ufw status
Access https://www.yourdomain.com to complete Drupal instalation.
Comments