×

LAMP (stands for Linux, Apache, MariaDB, PHP) is a collection of open-source software that is used to create dynamic websites and web-based applications. 

It uses Linux as the OS, Apache as a web server to serve web content over simple URLs, MariaDB as a database server to store websites and applications data, and PHP as the scripting language to serve dynamic content. 

Usually, the Lamp stack uses MySQL as a database server, however, for Debian systems; MariaDB  is now the default MySQL server.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Packages Installation tasks on their Linux Server.

In this context, we shall look into how to install Linux, Apache, MariaDB, and PHP (LAMP) Stack on Debian 10.


Steps to Install Linux, Apache, MariaDB, PHP (LAMP) Stack on Debian 10 ?

To begin, you need to have sudo privileges on the Debian Server and follow the steps given below.


1. How to install Apache ?

i. First, update the apt index using the below command in Terminal:

$ sudo apt update

ii. Then to install Apache, issue this command:

$ sudo apt install apache2

iii. Once the installation is completed, the Apache service will start running automatically. 

Here is the command to verify the status of the Apache service:

$ sudo systemctl status apache2

iv. Now if a firewall is enabled on your system, you will need to allow Apache port through it. The Debian system comes with different profiles for Apache which can be used to adjust the firewall settings. 

v. To view the list of all application profiles, issue the below command in Terminal:

$ sudo ufw app list

We will enable the "WWW Full" profile for Apache that will allow the traffic on both port 80(HTTP) and port 443(HTTPS).

vi. To view information about the "WWW Full" profile, execute the below command in Terminal:

$ sudo ufw app info "WWW Full"

vii. To enable the "WWW Full" profile, execute the below command in Terminal:

$ sudo ufw allow in "WWW Full"

viii. To verify if the rule has been added successfully, execute the below command in Terminal:

$ sudo ufw status

ix. Now to check if Apache is working and can serve web pages, try to open Apache’s default webpage in your web browser:

http://ip-address

Replace the ip-address with the IP address of your own system.

Alternatively, you can also access Apache’s default webpage using the curl command in your Terminal:

$ curl http://ip-address


2. How to install MariaDB ?

Now, we will install the MariaDB database that will be used to store data for our site. 

i. Execute the below command in Terminal to install MariaDB database:

$ sudo apt install mariadb-server

ii. Now execute the security script to implement some security features. Use the below command in Terminal to execute the script:

$ sudo mysql_secure_installation

You will be presented with a few questions to configure some options for MariaDB. 

When you are asked to provide the password for root, hit n

Then it will ask you to set the root password, again hit N, and then Enter

Then for all the next questions, hit y and then Enter to answer yes and accept the default values.

iii. Now connect to MariaDB console as a root user. You can do so using this command in Terminal:

$ sudo mariadb

Enter the sudo password.

Now create a database let's say "test":

CREATE DATABASE test;

Now create a user along with a password and give it full permission to the "test" database. 

Execute the below command to do so:

GRANT ALL ON test.* TO linuxapt@'localhost' IDENTIFIED BY 'linuxapt' WITH GRANT OPTION;

We have created a user 'linuxapt' with password 'linuxapt'.

Now reload the privileges using the below command:

FLUSH PRIVILEGES;

Then exit the console:

exit

iv. Now try logging in to the MariaDB console using the new user credentials you have set in the previous step.

$ mariadb -u linuxapt -p

Now enter the password for this user (in our case, it was "linuxapt").


v. To view the database "test" that you have created in the previous step, execute the below command in Terminal:

SHOW DATABASES;

To leave the console, execute the below command in Terminal:

exit


3. How to install PHP ?

Here, we will install PHP to connect with the MariaDB database and retrieve the required information. 

PHP also connects with the Apache server to hand over the processed information for displaying over the web.

i. In order to install PHP, issue this command in Terminal:

$ sudo apt install php libapache2-mod-php php-mysql

Usually, when a user requests something from the Apache server, it first searches it in the index.html file. 

ii. In order to make the server first look for the requested item in the index.php file, you will need to make a little change in the dir.conf file for Apache. 

Execute the below command in Terminal to edit this file:

$ sudo nano /etc/apache2/mods-enabled/dir.conf

Find the below line in the dir.conf file:

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

From the above line, cut index.php entry and paste it after the DirectoryIndex.

iii. Then save and close the dir.conf file and reload Apache's configuration using the below command:

$ sudo systemctl reload apache2

Then execute the below command to verify the status of Apache and to make sure there is no error:

$ sudo systemctl status apache2


4.  How to Test PHP Processing on Apache ?

Now in this step, we will check if Apache is configured properly and can process requests for PHP files. 

i. To do so, create a new info.php file inside the /var/www/html directory using the below command in Terminal:

$ sudo nano /var/www/html/info.php

Then add the below lines of code in the info.php file:

<?php
phpinfo();

After that save and close the info.php file.

ii. Open the below address in your web browser:

http://ip-address/info.php

Replace the ip-address with the IP address of your own system.

You will see a page which verifies that the Apache is configured correctly to serve the PHP content.

This page also shows some information about PHP so it is recommended to remove this page. 

iii. Execute the below command in Terminal to do so:

$ sudo rm /var/www/html/info.php


[Need urgent assistance to Configure Apache on your Ubuntu Server? We are available to help you. ]


Conclusion