This guide will explain how to install Apache, MariaDB and PHP ( LAMP Stack) on Debian Linux system. LAMP is an acronym for – Linux, Apache, MySQL/MariaDB and PHP. LAMP Stack is not a single package but a set of open-source tools that are used to power web applications and websites. You can run each component independently to serve your application depending on the needs.
Install LAMP Stack on Debian Linux
LAMP Stack comprises of the following open source software applications.
- Linux – This is the operating system hosting the Applications.
- Apache – Apache HTTP is a free and open-source cross-platform web server.
- MySQL/MariaDB – Open Source relational database management system.
- PHP – Programming/Scripting Language used for developing Web applications.
You can use a Virtual Machine on Premise, in the cloud or a dedicated server to install and configure LAMP Stack on Debian 10 operating system. A
Step 1: Update Debian System
Before we can start installation of LAMP Stack packages on Debian, it is recommended to keep the repository and packages up to date.
sudo apt update && sudo apt -y upgrade
Step 2: Install MariaDB Database Server
MariaDB is a relational database management system forked from MySQL. It is free and Open source. Install it by running the commands below.
sudo apt install -y mariadb-server mariadb-client
You can confirm version of MariaDB database server installed.
$ apt policy mariadb-server
mariadb-server:
Installed: 1:10.11.6-0+deb12u1
Candidate: 1:10.11.6-0+deb12u1
Version table:
*** 1:10.11.6-0+deb12u1 500
500 http://deb.debian.org/debian bookworm/main amd64 Packages
500 http://mirror.hetzner.com/debian/packages bookworm/main amd64 Packages
100 /var/lib/dpkg/status
The service name for MariaDB Database server is mysql
or mariadb
.
$ systemctl status mariadb
● mariadb.service - MariaDB 10.11.6 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enabled)
Active: active (running) since Fri 2024-02-23 09:49:20 UTC; 13s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 2054 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
Process: 2055 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 2057 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POS>
Process: 2097 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 2099 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
Main PID: 2086 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 12 (limit: 2251)
Memory: 165.0M
CPU: 725ms
CGroup: /system.slice/mariadb.service
└─2086 /usr/sbin/mariadbd
Feb 23 09:49:20 deb12 mariadbd[2086]: 2024-02-23 9:49:20 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Feb 23 09:49:20 deb12 mariadbd[2086]: 2024-02-23 9:49:20 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
Feb 23 09:49:20 deb12 mariadbd[2086]: 2024-02-23 9:49:20 0 [Note] Server socket created on IP: '127.0.0.1'.
Feb 23 09:49:20 deb12 mariadbd[2086]: 2024-02-23 9:49:20 0 [Note] InnoDB: Buffer pool(s) load completed at 240223 9:49:20
Feb 23 09:49:20 deb12 mariadbd[2086]: 2024-02-23 9:49:20 0 [Note] /usr/sbin/mariadbd: ready for connections.
Feb 23 09:49:20 deb12 mariadbd[2086]: Version: '10.11.6-MariaDB-0+deb12u1' socket: '/run/mysqld/mysqld.sock' port: 3306 Debian 12
Feb 23 09:49:20 deb12 systemd[1]: Started mariadb.service - MariaDB 10.11.6 database server.
Feb 23 09:49:20 deb12 /etc/mysql/debian-start[2101]: Upgrading MySQL tables if necessary.
Feb 23 09:49:20 deb12 /etc/mysql/debian-start[2114]: Checking for insecure root accounts.
Feb 23 09:49:20 deb12 /etc/mysql/debian-start[2118]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables
The last step is securing the d
- Setting strong root password
- Removing anonymous users
- Disabling remote login for root user.
- Removing
test database and access to it
Run the command below to secure your database server.
$ sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
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!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
… Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
… Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
Dropping test database…
… Success!
Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Test MariaDB database installation.
$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 64
Server version: 10.11.6-MariaDB-0+deb12u1 Debian 12
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> SELECT VERSION();
+---------------------------+
| VERSION() |
+---------------------------+
| 10.11.6-MariaDB-0+deb12u1 |
+---------------------------+
1 row in set (0.000 sec)
MariaDB [(none)]>
Step 3: Install Apache Web Server
Apache Web server packages are available on Debian official repositories. All that’s needed is execution of install command with sudo.
sudo apt install -y apache2 apache2-utils
Confirm Apache build and version.
$ sudo apache2 -v
Server version: Apache/2.4.57 (Debian)
Server built: 2023-04-13T03:26:51
Service is started automatically after installation.
$ systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running) since Fri 2024-02-23 09:50:58 UTC; 44s ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 2602 (apache2)
Tasks: 55 (limit: 2251)
Memory: 11.3M
CPU: 51ms
CGroup: /system.slice/apache2.service
├─2602 /usr/sbin/apache2 -k start
├─2604 /usr/sbin/apache2 -k start
└─2605 /usr/sbin/apache2 -k start
Feb 23 09:50:58 deb12 systemd[1]: Starting apache2.service - The Apache HTTP Server...
Feb 23 09:50:58 deb12 systemd[1]: Started apache2.service - The Apache HTTP Server.
You can restart service or reload when a change is made by using systemctl command.
sudo systemctl reload apache2
sudo systemctl enable apache2
To enable the service to start at boot, use
sudo systemctl enable apache2
To view Apache server full status, use apache2ctl
command.
sudo apt -y install elinks
sudo apache2ctl fullstatus
Your output should be similar to below.

Open server IP address on your browser to see default Apache page.

Step 4: Install PHP on Debian
Now that we have both Apache and MariaDB installed, the missing piece is PHP. We will install PHP and standard extensions which are commonly used.
sudo apt install php libapache2-mod-php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
Enable Apache module if not already enabled then restart the Web Server.
sudo a2enmod php*
Confirm your PHP version.
$ php --version
PHP 8.2.7 (cli) (built: Jun 9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies
Create a php script to test your LAMP stack installation.
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php
Open your Debian server IP and URL: http://[ServerIP/hostname]/phpinfo.php

This gives a detailed information about PHP and Apache web server. This marks the end our guide on how to Install LAMP Stack on Debian Linux system.
Other interesting guides:
- How to Install phpMyAdmin with Apache on Debian
- How to Monitor Apache Web Server with Prometheus and Grafana in 5 minutes
- Monitoring MySQL / MariaDB with Prometheus in five minutes