How To Install Drupal On Ubuntu

Coding School For Kids Presentation

Drupal is a content management system (CMS) and framework that is used as a back-end system for many websites and applications. It provides a robust architecture for developers to create sophisticated applications while simplifying the site-building and content-authoring experience for end users. It is used by organizations and individuals all over the world, including some of the largest companies and governments.

Drupal has many features that make it an attractive option for website development, including:

  • A flexible and extensible framework that allows for customizations and integrations.
  • A wide range of contributed modules adds functionality to core Drupal, making it suitable for almost any type of website or application.
  • Excellent security features, with regular updates to address new threats.
  • Good performance even with large amounts of data.

Drupal Installation Requirements

Before you begin, you will need the following:

  • A web server running Apache, MySQL, and PHP
  • A text editor
  • Composer

Why Should You Install Drupal 8 or 9 with Composer?

There are a few reasons why you should install Drupal 8 or 9 with Composer.

  • Composer is a dependency manager for PHP. This means that it can help you manage the various libraries and dependencies that your website needs in order to run.
  • It can help you keep your Drupal installation up to date. When a new version of Drupal is released, you can simply run the Composer update command to update your installation.
  • It can manage contributed modules and themes. Contributed modules and themes are modules and themes that are not part of the Drupal core.
  • Helps manage multiple Drupal sites. This is useful if you need to run multiple Drupal sites on a single server.

If these benefits make sense for your use case, let’s get started with installing Composer first.

Step 1 — Installing Composer

In order to install Drupal 8 with all its dependencies through Composer, we need to first install Composer globally on our system. You can learn how to do that by following Step 1 of How To Install and Use Composer on Ubuntu 18.04 .

First, update your local package index:

sudo apt update
Image 16

Then install the curl and unzip packages that will be required for downloading and installing Composer:

sudo apt install curl unzip
Image 17
Installing curl

After that’s been completed successfully, use curl to download the latest stable version of Composer into your home directory:

curl -sS https://getcomposer.org/installer -o composer-setup.php

Let’s install PHP,

As of this writing PHP 8.1 is available so I’m gonna go ahead and install PHP,

sudo apt-get install php
Image 20
Installation of php

Let’s download the sig file from the composer site,

$ HASH=curl -sS https://composer.github.io/installer.sig

Let’s have a look at the hash using echo command,

echo $HASH

And then verify that the installer matches the SHA384 signature for the current version with the one from the sig file.

Note that you should replace the highlighted link in this command with the one from the Composer download page:

php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

If you see Installer verified , as shown above, you can safely run the installer script:

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
The output will look something like this:<br>All settings correct for using Composer
Downloading…
Composer (version 1.7.4) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
Image 21
Entire installation process.

We can confirm that Composer was installed correctly by checking the version number:

composer --version

If everything worked as expected, you should see something like this:

Image 19
Composer version

Step 2 — Installing Drupal Console

The Drupal Console is a suite of tools that you can use to manage a Drupal website from the command line. It provides many useful commands for interacting with and managing a Drupal site.

In this step, we will install the latest stable version of the Drupal Console using Composer.

First, change into your home directory and download the latest stable release of the Drupal Console project into a drupal-console directory using the following command:

cd ~ && composer create-project drupal/console:~1.0 www/drupal-console --stability=dev --no-interaction
Image 18

Download Drupal Core Using Composer

Once you have Composer installed, you can use it to download Drupal 8 or 9.

To download Drupal 8, run the following command:

composer create-project drupal/drupal

To download Drupal 9, run the following command:

composer create-project drupal/drupal:^9

You will be prompted to choose a directory for the Drupal installation. We will assume that you choose the directory /var/www/html/drupal.

You will also be prompted to choose a version of Drupal to install. We will assume that you choose the latest version, Drupal 9.0.0.

Once the installation is complete, you will have a complete Drupal installation in the directory /var/www/html/drupal.

Download a Specific Drupal Core Version via Composer

If you want to download a specific Drupal core version, you can specify the version number when you run the Composer create-project command.

For example, to download Drupal 8.8.3, you would run the following command:

composer create-project drupal/drupal:8.8.3

To download Drupal 9.0.0, you would run the following command:

composer create-project drupal/drupal:9.0.0

You will be prompted to choose a directory for the Drupal installation. We will assume that you choose the directory /var/www/html/drupal.

Once the installation is complete, you will have a complete Drupal installation in the directory /var/www/html/drupal.

Download Contributed Modules and Themes Using Composer

In addition to the Drupal core, there are thousands of contributed modules and themes that you can download and install on your Drupal site. To download contributed modules and themes, you can use the Composer require command.

For example, to download the Views module, you would run the following command:

composer require drupal/views

To download the Bootstrap theme, you would run the following command:

composer require drupal/bootstrap

You will be prompted to choose a directory for the modules or themes. We will assume that you choose the directory /var/www/html/drupal/modules for modules and /var/www/html/drupal/themes for themes.

Once the installation is complete, you will have the Views module or the Bootstrap theme installed in the appropriate directory.

Download a Specific Version of Contributed Modules or Themes

If you want to download a specific version of a contributed module or theme, you can specify the version number when you run the Composer require command. For example, to download version 8.x-3.0 of the Views module, you would run the following command:

composer require drupal/views:8.x-3.0

To download version 3.0 of the Bootstrap theme, you would run the following command:

composer require drupal/bootstrap:3.0

You will be prompted to choose a directory for the modules or themes. We will assume that you choose the directory /var/www/html/drupal/modules for modules and /var/www/html/drupal/themes for themes. Once the installation is complete, you will have the Views module or the Bootstrap theme installed in the appropriate directory.

Changing Locations of Packages

By default, Composer will install modules and themes in the /var/www/html/drupal directory. If you want to change the location of the modules or themes directory, you can use the –path option when you run the Composer require command.

For example, to install the Views module in the /var/www/html/modules directory, you would run the following command:

composer require drupal/views --path=/var/www/html/modules

To install the Bootstrap theme in the /var/www/html/themes directory, you would run the following command:

composer require drupal/bootstrap --path=/var/www/html/themes

You will be prompted to choose a directory for the modules or themes. We will assume that you choose the directory /var/www/html/modules for modules and /var/www/html/themes for themes. Once the installation is complete, you will have the Views module or the Bootstrap theme installed in the appropriate directory.

Managing Drupal Site with Composer

Once you have Drupal 8 or 9 installed with Composer, you can use Composer to manage your Drupal site. For example, you can use Composer to keep your Drupal installation up to date. When a new version of Drupal is released, you can simply run the Composer update command to update your installation.

composer outdated "drupal/*"

This will list all the available versions of drupal.

composer update "drupal/core-*" --with-all-dependencies

Updating Drupal to the latest version using composer. You can also use Composer to manage contributed modules and themes. Contributed modules and themes are modules and themes that are not part of the Drupal core.

Summary

In this article, we showed you how to install Drupal 8 or 9 with Composer. We also showed you how to use Composer to manage your Drupal site.