10

Install and Configure Drupal 9 CMS on Debian 11|10

 3 years ago
source link: https://computingforgeeks.com/install-and-configure-drupal-cms-on-debian/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Install and Configure Drupal 9 CMS on Debian 11|10
Search

Drupal is a free and open-source content management system written in PHP. It is used to create and manage online content such as blogs, websites e.t.c. Drupal has over 17,000 addons/plugins to increase its functionality. it ships widgets, preinstalled themes, and other features that help one to get started with web programming, thus ideal for users with little web programming background knowledge.

The latest version of Drupal CMS is version 9 released in June 2020. This new version Drupal 9 CMS comes with the following features:

  • Backward compatibility – This simply implies that Drupal 9 is compatible with its predecessor Drupal 8.
  • A faster and better performance with m ultilingual capabilities, BigPipe, structure content and Content workflow that allow you to determine multiple workflows.
  • No deprecations
  • Windows development with ability to run on the windows web server.
  • Headless CMS that helps to build powerful front-end of websites with JavaScript framework

In this guide, we will install and configure Drupal 9 CMS on Debian 11 / Debian 10.

System Requirements.

For you to be able to install Drupal on Debian 11 / Debian 10, you will require the following.

  • PHP (the recommended versions for Drupal 9 are PHP 7.3 and above)
  • Database server – MySQL, MariaDB, PostgreSQL, Percona, SQLite e.t.c.
  • Web Server – Nginx, Apache, Caddy e.t.c

Update your system and install the required packages.

sudo apt update && sudo apt upgrade
sudo apt install wget vim

Now let’s dive in!

Step 1 – Install LAMP Stack on Debian 11/ Debian 10

In this guide, we will be using the Apache web server, PHP, and MariaDB database which can all be installed on our Debian 11/ Debian 10 system using the below APT command.

sudo apt install apache2 mariadb-server mariadb-client php libapache2-mod-php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-intl php-mbstring php-curl php-xml php-pear php-tidy php-soap php-bcmath php-xmlrpc 

Verify the installed PHP version.

$ php -v
PHP 7.4.21 (cli) (built: Jul  2 2021 03:59:48) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies

Enable mod rewrite for Apache.

sudo a2enmod rewrite
sudo systemctl restart apache2

Verify the module has been enabled.

$ sudo apache2ctl -M | grep rewrite
rewrite_module (shared)

Now that all the required packages have been installed, let’s begin by configuring our database.

Step 2 – Configure MariaDB for Drupal 9 CMS on Debian 11/ Debian 10.

Once MariaDB is installed, it is not secure, we need to harden it by setting the root password as below.

Start and enable MariaDB.

sudo systemctl enable --now mariadb

Harden MariaDB

sudo mysql_secure_installation

Proceed as below.

Enter current password for root (enter for none): Press Enter
....
Switch to unix_socket authentication [Y/n] y
.......
Change the root password? [Y/n] y
New password: Enter Password
Re-enter new password: Re-Enter Password
......
Remove anonymous users? [Y/n] y
...
Disallow root login remotely? [Y/n] y
...
...
Remove test database and access to it? [Y/n] y
....
Reload privilege tables now? [Y/n] y
.....
Thanks for using MariaDB!

Now create a database for Drupal 9 CMS on Debian 11/Debian 10

sudo mysql -u root -p

Enter the password set above and proceed to the MariaDB shell. Once in the shell, issue the below command to create a database for Drupal 9 CMS.

MariaDB [(none)]> CREATE DATABASE drupal CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

We have created a database with the name, drupal now create a database user and grant the user full access to the database.

CREATE USER drupal@localhost IDENTIFIED BY "StrongDBPassw0rd";
GRANT ALL ON drupal.* TO drupal@localhost IDENTIFIED BY "Passw0rd";
FLUSH PRIVILEGES;
QUIT

Step 3 – Download Drupal 9 CMS on Debian 11/ Debian 10.

Download the latest release version of Drupal from the Drupal release page. As of this guide, the latest available version was Drupal 9.2.7 which can also be pulled using Wget as below.

DRUPAL_VERSION="9.2.7"
wget https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz

Now that you have downloaded the archive, proceed and extract it.

tar xvf drupal-${DRUPAL_VERSION}.tar.gz

Move the extracted folder to the Apache directory at /var/www/html

sudo mv drupal-${DRUPAL_VERSION} /var/www/html/drupal

Set the permissions of the directory as below.

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

Step 4 – Create the Apache Virtual Host for Drupal 9

For the Drupal 9 site to serve, we need to create a virtual host file for Apache. Create the Virtual Host file on Debian 11/Debian 10 as below.

sudo vim /etc/apache2/sites-available/drupal.conf

In the configuration file, add the lines below replacing appropriately.

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName example.com
    DocumentRoot /var/www/html/drupal
    <Directory /var/www/html/drupal/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog /var/log/apache2/drupal_error.log
    CustomLog /var/log/apache2/drupal_access.log combined
</VirtualHost>

In the conf file, replace example.com with your domain name. Enable your site.

sudo ln -s /etc/apache2/sites-available/drupal.conf /etc/apache2/sites-enabled/drupal.conf

Restart Apache for the changes made to apply.

sudo systemctl restart apache2

Check the status of the service.

$ systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-10-22 06:16:13 EDT; 7s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 32050 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 32055 (apache2)
      Tasks: 6 (limit: 7075)
     Memory: 15.3M
        CPU: 46ms
     CGroup: /system.slice/apache2.service
             ├─32055 /usr/sbin/apache2 -k start
             ├─32056 /usr/sbin/apache2 -k start
             ├─32057 /usr/sbin/apache2 -k start
             ├─32058 /usr/sbin/apache2 -k start
             ├─32059 /usr/sbin/apache2 -k start
             └─32060 /usr/sbin/apache2 -k start

In case you cannot access the page, you might be required to move the default apache conf to a backup file as below.

sudo mv /etc/apache2/sites-enabled/000-default.conf /etc/apache2/sites-enabled/000-default.conf.bak
sudo systemctl restart apache2

Step 5 – Configure Drupal 9 CMS via the Web UI

The final step in our Drupal 9 CMS installation is setting it on the browser. On your favorite browser, access the site using the URL http://server-ip/ or http//hostname

On this page, you will be required to set your preferred language. Then proceed to the next page where you are required to select a profile from the 3 Drupal installation profiles. Here, simply go for the standard profile.

Next, configure your Drupal 9 database. Enter the credentials for the database we created earlier.

Once done, click save and continue and the Drupal 9 installation will proceed as below.

Once complete, you will be granted the below page, where you are required to provide the details for your site.

With everything done, you should be able to see this Drupal 9 welcome page.

That is it! From here, you are set to create blog websites with various templates provided.

Click add content and choose the type of content to add either an article or a basic page.

You can also customize your Drupal 9 appearance as below.

Step 6 – (Optional) Secure Drupal 9 CMS with Let’s Encrypt SSL

Accessing the site using HTTP is normally not secure and you might need to secure it to be able to access the site using HTTPS. In this guide, we will use Let’s Encrypt is to issue trusted SSL certificates for our FQDN. Before proceeding, ensure that you have an FQDN.

Install Certbot on Debian 11/10 as below.

sudo apt install certbot python3-certbot-apache2

Configure your apache configuration by adding the lines below at the bottom.

$ sudo vim /etc/apache2/sites-available/drupal.conf
........
<VirtualHost *:443>
    ServerName example.com
ServerAdmin [email protected]
    DocumentRoot /var/www/html/drupal
    <Directory /var/www/html/drupal/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog /var/log/apache2/drupal_error.log
    CustomLog /var/log/apache2/drupal_access.log combined
</VirtualHost>

Restart apache.

sudo systemctl restart apache2

Now install trusted certificates on Debian 11/10 as below.

sudo certbot --apache

Proceed as below.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): Enter a valid Email address here          

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
Account registered.

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1

Requesting a certificate for bitwarden.example.com
Performing the following challenges:
http-01 challenge for example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/apache2/sites-available/drupal.conf
Redirecting all traffic on port 80 to ssl in /etc/apache2/sites-available/drupal.conf

Successfully received certificate.
Certificate is saved at: a2enmod ssl
/etc/letsencrypt/live/example.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/example.com/privkey.pem
This certificate expires on 2022-01-09.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

With the certificates installed, your apache conf file should be as below.

$ sudo cat /etc/apache2/sites-available/drupal.conf
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName example.com
    DocumentRoot /var/www/html/drupal
    <Directory /var/www/html/drupal/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog /var/log/apache2/drupal_error.log
    CustomLog /var/log/apache2/drupal_access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
    ServerName example.com
ServerAdmin [email protected]
    DocumentRoot /var/www/html/drupal
    <Directory /var/www/html/drupal/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog /var/log/apache2/drupal_error.log
    CustomLog /var/log/apache2/drupal_access.log combined 
SSLCertificateFile /etc/letsencrypt/live/pw.hirebestengineers.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/pw.hirebestengineers.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

Now you can proceed and access your Drupal site using HTTPS with the URL https://hostname.

My site is secure as symbolized with a “padlock icon“.

Conclusion.

That marks the end of this guide on how to install and configure Drupal 9 CMS on Debian 11 / Debian 10. I hope this guide was significant.

See more on this page:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK