Drupal is a free and open-source web content management system written in PHP and distributed under GNU General Public License. Drupal provides a robust content management tool with sophisticated APIs for multichannel publishing.

Drupal is one of the most widely used CMS on the internet, used by at least 14% of the top 10,000 websites on the internet, and it’s used for global enterprise industries, governments, education, and institutions sites. Drupal provides a high-scalable system, integrated with digital applications, and can be used to create multisite for different organizations with multilingual support.

In this guide, I will show you how to install Drupal on a Debian 12 server. We’ll install Drupal on the LAMP Stack (Apache2, MariaDB, and PHP) and secure Drupal with SSL/TLS certificates from Letsencrypt.

Prerequisites

To begin, check that you have the following:

  • A Debian 12 server.
  • A non-root user with administrator privileges.
  • A domain name pointed to your server IP address.

Installing Dependencies

Drupal is an open-source content management system written in PHP with MySQL/MariaDB as the database. To install Drupal, you must install both PHP and MySQL/MariaDB packages to your system.

In the following step, you will install package dependencies for Drupal, including the LAMP Stack (Apache2, MariaDB, and PHP), Composer PHP dependency manager, and some additional PHP extensions.

First, run the following apt command to update and refresh your Debian package index.

sudo apt update

Once updated, install package dependencies by executing the command below. With the following command, you will install the LAMP Stack package (Apache2, MariaDB, and PHP), Composer PHP dependency manager, and additional PHP extensions that are required by Drupal.

sudo apt install apache2 mariadb-server composer php php-apcu php-dev libapache2-mod-php libcurl4-openssl-dev 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

Type y to proceed with the installation.

<img alt="install dependencies" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/1-install-deps.png653294037f4ee.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="137" loading="lazy" src="data:image/svg xml,” width=”750″>

After dependencies are installed, verify each dependency to ensure that the installation is successful.

Verify the apache2 service using the following command. This will ensure that the apache2 service is running and enabled.

sudo systemctl is-enabled apache2

sudo systemctl status apache2

The displayed output will reveal that the apache2 service is running and enabled.

<img alt="check apache2" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/2-verify-apache2.png65329403b014f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="232" loading="lazy" src="data:image/svg xml,” width=”750″>

Now verify the mariadb service by executing the following command.

sudo systemctl is-enabled mariadb

sudo systemctl status mariadb

The output should be similar to this:

<img alt="check mariadb" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/3-verify-mariadb.png65329403e37c7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="251" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, verify the location of the Composer binary file and the installed version using the command below.

which composer

sudo -u www-data composer -v

The output confirms that Composer 2.5 is installed at /usr/bin/composer.

<img alt="check composer" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/4-check-copmposer.png653294041acfc.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="297" loading="lazy" src="data:image/svg xml,” width=”489″>

Lastly, verify the PHP version and PHP-enabled modules using the command below.

php -v

php -m

PHP 8.2 should be installed on your Debian machine and default PHP extensions should be enabled.

<img alt="check php" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/5-check-php.png6532940456c26.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="461" loading="lazy" src="data:image/svg xml,” width=”606″>

Configuring MariaDB Server

With all dependencies installed, the next step is to secure your MariaDB server installation and create a new database and user that will be used by Drupal. You will secure MariaDB via the mariadb-secure-installation utility, then you will create a new database and user via the mariadb client command line.

Execute the mariadb-secure-installation command below to secure your MariaDB server.

sudo mariadb-secure-installation

During the process, you will be asked about the following configurations:

  • The default MariaDB installation comes without a password, press ENTER when prompted for the password.
  • Now input Y to set up the MariaDB root password. Then, type the new password for MariaDB and repeat the password.
  • Input Y to remove the anonymous user from your MariaDB installation.
  • Input Y again when prompted to disable the remote login for the MariaDB root user.
  • Input Y to remove the default database test from your MariaDB.
  • Lastly, input Y to reload table privileges and apply new changes.

Next, log in to the MariaDB server by executing the mariadb command below. Input your mariaDB root password when prompted.

sudo mariadb -u root -p

Once logged in, execute the following queries to create a new database drupaldb and user drupal on your MariaDB server. Be sure to change the password with your password.

CREATE DATABASE drupaldb;

CREATE USER drupal@localhost IDENTIFIED BY 'password';

GRANT ALL ON drupaldb.* TO drupal@localhost WITH GRANT OPTION;

FLUSH PRIVILEGES;

<img alt="create database user" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/6-create-database-user.png6532940479a2c.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="251" loading="lazy" src="data:image/svg xml,” width=”743″>

Lastly, run the following query to verify and ensure that the user drupal can access the database drupaldb.

SHOW GRANTS FOR drupal@localhost;

The displayed output below confirms that user drupal can access the database drupaldb for Drupal installation.

<img alt="verify database user" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/7-verify-database-user.png65329404a3c3b.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="260" loading="lazy" src="data:image/svg xml,” width=”750″>

Configuring PHP

After configuring the MariaDB server, you will configure PHP for Drupal installation by:

  • Installing Uploadprogress Extension via PECL (PHP Extension Community Library).
  • Editing php.ini file.

Let’s begin.

Installing Uploadprogress Extension via PECL

The uploadprogress extension is used to show and track the upload progress of files, which includes upload speed and estimated time remaining. The uploadprogress extension is available on PECL, which needs to be installed manually via the pecl command line.

Execute the following pecl command to install uploadprogress to your Debian system.

sudo pecl install uploadprogress

The uploadprogress installation should begin.

<img alt="install uploadprogress" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/8-install-uploadprogress-pecl.png65329404de4bf.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="427" loading="lazy" src="data:image/svg xml,” width=”750″>

After the installation is finished, execute the command below to uploadprogress the extension to your PHP installation. This will create a new PHP extension configuration /etc/php/8.2/mods-available/uploadprogress.ini.

cat <<EOF | sudo tee /etc/php/8.2/mods-available/uploadprogress.ini

; configuration for php uploadprogress module

; priority 15

extension=uploadprogress.so

EOF

Lastly, execute the following command to enable the uploadprogress extension on your PHP installation.

sudo ln -s /etc/php/8.2/mods-available/uploadprogress.ini /etc/php/8.2/apache2/conf.d/15-uploadprogress.ini

<img alt="enable uploadprogress" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/9-enable-uploadprogress-extension.png65329405184ca.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="161" loading="lazy" src="data:image/svg xml,” width=”750″>

Editing php.ini File

Open the default php.ini configuration /etc/php/8.2/apache2/php.ini using the following nano editor command.

sudo nano /etc/php/8.2/apache2/php.ini

Change the default PHP configuration with the following. Be sure to adjust the memory_limit and date.timezone options with your server environment.

memory_limit = 512M

upload_max_filesize = 60M

max_execution_time = 300

date.timezone = Europe/Amsterdam

Save and exit the file when you’re done.

Next, run the systemctl command below to restart the apache2 service and apply the changes that you’ve made.

sudo systemctl restart apache2

Then, run the following command to create a new PHPINFO file /var/www/html/info.php and verify your PHP configuration.

cat <<EOF | sudo tee /var/www/html/info.php

<?php

phpinfo();

?>

EOF

Launch your web browser and visit your server IP address, such as http://192.168.10.15/info.php. If your PHP configuration is successful, you should see the PHPINFO page like the following:

<img alt="phpinfo" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/10-phpinfo.png6532940573a13.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="631" loading="lazy" src="data:image/svg xml,” width=”750″>

Downloading Drupal Source Code

After configuring the MariaDB server and PHP installation, you will download the Drupal source code and install its PHP dependencies via Composer. In this case, you will download the latest version of Drupal.

Move your working directory /var/www and download Drupal via the wget command below. The Drupal source code will be available at drupal.tar.gz file.

cd /var/www/

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

Extract the file drupal.tar.gz via the tar command below. Then, rename the extracted directory to drupal, which means that the web root directory for Drupal will be /var/www/drupal.

tar -xvf drupal.tar.gz

mv drupal-* /var/www/drupal

Lastly, run the following command to change the permission and ownership of the Drupal web root directory /var/www/drupal. This directory will be owned by user www-data with permission 755.

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

sudo chmod -R 755 /var/www/drupal/

Configuring Apache2 Virtual Host

Now that you’ve downloaded Drupal and configured the web root directory to /var/www/drupal, the next step is to create a new Apache2 virtual host configuration that will be used to run Drupal. Before going further, ensure that you have the domain name pointed to your server IP address.

First, run the following command to enable some Apache2 modules that are required for Drupal.

sudo a2enmod rewrite ssl headers deflate

<img alt="enable apache2 modules" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/11-enable-apache2-modules.png65329405aaaab.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="369" loading="lazy" src="data:image/svg xml,” width=”560″>

Then, create a new virtual host configuration /etc/apache2/sites-available/drupal.conf using the following nano editor command.

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

Insert the following configuration and be sure to change the ServerName option with your domain name.

    ServerName hwdomain.io

    ServerAdmin [email protected]

    DocumentRoot /var/www/drupal

    # Add security

    php_flag register_globals off

    ErrorLog ${APACHE_LOG_DIR}/hwdomain.io.error.log

    CustomLog ${APACHE_LOG_DIR}/hwdomain.io.access.log combined

   

      SSLOptions StdEnvVars

   

   

        Options FollowSymlinks

        #Allow .htaccess

        AllowOverride All

        Require all granted

       

            SecRuleEngine Off

            # or disable only problematic rules

       

   

   

        RewriteEngine on

        RewriteBase /

        RewriteCond %{REQUEST_FILENAME} !-f

        RewriteCond %{REQUEST_FILENAME} !-d

        RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

   

When finished, save and close the file.

Next, run the following command to activate the virtual host file drupal.conf and verify your Apache2 syntax.

sudo a2ensite drupal.conf

sudo apachectl configtest

If you have proper Apache2 syntax, the output Syntax OK will be displayed.

<img alt="setup vhost" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/12-setup-virtual-hosts.png65329405df591.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="248" loading="lazy" src="data:image/svg xml,” width=”636″>

Now restart the apache2 service using the below command to apply the changes that you’ve made.

sudo systemctl restart apache2

Generating SSL/TLS Certificates Letsencrypt for Drupal

In the following step, you will secure your Drupal installation with SSL/TLS certificates from Letsencrypt. To achieve that, you must install Certbot and Certbot Apache plugin to your Debian system, then generate SSl/TLS certificates for your Drupal domain name.

Install Certbot and Certbot APache plugin using the following apt install command. Type y to proceed with the installation.

sudo apt install certbot python3-certbot-apache

<img alt="install certbot" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/13-install-certbot.png653294061956e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="398" loading="lazy" src="data:image/svg xml,” width=”663″>

Next, run the certbot command below to generate SSL/TLS certificates for your Drupal site. Be sure to change the email address and domain name in the following command.

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d hwdomain.io

Once the process is finished, your SSL/TLS certificates will be available in the /etc/letsencrypt/live/domain.com directory. Your Drupal installation is automatically configured with HTTPS, which is configured via the Certbot Apache plugin.

Installing Drupal via Web Installer

Launch your web browser and visit the domain name of your Drupal site, such as http://hwdomain.io/. If everything goes well, you should be redirected to HTTPS connections and the Drupal installation page will be shown.

Select the default language that will be used for Drupal installation and click Save and continue.

<img alt="choose language" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/14-choose-language.png6532940666b6e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="395" loading="lazy" src="data:image/svg xml,” width=”750″>

Select the Drupal installation profile that you want to use. The Standard profile is recommended for the new site owner, while Minimal requires an in-depth understanding of Drupal. Or you can also choose a profile with Demo.

The following example will be using the Standard profile, then click Save and continue.

<img alt="select installation profile" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/15-select-installation-profile.png65329406ba5d0.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="410" loading="lazy" src="data:image/svg xml,” width=”750″>

Now the Drupal web installer will verify your system environment for Drupal installation. You should be redirected to the database configuration if your server meets Drupal requirements.

Input details of your MariaDB database name, user, and password that Drupal will use. Then, click Save and continue again.

<img alt="database configuration" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/16-database-settings.png6532940706cf6.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="576" loading="lazy" src="data:image/svg xml,” width=”750″>

After configuring the database, the Drupal installation should begin.

<img alt="installation begin" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/17-installation.png653294074f581.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="400" loading="lazy" src="data:image/svg xml,” width=”750″>

Once the installation process is finished, configure your Drupal site. Input details of the Site name, Site email address, administrator username, password, default country, and timezone. Then, click Save and continue.

<img alt="site configuration" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/18-site-configuration.png65329407aa64e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="593" loading="lazy" src="data:image/svg xml,” width=”750″>

If your Drupal installation is successful, the output “Congratulations, you installed Drupal!” should be displayed on your screen.

<img alt="drupal installed" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/19-drupal-installed.png653294081639f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="472" loading="lazy" src="data:image/svg xml,” width=”750″>

From there, you can manage your Drupal content, site structures, and Drupal administration, and check the status of your Drupal installation. Click Manage and select the Configuration menu to configure your Drupal installation.

<img alt="site configuration" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/23-site-configuration.png6532940d2d9d0.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="496" loading="lazy" src="data:image/svg xml,” width=”750″>

Additional Configuration for Drupal

To complete this guide, you will add some additional configuration to your Drupal.

First, back to your terminal server and run the following command to change the permission of the settings.php file and open it with the nano editor.

sudo chmod 644 /var/www/drupal/sites/default/settings.php

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

Find the “trusted_host_patterns” section and input the domain name of your Drupal installation the following.

$settings['trusted_host_patterns'] = [

  '^hwdomain.io$',

];

Save and close the file when you’re done.

Now run the following command to revert back the permission of the settings.php file to 444.

sudo chmod 444 /var/www/drupal/sites/default/settings.php

Next, select the Reports menu and click Status Reports.

<img alt="status reports" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/21-status-reports.png6532940d64dae.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="319" loading="lazy" src="data:image/svg xml,” width=”750″>

You should see detailed information about your Drupal installation. In the following screenshot, Drupal 10 is installed with Apache2 web server 2.4, MariaDB server 10.11, and PHP 8.2.

<img alt="status report drupal" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/20-status-reports-drupal.png6532940dc7958.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="507" loading="lazy" src="data:image/svg xml,” width=”750″>

Now click the Details link on the status report, and you will be shown the details report of your Drupal server environment.

<img alt="status report" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/10/echo/22-details-status-reports.png6532940e1b221.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="593" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

Following this step-by-step guide, you’ve installed the Drupal Content Management System on the Debian 12 server with the LAMP Stack and SSL/TLS Letsencrypt. From here, you can now use Drupal as your website and install new themes and extensions for your Drupal CMS.