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 server, MariaDB/MySQL relational database management systems and PHP web scripting language.
Install 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;
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)
├─2227 /usr/sbin/apache2 -k start
├─2228 /usr/sbin/apache2 -k start
└─2229 /usr/sbin/apache2 -k start
Sep 02 19:57:45 bullseye.kifarunix-demo.com systemd: Starting The Apache HTTP Server...
Sep 02 19:57:45 bullseye.kifarunix-demo.com systemd: 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.
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;
If you want to use MariaDB 10.6, then check the guide below;
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;
If you want to use PHP 8, then check the guide below;
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
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!
That marks the end of our guide on how to Install LAMP Stack on Debian 11. Enjoy