16.6 C
Jaipur
Wednesday, December 1, 2021

How to Install Drupal with Apache and Let’s Encrypt SSL on Debian 11

Must read

Drupal is a free and open-source content management system based on the LAMP stack. Drupal has great standard features that allow you to create powerful websites and blogs. It comes with a lot of themes, plugins, and widgets that help you to create a website without any programming knowledge. It provides a lot of features such as multi-site support, multi-language support, comment system, RSS feed, user registration, and more.

In this post, we will show you how to install Drupal CMS with Apache and Let’s Encrypt SSL on Debian 11.

Prerequisites

  • A server running Debian 11.
  • A valid domain name pointed with your server IP.
  • A root password is configured on the server.

Install LAMP Stack

Drupal is based on LAMP stack. So the LAMP stack must be installed in your server. If not installed, you can install it by running the following command:

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

Once the LAMP stack is installed, edit the php.ini file and change some default settings:

nano /etc/php/7.4/apache2/php.ini

Change the following lines:

memory_limit = 256M
upload_max_filesize = 32M
max_execution_time = 300
date.timezone = Asia/Kolkata

Save and close the file when you are finished.

Create a Drupal Database

Drupal uses a MariaDB as a database backend. So you will need to create a database and user for Drupal.

First, log in to MariaDB with the following command:

mysql

Once you are log in, create a database and user using the following command:

MariaDB [(none)]> CREATE DATABASE drupaldb;
MariaDB [(none)]> CREATE USER 'drupaluser'@'localhost' IDENTIFIED BY "securepassword";

Next, grant all the privileges to the Drupal database using the following command:

MariaDB [(none)]> GRANT ALL ON drupaldb.* TO 'drupaluser'@'localhost' IDENTIFIED BY "securepassword";

Next, flush the privileges and exit from the MariaDB with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Download Drupal

First, go to the Drupal website pick the latest version of Drupal and download it with the following command:

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

Once the Drupal is downloaded, extract the downloaded file with the following command:

tar -xvf drupal.tar.gz

Next, move the extracted directory to the Apache default root directory:

mv drupal-* /var/www/html/drupal

Next, change the ownership and permission of the Drupal directory using the following command:

chown -R www-data:www-data /var/www/html/drupal/
chmod -R 755 /var/www/html/drupal/

Create an Apache Virtual Host for Drupal

Next, you will need to create an Apache virtual host configuration file to host Drupal. You can create it using the following command:

nano /etc/apache2/sites-available/drupal.conf

Add the following lines:

<VirtualHost *:80>
     ServerAdmin [email protected]
     DocumentRoot /var/www/html/drupal/
     ServerName  drupal.example.com  

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

     <Directory /var/www/html/drupal/>
            Options FollowSymlinks
            AllowOverride All
            Require all granted
     </Directory>

     <Directory /var/www/html/>
            RewriteEngine on
            RewriteBase /
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    </Directory>
</VirtualHost>

Save and close the file then enable the Drupal virtual host and Apache rewrite module with the following command:

a2ensite drupal.conf
a2enmod rewrite

Next, restart the Apache service to apply the changes:

systemctl restart apache2

To check the status of the Apache, run the following command:

systemctl status apache2

You should get the following output:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-09-18 14:59:40 UTC; 5s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 19698 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 19703 (apache2)
      Tasks: 6 (limit: 2341)
     Memory: 15.3M
        CPU: 78ms
     CGroup: /system.slice/apache2.service
             ??19703 /usr/sbin/apache2 -k start
             ??19704 /usr/sbin/apache2 -k start
             ??19705 /usr/sbin/apache2 -k start
             ??19706 /usr/sbin/apache2 -k start
             ??19707 /usr/sbin/apache2 -k start
             ??19708 /usr/sbin/apache2 -k start

At this point, the Apache webserver is configured to serve Drupal. You can now proceed to the next step.

Access Drupal Website

Now, open your web browser and access Drupal using the URL http://drupal.example.com. You will be redirected to the following page:

Choose the English language and click on the Save and Continue button, you should see the following image:

Installation profile

Select an Installation Profile and click on the Save and Continue button. You should see the following page:

Database configuration

In the Database Configuration page, provide all the required database details like database name, database username, and password, database host, then click on the Save and Continue button, you should see the following image:

Site information

Regional settings

In the Drupal Site Configuration page, provide your site name, admin username and password then click on the Save and Continue button to start installing Drupal. Once Drupal is installed, you should see the Drupal dashboard in the following image:

Login to Drupal

Enable Let’s Encrypt SSL Support on Drupal Website

It is always a good idea to secure your website with Let’s Encrypt SSL. First, you will need to install the Certbot client to install and manage the SSL. By default, the Certbot package is included in the Debian 11 default repository so you can install it with the following command:

apt-get install python3-certbot-apache -y

Once the Certbot is installed, run the following command to secure your website with Let’s Encrypt SSL:

certbot --apache -d drupal.example.com

You will be asked to provide your email and accept the term of service as shown below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing 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
Plugins selected: Authenticator apache, Installer apache
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for drupal.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/drupal-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/drupal-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/drupal-le-ssl.conf

Next, select whether or not to redirect HTTP traffic to HTTPS as shown below:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Type 2 and hit Enter to install the Let’s Encrypt SSL for your website:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/drupal.conf to ssl vhost in /etc/apache2/sites-available/drupal-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://drupal.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=drupal.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/drupal.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/drupal.example.com/privkey.pem
   Your cert will expire on 2021-04-20. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - 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

Conclusion

That’s it for now. You have successfully installed Drupal with Let’s Encrypt SSL on Debian 11. You can now start creating your own blog or website without any programming knowledge. Feel free to ask me if you have any questions.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -

Latest article