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.
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
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
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
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/
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
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.
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.
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;
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
# apt-cache search php | egrep 'module' | grep default
Now reload Apache’s configuration and check the status with the following commands.
# systemctl reload apache2 # systemctl status apache2
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
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
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.