This guide will explain how to install Apache, MariaDB and PHP ( LAMP Stack) on Debian 10 Buster. 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. Each component can be used independently to serve an application.

Install LAMP Stack on Debian 10 Buster

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 use account used in this setup needs sudo privileges to install software, edit configuration files, and manage services.

Step 1: Update Debian 10 Buster

Before we can start installation of LAMP Stack packages on Debian 10, 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

The version of MariaDB installed is 10.3.

$ apt policy mariadb-server
mariadb-server:
Installed: 1:10.3.13-1
Candidate: 1:10.3.13-1
Version table:
*** 1:10.3.13-1 500
500 http://httpredir.debian.org/debian buster/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.3.13 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-03-29 10:31:19 UTC; 6min ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 14616 (mysqld)
Status: "Taking your SQL requests now…"
Tasks: 30 (limit: 1148)
Memory: 51.8M
CGroup: /system.slice/mariadb.service
└─14616 /usr/sbin/mysqld
Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: performance_schema
Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: Phase 6/7: Checking and upgrading tables
Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: Running 'mysqlcheck' with connection arguments: --socket='/var/run/mysqld/mysqld.sock' --host='lo
Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: # Connecting to localhost…
Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: # Disconnecting from localhost…
Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: Processing databases
Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: information_schema
Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: performance_schema
Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: OK

The last step is securing the database server. This includes:

  • 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 67
Server version: 10.3.13-MariaDB-1 Debian buildd-unstable
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.3.13-MariaDB-1 |
+-------------------+
1 row in set (0.001 sec)
MariaDB [(none)]>

Step 3: Install Apache Web Server

Apache Web server packages are available on Debian 10 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.38 (Debian)
Server built: 2019-01-31T20:54:05

Service is started automatically after installation.

$ systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-03-29 10:56:09 UTC; 18s ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 16696 (apache2)
Tasks: 55 (limit: 1148)
Memory: 9.0M
CGroup: /system.slice/apache2.service
├─16696 /usr/sbin/apache2 -k start
├─16698 /usr/sbin/apache2 -k start
└─16699 /usr/sbin/apache2 -k start

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 10 Buster

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. The version of PHP installed on Debian 10 is PHP 7.3.

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 php7.3 

Confirm your PHP version.

$ php -v
PHP 7.3.3-1 (cli) (built: Mar 7 2019 19:43:34) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.3-1, Copyright (c) 1999-2018, 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 10 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 10 Buster.

Other interesting guides:

How to Install phpMyAdmin with Apache on Debian 10 (Buster)

How to Monitor Apache Web Server with Prometheus and Grafana in 5 minutes

Monitoring MySQL / MariaDB with Prometheus in five minutes