How to Install LAMP on Debian 10 Server

A “LAMP” stack is a collection of open-source software that is generally installed together to allow a system to deploy dynamic applications. This term is an acronym which describes the Linux operating system, Apache web server, a MariaDB database, and PHP programming.

Read Also: How to Install LEMP on Debian 10 Server

Although this “LAMP” stack usually involves MySQL as the database management system, some Linux distributions such as Debian — use MariaDB as a drop-in replacement for MySQL.

Requirements

  1. How to Install a Debian 10 (Buster) Minimal Server

In this article, we will show you how to install a LAMP stack on a Debian 10 server, using MariaDB as the database management system.

Installing Apache Web Server on Debian 10

The Apache web server is an open-source, powerful, reliable, secure, highly-extensible and widely used HTTP server software for hosting a website.

To install Apache, use Debian’s apt package manager as shown.

# apt install apache2 
Install Apache on Debian 10

Install Apache on Debian 10

When the Apache installation is complete, the installer will trigger systemd system and service manager to start the Apache2 service for now and enable it to automatically start at system boot.

To check if the Apache service is up and running fine, run the following systemctl command.

# systemctl status apache2
Check Apache Status in Debian 10

Check Apache Status in Debian 10

You can also start, stop, restart and get the status of Apache web server using the following systemctl commands.

# systemctl start apache2.service 
# systemctl restart apache2.service 
# systemctl stop apache2.service
# systemctl reload apache2.service 
# systemctl status apache2.service 

If you’ve ufw firewall running, you need to open port 80 (www) and 443 (https) to allow incoming traffic on Apache.

# ufw allow www
# ufw allow https
# ufw status
Open Apache Ports in Debian 10

Open Apache Ports in Debian 10

Now you need to test if Apache is properly installed and can serve web pages. Open a web browser and use the following URL to access the Apache Debian Default Page.

http://SERVER_IP/
OR
http://localhost/
Check Apache Web Page

Check Apache Web Page

Installing MariaDB on Debian 10

Once Apache web server up and running, you need to install the database system to be able to keep and manage data for your website.

To install MariaDB, use Debian’s apt package manager as shown.

# apt install mariadb-server
Install MariaDB in Debian 10

Install MariaDB in Debian 10

Once MariaDB installed, it is recommended to run the following security script that will remove some insecure default settings and disable access to your database system.

# mysql_secure_installation

The above security script will take you through a series of following questions where you can make some changes to your MariaDB setup as shown.

Secure MariaDB in Debian 10

Secure MariaDB in Debian 10

If you want to create a database named "tecmint_wpdb" and a user named "tecmint_wpuser" with full privileges over the database, run the following commands.

# mysql -u root -p
MariaDB [(none)]> CREATE DATABASE tecmint_wpdb;
MariaDB [(none)]> GRANT ALL ON tecmint_wpdb.* TO 'tecmint_wpuser'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit;

You can confirm if the new user has the full permissions on the database by logging in to the MariaDB with user credentials as shown.

# mysql -u tecmint_wpuser -p
MariaDB [(none)]> SHOW DATABASES;
Check Database User Permissions

Check Database User Permissions

Installing PHP 7.3 on Debian 10

PHP (Hypertext Preprocessor) is a popular scripting language used to build the logic for displaying web content and for users to interact with the database.

To install the PHP package, run the following command.

# apt install php libapache2-mod-php php-mysql
Install PHP in Debian 10

Install PHP in Debian 10

If you want to install additional PHP modules, you can search and install using the combination of apt-cache command and grep command as shown.

# apt-cache search php | egrep 'module' | grep default
Install PHP Modules in Debian 10

Install PHP Modules in Debian 10

Now reload Apache’s configuration and check the status with the following commands.

# systemctl reload apache2
# systemctl status apache2
Reload Apache Configuration

Reload Apache Configuration

Testing PHP Processing on Apache

We will be creating a simple PHP script to verify that the Apache can process requests for PHP files.

# nano /var/www/html/info.php

Add the following PHP code, inside the file.

<?php phpinfo(); ?>

When you are done, save and close the file.

Now open a browser and type the following address to see whether your web server can show content created by this PHP script.

http://SERVER_IP/info.php
OR
http://localhost/info.php
Check PHP Info in Debian 10

Check PHP Info in Debian 10

If you see the above page in your web browser, then your PHP installation is working as expected. Also, this page shows some basic details about your PHP installation and it is useful for debugging purposes, but at the same time it will also show some sensitive information about your PHP.

So, it is highly recommended to delete this file from the server.

# rm /var/www/html/info.php
Conclusion

In this article, we’ve explained how to install Linux, Apache, MariaDB, and PHP (LAMP) stack on a Debian 10 server. If you have questions about this article, feel free to ask in the comment section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.