How to Install Drupal With Nginx on Debian 10 VPS

132
Published on April 16, 2020 by

This video shows you how to install Drupal with Nginx on Debian 10 VPS. Drupal is one of the most popular open-source CMS platforms worldwide. It is written in PHP and can be used to build different types of websites ranging from small personal blogs to large corporate, political, and government sites.

==============================
INITIAL SERVER SETUP DEBAIN 10
==============================
Login to Server:
ssh root@your_server_ip

apt update -y && apt upgrade -y

adduser debian

usermod -a -G sudo debian

Configure SSH :
nano /etc/ssh/sshd_config

Add and change the information:
Port 22500
Protocol 2
PermitRootLogin no

Add to End of File :
UseDNS no
AllowUsers debian

Save and Close

Restart SSH service:
systemctl restart ssh.service

Logout:

Ctrl+D

Login using user with sudo privilages:
ssh -p 22500 user@ip_address

==============================
INSTALL NGINX, PHP AND MARIADB
==============================
Install Nginx, MariaDB, PHP, and other PHP modules :
sudo apt install nginx php-cgi php-common php-fpm php-mysql php-gmp php-curl php-intl php-mbstring php-xmlrpc php-gd php-xml php-cli php-zip mariadb-server mariadb-client unzip wget git curl -y

Open the php.ini file:
sudo nano /etc/php/7.3/fpm/php.ini

Make the following changes:
#file_uploads = On
#allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago //optional

using sed:
sed -i "s/short_open_tag = .*/short_open_tag = On/" /etc/php/7.3/fpm/php.ini
sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.3/fpm/php.ini
sed -i "s/max_execution_time = .*/max_execution_time = 360/" /etc/php/7.3/fpm/php.ini
sed -i "s/upload_max_filesize = .*/upload_max_filesize = 128M/" /etc/php/7.3/fpm/php.ini
sed -i "s/cgi.fix_pathinfo = .*/cgi.fix_pathinfo = 0/" /etc/php/7.3/fpm/php.ini

Save and Close :
Ctrl O+X

Restart PHP-FPM service:
sudo systemctl restart php7.3-fpm.service

==============================
CONFIGURE NGINX FOR DRUPAL
==============================
Create Document Root directory:
sudo mkdir -v /var/www/linuxscoop

sudo nano /etc/nginx/sites-available/linuxscoop.cc

-----------------------------
server {
    listen 80;
    listen [::]:80;
    root /var/www/linuxscoop;
    index  index.php index.html index.htm;
    server_name  linuxscoop.cc www.linuxscoop.cc;
    
    access_log /var/log/nginx/linuxscoop_access.log;
    error_log /var/log/nginx/linuxscoop_error.log;

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

    location @rewrite {
               rewrite ^/(.*)$ /index.php?q=$1;
        }

    location ~ [^/]\.php(/|$) {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/run/php/php7.3-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
    }

    location ~ ^/sites/.*/files/styles/ {
               try_files $uri @rewrite;
        }

    location ~ ^(/[a-z\-]+)?/system/files/ {
        try_files $uri /index.php?$query_string;
        }
}
-----------------------------
sudo nginx -t
sudo ln -s /etc/nginx/sites-available/linuxscoop.cc /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service
sudo systemctl restart php7.3-fpm.service

==============================
CONFIGURE A DRUPAL DATABASE
==============================
sudo mysql_secure_installation
mysql -u root -p
CREATE DATABASE dbdrupal DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON dbdrupal.* TO 'dpuser'@'localhost' IDENTIFIED BY '5tR0n6p@s5WorD';
FLUSH PRIVILEGES;
EXIT;

==============================
INSTALL AND CONFIGURE LET'S ENCRYPT SSL CERTIFICATE
==============================
sudo apt install python3-acme python3-certbot python3-mock python3-openssl python3-pkg-resources python3-pyparsing python3-zope.interface
sudo apt install python3-certbot-nginx
sudo certbot --nginx -d linuxscoop.cc -d www.linuxscoop.cc

Renew :
sudo certbot renew --dry-run
==============================
SETTING UP FIREWALL
==============================
sudo apt install ufw
sudo ufw enable
sudo ufw app list
sudo ufw allow 22500/tcp comment 'Open port ssh tcp port 22500'
sudo ufw allow 80
sudo ufw allow 443
sudo ufw status

==============================
DOWNLOAD AND INSTALL DRUPAL
==============================
cd /tmp

wget https://ftp.drupal.org/files/projects/drupal-8.8.4.tar.gz

tar -zxvf drupal*.gz

sudo cp -a drupal-8.8.4/. /var/www/linuxscoop

sudo chown -R www-data:www-data /var/www/linuxscoop/

==============================
COMPLETE DRUPAL SETUP
==============================
Install Drupal through Web Browser

sudo nano /var/www/linuxscoop/sites/default/settings.php

Add this line to file settings.php
------------------------------
$settings['trusted_host_patterns'] = array(
  '^www\.linuxscoop\.cc$',
  '^linuxscoop\.cc$',
  );
------------------------------

cd /var/www/linuxscoop/

sudo find . -type d -exec chmod 0755 {} \;

sudo find . -type f -exec chmod 0644 {} \;
Category Tag