Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install Drupal on Ubuntu (Apache, MariaDB, PHP)

Set up a LAMP stack, create a database and install the Drupal CMS on Ubuntu.

CMS and Apps2 min read23 screenshots

What you need

  • Ubuntu 22.04 or newer.
  • A user with sudo rights.
  • A domain name for the site (or the IP address for tests).

Step 1: Update the server

sudo apt-get update && sudo apt full-upgrade
Updating the server

Step 2: Install Apache

sudo apt install apache2
Installing Apache
sudo systemctl enable apache2 && sudo systemctl start apache2
Starting Apache
sudo systemctl status apache2
The Apache status

Open the firewall for web traffic:

sudo ufw allow http
sudo ufw allow https
Allowing HTTP

Step 3: Install PHP

Drupal needs PHP and several extensions:

sudo apt install php php-cli php-mysql php-gd php-curl php-xml php-mbstring php-zip php-opcache libapache2-mod-php unzip
Installing PHP

Step 4: Install MariaDB

sudo apt install mariadb-server -y
Installing MariaDB
sudo systemctl start mariadb && sudo systemctl enable mariadb
Starting MariaDB
sudo systemctl status mariadb
The MariaDB status

Secure it with sudo mysql_secure_installation.

Step 5: Create the database and user

sudo mariadb -u root
Opening the MariaDB shell

Run (use your own strong password):

CREATE USER 'drupal'@'localhost' IDENTIFIED BY 'DrupalPassword';
CREATE DATABASE drupal;
GRANT ALL PRIVILEGES ON drupal.* TO 'drupal'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Creating the database and the user

Step 6: Download Drupal

cd /var/www/html
Moving to the web folder

Download the latest version from drupal.org:

sudo wget https://www.drupal.org/download-latest/zip -O drupal.zip
Downloading Drupal

Unzip it. The folder name depends on the version:

sudo unzip drupal.zip
Unzipping Drupal

Rename the folder and set the owner:

sudo mv drupal-10.3.1/ drupal/
Renaming the folder
sudo chown -R www-data:www-data drupal/
Setting the owner

Step 7: Create an Apache virtual host

cd /etc/apache2/sites-available/
Moving to sites-available
sudo touch drupal.conf
Creating the file

Edit drupal.conf and add:

<VirtualHost *:80>
    ServerName yourdomain.com
    DocumentRoot /var/www/html/drupal

    <Directory /var/www/html/drupal>
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The virtual host file

Step 8: Enable the site and the rewrite module

sudo a2ensite drupal.conf
sudo a2enmod rewrite
sudo systemctl reload apache2
Reloading Apache
Enabling the rewrite module

Check the syntax:

apachectl -t
Checking the Apache syntax

Step 9: Finish in the browser

Open http://yourdomain.com. The Drupal installer starts. Choose a language and the Standard profile, enter the database details (database drupal, user drupal, the password you set) and your site and admin details.

The Drupal installer

After the install, protect the settings file:

sudo chmod 444 /var/www/html/drupal/sites/default/settings.php

Add an SSL certificate with Let's Encrypt (certbot --apache).

Quick recap

  • Install Apache, PHP and MariaDB, and create a database.
  • Download Drupal to /var/www/html/drupal.
  • Create a virtual host and finish the web installer.