Jul 11, 2023 7 min read

How to Install Drupal on Ubuntu 22.04

Install Drupal on Ubuntu 22.04 with our step-by-step tutorial. It is a powerful open-source content management system (CMS).

Install Drupal on Ubuntu 22.04
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install Drupal on Ubuntu 22.04, let's briefly understand – What is Drupal?

Drupal is a powerful open-source content management system (CMS) that enables the creation and management of websites and online applications. It offers a flexible and customizable platform for building websites, blogs, e-commerce sites, and more.

With its user-friendly interface and vast library of modules and themes, Drupal empowers users to create unique and engaging digital experiences. It is widely known for its scalability, security, and ability to handle large amounts of content. Whether you're a beginner or an expert, Drupal provides the tools and flexibility to bring your online vision to life.

In this tutorial, you will install Drupal on Ubuntu 22.04. We will also address a few FAQs on how to install Drupal on Ubuntu 22.04.

Advantages of Drupal

  1. Flexibility: Drupal offers a highly flexible and customizable platform, allowing you to create unique and tailored websites.
  2. Scalability: It can handle large amounts of content and traffic, making it suitable for websites of all sizes.
  3. Security: Drupal has a strong security framework, ensuring the protection of your website and user data.
  4. Extensibility: With thousands of modules and themes, Drupal allows you to extend and enhance your website's functionality easily.
  5. Active Community: It has a vibrant community of developers and users, providing constant support, updates, and resources for your Drupal site.

Step 1 – Update the System

By executing the commands below, let's upgrade the system packages to the most recent version.

sudo apt update && sudo apt upgrade -y

Step 2 – Install MariaDB Server

Install MariaDB or MySQL next. MariaDB will be used throughout this procedure. So let's run the following command to install MariaDB.

sudo apt install -y mariadb-server mariadb-client

Set a root password, disable root remote logins, and delete test databases to secure your database server.

sudo mysql_secure_installation
Output

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

To log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Verify that you can utilize a password-protected root user login to the database.

mysql -u root -p

We can now construct a Drupal database that will be used by Drupal once it has been installed on our system because we can log in as regular users. Use the following command to create one.

Step 3 – Create Database for Drupal

mysql -u root -p
CREATE DATABASE drupal;
CREATE USER 'drupal_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON drupal.* to drupal_user@'localhost';
FLUSH PRIVILEGES;
\q
Output

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 128
Server version: 10.6.7-MariaDB-2ubuntu1 Ubuntu 22.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE drupal;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON drupal.* TO ‘drupal’@’localhost’ IDENTIFIED BY "StrongPassword";
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> \q
Bye

Step 4 – Install PHP

Ubuntu 22.04 ships with PHP 8.1 by default. We'll set up PHP and the additional modules needed to run Drupal.

sudo apt install php php-{cli,fpm,json,common,mysql,zip,gd,intl,mbstring,curl,xml,pear,tidy,soap,bcmath,xmlrpc}

Step 5 – Install Apache Web Server

We will use Apache as our web server because it is simple to set up and operate.

Run the commands listed below to install.

sudo apt install apache2 libapache2-mod-php

Update PHP's memory limit and time zone.

💡
Note: You should enter the TimeZone that Drupal should use by default.
sudo nano /etc/php/*/apache2/php.ini
memory_limit = 256
date.timezone = UTC

On Ubuntu 22.04, download the most recent version of Drupal and extract it.

wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
tar xvf drupal.tar.gz
mv drupal-*/  /var/www/html/drupal

Change the Apache user and group's ownership of a directory in Drupal.

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

Step 6 – Set Up Apache Web Server for Drupal

Disable the default Apache page:

sudo a2dissite 000-default.conf
sudo systemctl restart apache2

Make a Drupal configuration file.

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

Include the following content.

💡
Note: Use your actual domain name in place of example.com.
<VirtualHost *:80>
     ServerName mysite.com
     ServerAdmin [email protected]
     DocumentRoot /var/www/html/drupal/

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

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

Use the commands listed below to configure and enable the website.

sudo apachectl -t
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
sudo a2enmod php8.1
sudo a2enmod rewrite
sudo a2ensite drupal.conf
sudo systemctl restart apache2

From the browser, check and install Drupal on Ubuntu.

Use http://example.com or http://localhost_or_IP to get to the Drupal configuration page.

💡
Note: Use your actual domain instead of example.com.

Choose a profile for installation.

Drupal database configuration is set.

Hold on until the installation is finished.

Set up your website,

In a few, you'll reach the Drupal dashboard.

FAQs to Install Drupal on Ubuntu 22.04

Which version of PHP is compatible with Drupal on Ubuntu 22.04?

Drupal 9 requires PHP 7.3 or higher. You can install PHP on Ubuntu 22.04 by running sudo apt-get install php in the terminal.

How do I set up a MySQL database for Drupal on Ubuntu 22.04?

Install MySQL by running sudo apt-get install mysql-server and then create a new database and user for Drupal using MySQL commands.

Can I use MariaDB instead of MySQL for Drupal on Ubuntu 22.04?

Yes, you can use MariaDB as an alternative to MySQL. Install it using sudo apt-get install mariadb-server and follow the same database setup steps.

What permissions should be set for Drupal files and folders on Ubuntu 22.04?

Set the permissions to ensure that the web server has appropriate access. Generally, it's recommended to set directories to 755 and files to 644.

How do I configure the Drupal database connection on Ubuntu 22.04?

During the installation process, you'll be prompted to enter database details. Provide the database name, username, password, and host (usually "localhost").

Can I use a different theme for my Drupal site on Ubuntu 22.04?

Yes, Drupal allows you to use different themes. You can download and install new themes from the Drupal theme repository or create custom themes.

How do I access the Drupal administration dashboard on Ubuntu 22.04?

After installing Drupal, access the administration dashboard by appending /user/login to your website URL and logging in with the administrator account you created during installation.

Conclusion

Enjoy Drupal 9's power in your website. For more tuning and complex configurations, consult the official manual.

If you have any queries or doubts, please leave them in the comment below. We'll be happy to address them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.