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 read this far, tweet to the author to show them you care. Tweet a thanks
Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

3 thoughts on “How to Install LAMP on Debian 10 Server”

    • @Juan,

      You can install PhpMyAdmin on Debian 10 using the following commands.

      $ wget https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-all-languages.zip
      $ tar xvf phpMyAdmin-5.0.2-all-languages.zip
      $ sudo mv phpMyAdmin-*/ /usr/share/phpmyadmin
      $ sudo mkdir -p /var/lib/phpmyadmin/tmp
      $ sudo chown -R www-data:www-data /var/lib/phpmyadmin
      $ sudo mkdir /etc/phpmyadmin/
      $ sudo cp /usr/share/phpmyadmin/config.sample.inc.php  /usr/share/phpmyadmin/config.inc.php
      

      Open the configuration config.inc.php file, set secret passphrase and tmp directory.

      $cfg['blowfish_secret'] = 'H2OxcGXxflSd8JwrwVlh6KW6s2rER63i'; 
      $cfg['TempDir'] = '/var/lib/phpmyadmin/tmp';
      

      Configure your apache to access the phpmyadmin.

      Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.