Install LAMP Stack on Debian 11

Last Updated:

Follow through this guide to learn how to install LAMP Stack on Debian 11. If you are looking at building some web application, LAMP stack is the first thing you might need. As you already know, LAMP is a group of opensource web development software; Linux OS, Apache http serverMariaDB/MySQL relational database management systems and PHP web scripting language.

Installing LAMP Stack on Debian 11

As per the acronym, Linux system is the first component of LAMP stack. And of course Debian 11 is our first component of LAMP stack.

Run System Update

To begin with, update and upgrade your system packages;

apt update
apt upgrade

Install Apache Web Server on Debian 11

Apache web server can be installed by running the command below;

apt install apache2 -y

Once the installation is done, Apache is started and enabled to run on system boot.

systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-09-02 19:57:45 EAT; 1s ago
    Process: 2223 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 2227 (apache2)
      Tasks: 55 (limit: 1133)
     Memory: 8.7M
        CPU: 25ms
     CGroup: /system.slice/apache2.service
             ├─2227 /usr/sbin/apache2 -k start
             ├─2228 /usr/sbin/apache2 -k start
             └─2229 /usr/sbin/apache2 -k start

Sep 02 19:57:45 systemd[1]: Starting The Apache HTTP Server...
Sep 02 19:57:45 systemd[1]: Started The Apache HTTP Server.

Verify external access to Apache by navigating to your browser and entering the server IP address or resolvable hostname as http://Server.IP_or_hostname. You should land on Apache HTTP server test page.

Install LAMP Stack on Debian 11

To restrict access to Apache, you can install UFW;

apt install ufw

Once UFW is installed, you can enable it to secure your system against unrestricted access.

Before you can enable UFW, ensure that you have opened SSH port, in case you had logged in via SSH.

Replace SOURCE_IP, with the address from which you are logging in from.

ufw allow from SOURCE_IP to any port 22 proto tcp

You can then allow external access to Apache;

ufw allow "WWW Full"

or simply run ufw allow 80/tcp to allow HTTP traffic.

Great. Proceed to install MySQL/MariaDB on Debian 11.

Install MySQL Database Server on Debian 11

In this demo, we are running LAMP stack on Debian 11 with MySQL 8.

Therefore, follow the link below to install MySQL 8 on Debian 11;

Install MySQL 8 on Debian 11

If you want to use MariaDB 10.6, then check the guide below;

Install MariaDB 10.6 on Debian 11

Install PHP on Debian 11

PHP is the last but not least component in LAMP Stack.

Follow the link below to learn how to install PHP on Debian 11;

Install PHP 7.1/7.2/7.3/7.4 on Debian 11

If you want to use PHP 8, then check the guide below;

Install PHP 8 on Debian 11

Installing PHP Modules on Debian 11

In this demo, we are going to use PHP 7.4 for our LAMP stack.

Installation of PHP installs with itself other PHP modules such as, libapache2-mod-php7.4 libsodium23 php php-common php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline psmisc.

Install MySQL module for PHP and any other module you may need for your web application.

apt install php-mysql

Testing PHP Processing on Debian 11

You can test PHP to confirm that is working as required as well check the version and installed modules using the simple PHP info script.

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Restart Apache

systemctl restart apache2

Next, navigate to the browser and enter the address, http://<server-IP>/info.php


If you see this page, then PHP installation is working pretty well and Apache can server PHP content!

Related Tutorials

Install LAMP Stack on CentOS 8

Install LAMP Stack with MariaDB 10 on Debian 10 Buster

Install LAMP Stack on Fedora 30

Install LAMP Stack on Debian 9


We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Co-founder of, Linux Tips and Tutorials. Linux/Unix admin and author at

Leave a Comment