How to Install Drupal with Apache on Debian and Ubuntu

Developing your website from scratch can be a daunting task. It’s time-consuming and expensive if you are planning to hire a developer. An easy way to get your blog or website off the ground is using a CMS (content management system) like Drupal.

Drupal is an open-source content management system (CMS), written in PHP and released under GPL. It was first released in January 2001 to power personal blogs, corporate websites, and any kind of websites that people may need. Today, Drupal is one of the most famous CMS in the world running millions of websites worldwide.

The latest version of Drupal at the time of writing this guide is Drupal 9.

Drupal Features

  1. Free and open-source.
  2. Basic features like the ability to publish posts, pages, and a comment system, RSS feed, user registration. install and modify templates & add-ons.
  3. More than 30000 available modules to download for free from the Drupal store.
  4. Available in more than 110 languages with support for RTL languages like Arabic.
  5. Multi-site support and Multi-user content editing and creation support.
  6. Support for creating blogs, forums, polls using modules that are installed by default.
  7. Very-well updates system to notify you about security updates.
  8. Many other features.

In this guide, we will install Drupal on Debian 10/9 and Ubuntu 20.04/18.04.

Drupal Prerequisites

Since Drupal is a PHP-driven CMS that is accessed from the front-end by users, you need to have a LAMP stack installed on your Debian/Ubuntu instance. LAMP is a software stack used for testing and deploying websites and comprises 3 major components:

  • Apache webserver.
  • MariaDB database server.
  • PHP (For Drupal 9, PHP 7.3 and later versions is recommended).

With the requirements met, let’s get started!

Step 1: Install Apache, MariaDB, and PHP

1. To install Drupal, you will require a running web-server and a database server, in this article we will work with Apache, PHP, and MariaDB, you can install them easily with the help of a package manager tool called apt.

$ 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 
Install LAMP on Ubuntu
Install LAMP on Ubuntu

2. On production servers, you must enable some basic security measures for the MariaDB database installation, by running the following security script which ships with the MariaDB package.

$ sudo mysql_secure_installation

After running the script, it will take you through a series of questions where you can answer yes(y) to enable some basic security options as shown.

  • Enter current password for root (enter for none): Enter
  • Set a root password? [Y/n] y
  • 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
Secure MariaDB Server
Secure MariaDB Server

That’s it, you’ve successfully installed all the required packages and also added a MySQL password. Now it’s time to move forward and create a database for drupal installation.

Step 2: Create a Drupal Database

3. We’ll need to create a database for our Drupal installation, to do so, run the following command to connect to the mysql shell.

$ sudo mysql -u root -p

Note: It will ask you to enter the MySQL root password, that you’ve set while securing the MySQL package, enter it and you will be prompted to the mysql terminal.

Connect to MySQL Shell
Connect to MySQL Shell

4. Next, run the following series of commands on the MySQL terminal to create new ‘drupal‘ user, database and grant privileges.

## Creating New User for Drupal Database ##
MariaDB [(none)]> CREATE USER drupal@localhost IDENTIFIED BY "your_password_here"; ## Create New Database ##
MariaDB [(none)]> create database drupal; ## Grant Privileges to Database ##
MariaDB [(none)]> GRANT ALL ON drupal.* TO drupal@localhost; ## FLUSH privileges ##
MariaDB [(none)]> FLUSH PRIVILEGES; ## Exit ##
MariaDB [(none)]> exit

Note: If you want, you can replace the user name and database name with any other name.

Step 3: Download and Install Drupal in Ubuntu

5. Drupal is available to download from the official Ubuntu/Debian repository as a package, however, it is an old version from Drupal which has many security vulnerabilities, and the current Drupal version is 9.0.6), that’s why we will be downloading Drupal from the official website

Alternatively, you may use the following wget command to grab the latest version directly.

$ sudo wget -O drupal.tar.gz

6. Next, extract the tarball file and move the uncompressed drupal folder to the /var/www/html path as shown.

$ sudo tar -xvf drupal.tar.gz
$ sudo mv drupal-9.0.6 /var/www/html/drupal

7. For drupal to be accessible, assign the permissions shown:

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

Step 4: Create an Apache Drupal Virtual Host

8. The final part of configuration requires us to create an Apache virtual host file for our Drupal website. Proceed and create the virtual host file as shown:

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

Paste the content below.

<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/html/drupal/ ServerName ServerAlias 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>

Thereafter, save and exit the configuration file.

9. With the virtual host in place, we need to enable it using the commands below:

$ sudo a2ensite drupal.conf
$ sudo a2enmod rewrite

10. Then restart the Apache webserver for the changes to apply.

$ sudo systemctl restart apache2

Step 6: Setup Drupal from a Browser

11. In this step we wrap up Drupal’s installation by setting it up on a web browser. So launch your browser and head over to your server’s IP address as shown:


12. On the page that appears, select your preferred language and click on the ‘Save and continue’ button.

Choose Drupal Language
Choose Drupal Language

13. The next step gives you 3 installation profiles that you can leverage. To keep matters easy and straightforward, select the first option which is the Standard profile, and hit the ‘Save and continue’ button.

Choose Drupal Installation Profile
Choose Drupal Installation Profile

14. In the next step fill out the database details.

Set Drupal Database Settings
Set Drupal Database Settings

15. Soon after, the installation of all the necessary files will begin. This takes roughly 5 minutes and some patience will do.

Drupal Installation Progress
Drupal Installation Progress

16. Fill in all the required fields about your site such as site name, site email address, location, and timezone.

Set Drupal Site Settings
Set Drupal Site Settings

17. Finally, you will get the default dashboard for Drupal as shown:

Drupal Dashboard
Drupal Dashboard

From here, you can start creating your own responsive and elegant website using the available themes or leveraging the premium Drupal themes. That’s all we had for today. We hope you can comfortably set up Drupal on Debian 10/9 and Ubuntu 20.04/18.04.

Posted by Contributor