Drupal is an open-source and popular content management tool that is the foundation of many websites across the internet. It comes with a lot of modules that allow the creation of any and every type of website.
In this post, we are going to explain how to install the Drupal content management tool on Ubuntu OS.
Note: The steps mentioned here have been tested on Ubuntu 20.04 LTS.
Step 1: Install LAMP Stack
For Drupal, the most commonly used platform is the LAMP stack. Therefore, you will have to first install the LAMP stack on your Ubuntu machine. To install the LAMP stack on Ubuntu, follow this guide.
Step 2: Configure Database and User for Drupal
Drupal uses a database for storing the data being handled on your website. Here, we’ll be using MariaDB (fork of MySQL) as our database engine.
To configure database and a user for Drupal, login to MariaDB shell:
$ sudo mysql -u root -p
You will be asked for the MariaDB root user password. Provide the password that you have set during the MariaDB’s installation.
After authentication, you will see the MariaDB’s login prompt.
Now create a database for Drupal named drupal_db:
$ CREATE DATABASE drupal_db;
Then create a user for Drupal named drupal_user using the below command:
$ CREATE USER ‘drupal_user’@’localhost’ IDENTIFIED BY ‘abc123;
Now grant privileges to the user:
$ GRANT ALL ON drupal_db.* TO ‘drupal_user’@’localhost’;
Now apply the changes:
$ FLUSH PRIVILEGES
Then exit the MariaDB shell:
Step 3: Download Drupal
Now visit the Drupal website Downloads page and download the Drupal tar.gz package. Alternatively, you can use the command below for downloading the Drupal latest version (as of August 2021).
$ wget https://www.drupal.org/download-latest/tar.gz
Extract the tar.gz file into the webroot directory of your system using the below command:
$ sudo tar -xvf drupal.tar.gz -C /var/www/html
The extracted directory will be something like drupal-9.2.4 (Drupal-version-number). To make things simpler, rename the extracted directory drupal-9.2.4 to just drupal:
$ sudo mv /var/www/html/drupal-9.2.4/ /var/www/html/drupal
Now change the ownership of the Drupal installation files to your web server user which is www-data. Use the below command to do so:
$ sudo chown -R www-data:www-data /var/www/html/drupal
Also, change the permissions using the below command:
$ sudo chmod -R 775 /var/www/html/Drupal
Step 4: Create Apache’s Virtual Host File
Now create Apache’s virtual host file for Drupal. Use the below command to create the Apache virtual host file drupal.conf:
$ sudo nano /etc/apache2/sites-available/drupal.conf
Now add the below lines in the file. Replace 192.168.72.200 with your server’s IP address or domain name:
<VirtualHost *:80> ServerName 192.168.72.200 DocumentRoot /var/www/html/drupal/ <Directory /var/www/html/drupal/> AllowOverride All </Directory> </VirtualHost>
Then save the drupal.conf file and close editor.
Now use the command below to restart Apache service:
$ sudo service apache2 restart
Step 5: Make Adjustments to Filesystem
We will need to make little adjustments to our file system in order to complete the process correctly.
Under Drupal’s root directory, there is a subdirectory named default. Create files directory under the default directory using the below command:
$ mkdir /var/www/html/sites/default/files
Under the /var/www/html/sites/default directory, there is a file default.settings.php. Copy this file into the same directory but with the name settings.php.
$ sudo cp /var/www/html/drupal/sites/default/default.settings.php /var/www/html/drupal/sites/default/settings.php
Now assign write permission to group owner using the below command:
$ sudo chmod 664 /var/www/html/drupal/sites/default/settings.php
Then change the ownership of the /var/www/html/drupal/* to the webserver:
$ sudo chown -R :www-data /var/www/html/drupal/*
Step 6: Start the Installation Wizard
Now we will start the installation wizard. Open your web browser and navigate to the below address:
After opening the above link, the following installation wizard will appear. Choose your preferred language and hit Save and continue.
Then choose the installation profile. To keep things simple, choose Standard and hit Save, and continue.
Now on the Database configuration page, fill in your database details and hit Save, and continue.
Now the installation of Drupal will be started.
After that Site configuration page will appear. Fill in some basic information about your site and then hit Save and continue.
You will see the following welcome page. From now on, you can access your Drupal site by its IP or domain name.
Installation of Drupal has been completed. Now revert the permissions for the settings.php file:
$ chmod 644 /var/www/html/sites/default/settings.php
Drupal is one of the top 5 CMS platforms for creating websites and blogs. In this post, we covered the installation of the Drupal content management tool on Ubuntu OS. Now you can build any blog or website using various Drupal templates.