How to Install LaMp on Debian 12

The LaMp is the collection of the software applications that are used to develop the website. It includes the Linux Apache, MySQL database, and the package of the PHP programming language. 

The Apache is the web server that is used to serve the content of the website through an internet connection. The next thing in web development is the database to store and manage the contents of the website. For this purpose, MySQL database is used which is the relational database and manages the website’s data in the tabular form. The last thing is to design the website and for this purpose, PHP programming language is used. 

The complete guide to set up the LaMp on Debian 12 has been demonstrated with the step-by-step guide. 

What is the Method to Set Up the LaMp on Debian 12?

First, make sure all the packages of Debian 12 including the application software and their dependencies are up to date. For this purpose, start up the Debian’s terminal and run the next-mentioned command:

$ sudo apt update

Now set up the LaMp on Debian 12 by following the instructions explained in the next steps.

Step 1: Install MySQL on Debian 12

After the assurance that all the packages are up to date, download the debian package of MySQL with the wget command:

$ sudo wget

When the execution of the command is completed, list down the contents of the directory to confirm the download:

$ ls

The Debian package of MySQL has been downloaded successfully, then, install the downloaded package of MySQL by running the command:

$ sudo apt install ./mysql-apt-config_*_all.deb

 Update the repository of Debian to add the downloaded MySQL package in it:

$ sudo apt update

Also, install the server of MySQL on Debian by running the command:

$ sudo apt install mysql-server -y

Finally, start the MySQL database using the “systemctl” command:

$  sudo systemctl start mysql.service && systemctl is-active mysql

MySQL is not only installed but also running successfully on Debian 12 as can be seen above.

Step 2: Secure the MySQL Database

After the MySQL is installed and running, secure it by running the command:

$ sudo mysql_secure_installation

Restart the MySQL database to apply the changes made in this step:

$  sudo systemctl restart mysql.service

Everything is being set about the MySQL database on Debian 12. 

Some people used MariaDB instead of MySQL which is also good. But conventionally, MySQL is being used to install the LaMp on Debian. 

Step 3: Install and Configure the Apache2 on Debian 

Now to install the Apache’s package on Debian 12 with the command:

$ sudo apt install apache2 apache2-doc -y

When the Apache server is installed, configure the user directories on Debian 12. To start the mentioned configuration, first run the command:

$ sudo a2enmod userdir

Now create the Apache configuration file by creating the file with the nano text editor:

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

Type the following mentioned lines in the file:

<IfModule mod_userdir.c>
        UserDir public_html
        UserDir disabled root

        <Directory /home/*/public_html>
                AllowOverride All
                Options MultiViews Indexes SymLinksIfOwnerMatch
                <Limit GET POST OPTIONS>
                        Require all granted
                <LimitExcept GET POST OPTIONS>
                        Require all denied

Using the shortcut, CTRL+S saves the file and exits the nano text editor. Create a new directory with the “User” instead of the root user:

$ mkdir /home/$USER/public_html

Change the group as the root user with the execution of the command:

$ sudo chgrp www-data /home/itslinuxfoss/public_html

In the above command, replace the “itslinuxfoss” with your unique username. Finally, restart the Apache server to apply the new changes:

$ sudo service apache2 restart

Confirm the status of the Apache web server by running the command:

$ sudo systemctl status apache2

After installation of the Apache2, the web server is ready to serve the web developers on Debian 12. 

Step 4: Install the PHP on Debian 

The final step of setting up the LaMp stack is the programming language for the script of the website. For this purpose, install the PHP on Debian by running the command:

$ sudo apt install php php-mysql -y

If web developers are willing to install the Python instead of the PHP, then they are supposed to run the command:

$ sudo apt install python3 libapache2-mod-python -y

If the Perl programming language is supposed to install in the LaMp stack, execute the command:

$ sudo apt install perl libapache2-mod-perl2 -y

After installing any of the above programming languages, the “P” component of the LaMp has been installed. 

How to Test the Setup of the LaMp on Debian?

When the LaMp is set up successfully, it’s time to test it on Debian. First, create a text file with the nano text editor:

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

Now add the following function of the PHP in the opened file:

<?php phpinfo(); ?>

Save the file and exit the text editor using the CTRL+X as this function will display the information of the installed PHP on Debian. Finally, open the web browser and visit the localhost URL to display the PHP information:


The output is displaying the successful installation of the LaMp stack on Debian 12. 

How to Uninstall the LaMp on Debian?

To uninstall and remove the LaMp on Debian 12, run the following command:

$ sudo apt purge php php-mysql apache2 apache2-doc mysql-server -y

The above command will uninstall and remove the installed packages of Apache web server, PHP, and MySQL.


The LaMp stack can be installed on Debian 12, by installing the packages of Apache web server, MySQL database and PHP programming language. These packages are used by the web developers to develop the websites. 

Nginx is also used instead of Apache and MariaDB instead of MySQL. Likewise, the Perl and Python programming languages are used instead of the PHP on Debian. 

This blog explained the installation of the LaMp on Debian with the complete guide.