Installing LAMP Stack with MariaDB on Ubuntu 21.04

In this week’s feature highlight, we look at How to Install LAMP Stack with MariaDB on Ubuntu 21.04

Update the system

First, lets check for any pending system package updates,

apt update
apt upgrade

Install Apache

A command to install apache2 and with its utilities.

apt install -y apache2 apache2-utils

Next, check the Status of Apache.

systemctl status apache2


root@server:~# systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor prese>
     Active: active (running) since Thu 2021-04-29 16:37:46 UTC; 16s ago
   Main PID: 31366 (apache2)
      Tasks: 55 (limit: 2280)
     Memory: 5.5M
     CGroup: /system.slice/apache2.service
             ├─31366 /usr/sbin/apache2 -k start
             ├─31367 /usr/sbin/apache2 -k start
             └─31368 /usr/sbin/apache2 -k start

If Apache is not active can start using the following command.

systemctl start apache2

Use the following command to auto starts apache at boot time.

systemctl enable apache2

To check Apache Version.

apache2 -v


Server version: Apache/2.4.41 (Ubuntu)
Server built:   2020-08-12T19:46:17

Enabling the Firewall

Allow the port/service http via UFW

ufw allow http


Rules updated
Rules updated (v6)

You can now verify whether the Apache webserver is installed correctly and functioning via your web browser.

NOTE: Replace “ip-address” with your actual server IP-Address below.


Install MariaDB Server

Installing MariaDB

apt install mariadb-server mariadb-client

Checking MariaDB status

systemctl status mariadb


root@server:~# systemctl status mariadb
● mariadb.service - MariaDB 10.3.25 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor prese>
     Active: active (running) since Thu 2021-04-29 16:41:06 UTC; 15s ago
       Docs: man:mysqld(8)
   Main PID: 33004 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 31 (limit: 2280)
     Memory: 64.7M
     CGroup: /system.slice/mariadb.service
             └─33004 /usr/sbin/mysqld

To start MariaDB if it is not active.

systemctl start mariadb

Use the following command to auto starts MariaDB at boot time.

systemctl enable mariadb

Next, MariaDB database security.

NOTE: In this step you will be prompted with several questions.



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.

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

Login to MariaDB

 mariadb -u root

Exit from MariaDB


Checking the MariaDB Version

mariadb --version


root@server:~# mariadb --version
mariadb  Ver 15.1 Distrib 10.3.25-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Installing PHP 7.4

Run the following commands to install PHP 7.4

apt install php7.4 libapache2-mod-php7.4 php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline

Enable the php7.4 module for Apache and restart the Apache Web server.

a2enmod php7.4

systemctl restart apache2

Checking the PHP Version.

php --version


root@server:~# php --version
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

To ensure PHP is functioning correctly, lets create a test PHP script, for this we create a new file called info.php,

nano /var/www/html/info.php

Add the following into the file, info.php,

<?php phpinfo(); ?>

Visit the the following link in a web browser to verify that PHP is working fine,

NOTE: Replace “ip-address” with your actual server IP-Address below.


To Run Apache with PHP-FPM (Optional)

FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for heavy-loaded sites.

NOTE: This is an optional step if you wish to run your WordPress website with PHP-FPM.

First, disable normal/plain PHP 7.4,

a2dismod php7.4

Next, Install the php7.4-fpm package,

apt install php7.4-fpm

Enable the proxy_fcgi and setenvif module.

a2enmod proxy_fcgi setenvif


Considering dependency proxy for proxy_fcgi:
Enabling module proxy.
Enabling module proxy_fcgi.
Module setenvif already enabled
To activate the new configuration, you need to run:
  systemctl restart apache2

Enable the php7.4-fpm module in Apache,

a2enconf php7.4-fpm

Restart Apache,

systemctl restart apache2

Enable php7.4-fpm to start on boot, so anytime your system reboots, php7.4-fpm will start with it,

systemctl enable php7.4-fpm

Start the php7.4-fpm service,

systemctl start php7.4-fpm

If you wish to check the status of php7.4-fpm,

systemctl status php7.4-fpm


root@server:~# systemctl status php7.4-fpm
● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: >
     Active: active (running) since Thu 2021-04-29 17:13:08 UTC; 15min ago
       Docs: man:php-fpm7.4(8)
    Process: 42271 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/>
   Main PID: 42263 (php-fpm7.4)
     Status: "Processes active: 0, idle: 2, Requests: 1, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 2280)
     Memory: 8.1M
     CGroup: /system.slice/php7.4-fpm.service

To verify enter the following link in a web browser.

NOTE: Replace “ip-address” with your actual server IP-Address below.


Now you have successfully installed LAMP stack (Apache, MariaDB, and PHP7.4) on Ubuntu 21.04.

(Visited 96 times, 2 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *