Install LAMP – Linux, Apache, MariaDB, and PHP on Debian

🖊 Written by Updated on

LAMP stack is a group of software or resources for the web application. LAMP stands respectively for Linux, Apache, MariaDB or MySQL, and PHP. These all software are open source and gives power to a huge number of websites.

In this tutorial I am going to use MariaDB as a replacement of MySQL, typically MySQL is included in the LAMP stack. Installations of a LAMP stack on Linux, you will need to Ubuntu or Debian latest distribution.

I am going use Debian 10 to install LAMP stack, but the same instructions you can apply on Ubuntu 18.04 or the latest Ubuntu 20.04, so let’s start 😃.

STEP – 1. Installing Apache Server

Apache server is one of the widely used and very popular web servers. Apache is easy to use and you can find a huge amount of documentation and tutorials over the Internet.

$ sudo apt update

$ sudo apt install apache2
installing apache2 server on LAMP stack

This apache server installation process will require sudo permission and when you execute the command for installing the Apache server as above the image shown “Do you want to continue? [Y/n]”, Press Y and hit ENTER.

Now check, is Apache server working or not? There are two simple methods to check apache status, first execute the following command:

$ sudo service apache2 status
apache server-status checking by executing command on debian

Or you can simply type your IP address on the new browser tab as this format https://youripaddress.

checking apace server is running or not on ubuntu 18.04 or debian 10

If the second method doesn’t work or as above in the image shown the apache server page doesn’t work then probably there is an issue with firewall rules.

The best practice for set up firewall rules is manually checkup the security rules on the webserver console or the server instance’s setting.

STEP – 2. Installing MariaDB Database

Our server is running and now what we need, storage that store data in a structured table format. Obviously, table format data is very easy to manage and most of the websites and web developers prefer to use table structured storage.

MariaDB is a forked version of the MySQL database developed by Oracle. Debian and Ubuntu’s latest version can be easily configurable with MariaDB.

For installing MariaDB for our LAMP stack, execute the following command:

$ sudo apt install default-mysql-server
installing MariaDB MySQL database on the LAMP stack

When we execute the command the machine will prompt you to continue or not, Press Y and hit ENTER, this process will take less than 20 seconds, and after we will good to go for the next step.

Now, our MariaDB installation was successful, we need to secure it. MariaDB happens without any password protection and there will an anonymous user for a test database, so we need to remove that user and the test database.

For securing the MariaDB execute the following command:

$ sudo mysql_secure_installation
Securing MariaDB 1 Database on LAMP stack Debian 10

As you can see in the image above, when we execute the command for securing MariaDB then the instance prompts us to enter the root password, but for your clarity when we install a database then there is no password, so simply hit ENTER.

Now the prompt is for the set new root password, Press Y and hit ENTER, then it will ask to enter a new password when you enter then the second time will ask for Re-enter new password. To re-enter the password and hit the ENTER key.

The next prompt will be removing anonymous users, so definitely, Press Y and hit the ENTER button. As you can see in the image above, the MariaDB installation adds an anonymous user so anyone can log into the database without having a user account. So, the best practice is that, remove anonymous users.

Securing MariaDB Database on LAMP Stack

The next prompt is “Disallow root login remotely?” That means if you enable this feature then you can access your database from any network or location, but it could be harmful to your projects or websites because hackers can inject malicious code or even hijack your websites. So, Disallow the remote login by pressing Y and then hit ENTER.

The next prompt is the “Remove test database?” Definitely press Y and hit ENTER for removing the test database that has no password. This test database comes during the MariaDB installation.

Next and last prompt to reloading the privilege, Press Y and hit ENTER to reload all the privileges. These changes take immediate effect and make our database secured.


Execute command > Hit enter for current root password > Press Y and hit ENTER for new password > Set New Password > Re-enter New Password > Press Y and Hit ENTER for delete anonymous users > Press Y and Hit ENTER for Disallow remote login > Press Y and Hit ENTER for Delete test Database > Press Y and Hit ENTER for Reload Privileges.

Those are the simple steps of installations of MariaDB for the LAMP stack on Ubuntu and Debian server. After database installation you can create a new database for your every new project, also you can create your database for WordPress website, and even you can create multiple databases and install multiple WordPress websites in a single server.

Next to installation steps for the latest PHP.

STEP – 3. Installing PHP 7.4x

PHP is a popular and widely used scripting language in the world. PHP – Hypertext Preprocessor, is very important to run a web application or website. You know the popular platform WordPress, which is based on PHP. PHP script runs in the backend and dynamically shows the data from the database in the frontend of any application or website.

We are going to install latest version of PHP, so our application and projects would be secured from hackers. For installing the latest version of PHP 7.4x, use the following commands:

#Update System and Reboot:

$ sudo apt update

$ sudo apt upgrade -y && sudo reboot

#Add Sury PHP PPA Repository and key data:

$ sudo apt -y install lsb-release apt-transport-https ca-certificates

$ sudo wget -O /etc/apt/trusted.gpg.d/php.gpg

$ echo "deb $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list

#Install latest PHP 7.4x:

$ sudo apt update

$ sudo apt -y install php7.4

#Install latest PHP modules:

$ sudo apt install php7.4-common php7.4-cli php7.4-bz2 php7.4-curl php7.4-gd php7.4-intl php7.4-json php7.4-readline php7.4-xml php7.4-zip php7.4-fpm php7.4-bcmath php7.4-mbstring
Installing PHP modules on Lamp stack

#Install Apache with PHP modules:

$ sudo apt install apache2 php7.4 libapache2-mod-php7.4 php7.4-common php7.4-mbstring php7.4-xmlrpc php7.4-soap php7.4-gd php7.4-xml php7.4-intl php7.4-mysql php7.4-cli php7.4-ldap php7.4-zip php7.4-curl

#Enable PHP FPM services:

$ a2enmod proxy_fcgi setenvif

$ a2enconf php7.4-fpm

#Restart or Reload Apache server:

$ systemctl restart apache2

$ systemctl reload apache2

#checking PHP version:

$ php- value
checking PHP version on the LAMP stack ubuntu

PHP installation also has been done, now you can deploy any kind of web application or website using these resources.


LAMP stack is very useful when we work on multiple projects and we have a single server. It is a powerful group of software that makes it easier to develop websites and web applications. If you want to install multiple WordPress sites in a single server then the LAMP stack would be helpful.

You can use these simple steps to install LAMP stack in any Ubuntu system or Debian system, it will work perfectly. By chance, if you have encountered an error, please put your comments on the box. We are willing to share good knowledge with everyone.

Thank you! If you think this article would be helpful for your close one, please share 💚.

FAQs about LAMP installation

  1. How do I install PHP?

    Use the following commands for installing latest PHP $ sudo apt update $ sudo apt -y install php7.4

  2. How do you install a LAMP stack?

    You need to install Apache, MySQL, and PHP one by one individually on a Linux system. Then it would called LAMP stack.

  3. How do I install a lamp in Windows 10?

    You can install a LAMP stack on Windows 10 using Bitnami Xaamp or LAMP software.

  4. How do I check if a lamp is installed Ubuntu?

    Check Apache status, MySQL status, and PHP status individually in terminal using these commands respectively:
    $ services apace2 status
    $ mysql
    $ php -value

  5. What is meant by the LAMP stack?

    LAMP stack is a group of opensource software and L stand for Linux, A stand for Apache, M stand for MySQL, and P stand for PHP.

  6. What can you do with a LAMP server?

    LAMP server is very useful, it is a group of software that gives power to your Web application project or website projects.

  7. How do I know if PHP is installed?

    Open Terminal and type $ php -value , it will shows you the PHP versions if installed.

  8. Do you need to install PHP?

    For LAMP stack, yes need to download PHP and also for Web development.

  9. How do I start a lamp in Linux?

    When you install one by one the LAMP stack’s software, it automatically start.

  10. Which is better xampp or lamp?

    XAMPP and LAMP both are usefull stack, XAMPP includes more software than LAMP.

  11. Is lamp a framework?

    LAMP is a group of software.


I am a blogger and a digital marketer based in Delhi, India. I have a passion for blogging and influencing people from my work. I am a student pursuing a Bachelor's Degree in Science from Delhi University.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap