How To Set Up LAMP Stack (Apache, MariaDB, and PHP) on Debian 11

The full form of the lamp comes from 4 different tools. The first is Linux, the second is Apache, the third is MariaDB/MySQL and the fourth is PHP. However, some developers also prefer python instead of Php.

It is an open-source, free platform for Web development where Linux is used as the operating system, Apache as the web server, all the data of the site stored in MySQL/MariaDB, and last but not the least Php handles all the dynamic content. Most developers use MySQL with the lamp stack but it should be kept in mind that the Debian system has MariaDB as default.

Now that we know what a lamp is, let us set up a Lamp stack on Debian 11. Stay with us till the end of the article and we promise by the end of the article you will be able to install all of these in one go on your Debian 11 system. So stay put and let’s get started.

Step1: Updating and Upgrading Debian 11 Package Index

We will start installing the Lamp sTack once we are over with updating and upgrading the package index as is recommended. We will first update for which use the following command in your Debian 11 terminal:

$ sudo apt update

After this command, we will upgrade for which type the following command in your Debian 11 terminal:

$ sudo apt upgrade

Step2: Installing MariaDB

Now that we have updated and upgraded let’s come back to installing the lamp stack. The first step we will take is to install Maria DB in Debian 11. MariaDB is a relational database that is open source, free, and is similar to MySQL. We will install it on Debian 11 by typing the following command in the terminal:

$ sudo apt install -y mariadb-server mariadb-client

To verify the installation type the following in your terminal:

$ mariadb --version

Now that we have successfully installed the MariaDB database let’s start MariaDB with the following command:

$ sudo systemctl start mariadb

To enable MariaDB type the following command in your Debian 11 Terminal:

$ sudo systemctl enable mariadb

Now that everything is set, let us secure our database by typing the following command in your terminal:

$ sudo mysql_secure_installation

It will ask a series of questions and depending on your preference you can set them. To indicate none or use default value we will press Enter. We set the configurations like shown below:

  • Set root password? Enter
  • Switch to unix_socket. Y
  • Change the root password? Y
  • Remove anonymous users? Y
  • Disallow root login remotely? Y
  • Remove test database access to it? Y

Now that we are done with making our server secure and configuring MariaDB let us test MariaDB by typing the following command in your terminal:

$ mysql -u root -p

Congratulations! We have successfully installed MariaDB on Debian 11. To exit the database type exit and you will see the message bye::

Step3: Installing Apache

On Debian 11 operating system the apache web server package is already available by default. We just have to execute the following install command:

$ sudo apt install -y apache2 apache2-utils

We can confirm the installation by typing the following command which will give us the Apache version and build:

$ sudo apache2 -v

By default when we install the Apache, it is automatically started. However, if you want to check the status type the following command in your terminal:

You will see the status as active which confirms that it is enabled. Press CTRL+C to exit.

If you want to reload a service type the following command in your terminal:

$ sudo systemctl reload apache2

After this you have to enable Apache again for which you can use the following command:

$ sudo systemctl enable apache2

If you want to view the full status of Apache then type the following command on your terminal:

$ sudo apt -y install elinks

After this type the following command and you will see the full status:

$ sudo apache2ctl fullstatus

Now open your browser and type Debian Ip or server Ip in the search bar. When you click enter you will see the Apache Default page:

You can find the IP address by typing the following command in your terminal:

$ ip a

Step4: Installing PHP

Now that we are done with installing the MariaDB database and Apache server let us install Php in Debian 11 system. To install PHP on Debian 11 type the following command in your terminal:

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

This will install PHP on Debian without any errors. You will see the following output:

We can verify the PHP installation by typing the following command in terminal:

$ php -v

Congratulations! We are done with installing the main tools in the Lamp stack.

Testing Lamp Stack

We will create a PHP script which we will use to test our Lamp stack installation. For this purpose type the following command on your Debian 11 terminal:

We have invoked the function phpinfo() and now we will go to the following link:

http://IpAddress/phpinfo.php

Replace the IP address keyword in the above link with your system ip address. If you see the following output on your browser then you have successfully set up Lamp stack.

This webpage will give detailed information about Apache web server as well as PHP.

Conclusion

Lamp stack means Linux used as an operating system, Apache as a web server, MySQL/MariaDB as the database where all our data will be stored, and PHP where all the processing and handling content happens. Lamp stack is a blessing for web developers and that is why it is very popular.

In this article, we took your hand and walked you through every little and major step in setting up a Lamp stack(Apache, MariaDB, and PHP).