How to Install Drupal on Ubuntu 20.04

Drupal is a Content Management System (CMS) to maintain and publish an internet website. It's an open-source content management system (CMS) with a large, supportive community. It's used by millions of people and organizations around the globe to build and maintain their websites.

Update the system.

apt update -y 

apt upgrade -y

Install MariaDB database server

sudo apt install -y mariadb-server mariadb-client

Secure your database server by setting a root password, disabling root remote logins, and removing test databases.

sudo mysql_secure_installation

Output:

root@vps:~# sudo mysql_secure_installation

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

In order 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!

Allow normal users to login as root user with a password.

sudo mysql -u root
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'root';
FLUSH PRIVILEGES;
QUIT;

Check that you can login to the database as a root user with a password set

mysql -u root -p

Output:

root@vps:~# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 58
Server version: 10.3.31-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.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 for Drupal

mysql -u root -p
CREATE DATABASE drupal;
GRANT ALL PRIVILEGES ON drupal.* TO ‘drupal’@’localhost’ IDENTIFIED BY "StrongPassword";
FLUSH PRIVILEGES;
\q

Output:

root@vps:~# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 58
Server version: 10.3.31-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.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

Install PHP

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

Output:

root@vps:~# sudo apt install php php-{cli,fpm,json,common,mysql,zip,gd,intl,mbstring,curl,xml,pear,tidy,soap,bcmath,xmlrpc}
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils fontconfig-config fonts-dejavu-core libapache2-mod-php7.4 libapr1 libaprutil1
  libaprutil1-dbd-sqlite3 libaprutil1-ldap libfontconfig1 libgd3 libjansson4 libjbig0 libjpeg-turbo8 libjpeg8 liblua5.2-0 libonig5
  libtidy5deb1 libtiff5 libwebp6 libxmlrpc-epi0 libxpm4 libzip5 php7.4 php7.4-bcmath php7.4-cli php7.4-common php7.4-curl php7.4-fpm
  php7.4-gd php7.4-intl php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-soap php7.4-tidy php7.4-xml
  php7.4-xmlrpc php7.4-zip ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser libgd-tools openssl-blacklist
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils fontconfig-config fonts-dejavu-core libapache2-mod-php7.4 libapr1 libaprutil1
  libaprutil1-dbd-sqlite3 libaprutil1-ldap libfontconfig1 libgd3 libjansson4 libjbig0 libjpeg-turbo8 libjpeg8 liblua5.2-0 libonig5
  libtidy5deb1 libtiff5 libwebp6 libxmlrpc-epi0 libxpm4 libzip5 php php-bcmath php-cli php-common php-curl php-fpm php-gd php-intl
  php-json php-mbstring php-mysql php-pear php-soap php-tidy php-xml php-xmlrpc php-zip php7.4 php7.4-bcmath php7.4-cli php7.4-common
  php7.4-curl php7.4-fpm php7.4-gd php7.4-intl php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-soap
  php7.4-tidy php7.4-xml php7.4-xmlrpc php7.4-zip ssl-cert

Install Apache WebServer

sudo apt install apache2 libapache2-mod-php

Output:

root@vps:~# sudo apt install apache2 libapache2-mod-php
Reading package lists... Done
Building dependency tree       
Reading state information... Done
apache2 is already the newest version (2.4.41-4ubuntu3.8).
apache2 set to manually installed.
The following NEW packages will be installed:
  libapache2-mod-php

Update PHP Timezone and Memory Limit.

sudo vi /etc/php/*/apache2/php.ini
memory_limit = 256
date.timezone = America

Download the Latest Version of Drupal and extract it on Ubuntu 20.04

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

Update ownership for the drupal directory to Apache user and group

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

Configure Apache Web Server for Drupal.

Create a configuration file for Drupal

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

Add the following content,

Replace example.com with your actual domain name.

<VirtualHost *:80>
     ServerName mysite.com
     ServerAlias www.example.com
     ServerAdmin admin@example.com
     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>

Configure and Enable Website using below commands,

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

Check and Install Drupal on Ubuntu from the browser.

Access the Drupal configuration page by using http://example.com

Replace example.com with your actual domain.

images

Select an installation profile.

images

Set Database Configure for Drupal.

images

Wait for the installation to complete,

images

Configure your site,

images

You’ll get to the Drupal dashboard in a few,

images

Done.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS