Install LAMP – Linux, Apache, MariaDB, and PHP

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

In this tutorial, I will use MariaDB as a replacement for MySQL; typically, MySQL is included in the LAMP stack. For installations of a LAMP stack on Linux, you will need Ubuntu or Debian’s latest distribution.

I will use Debian 10 to install the LAMP stack, but the same instructions you can apply on Ubuntu 18.04, 20.04, or the latest Ubuntu 22.04 LTS Server, 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. When you execute the Apache server’s command above, the image showed, “Do you want to continue? [Y/n]” Press Y and hit ENTER.

Now check, is the 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 type your IP address on the new browser tab in this format https://youripaddress.

checking apace server is running or not on ubuntu 18.04 or debian 10
Apache Default Index Page

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

The best practice for setting up firewall rules is manually checking up the security rules on the web-server or server instance’s setting.

Get Hostinger Hosting

Is Your Website Slow?

Migrate to Hostinger and get up to 80% off on all shared hosting plans. Hostinger is one best hosting in terms of performance and affordability. Starts at $1.99/mo.

Step – 2. Installing MariaDB Database

Our server is running, and now what we need, is storage that stores data in a structured table format. Obviously, table format data is elementary to manage, and most 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 versions can be easily configurable with MariaDB.

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

sudo apt install default-mysql-server


sudo apt install mariadb-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 go to the next step.

Now, our MariaDB installation was successful, and we need to secure it. MariaDB happens without any password protection, and there will be 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, the instance prompts us to enter the root password. Still, when we install a database for your clarity, there is no password, so hit ENTER.

Now the prompt is for the set new root password, Press Y and hit ENTER, and then it will ask to enter a new password when you enter then the second time will ask to Re-enter the 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. Still, 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 reload the privilege, Press Y and hit ENTER to reload all the privileges. These changes take immediate effect and make our database secure.

Simplify the Installation:

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 servers. After database installation, you can create a new database for every new project.

You can also create your database for a WordPress website, and even you can create multiple databases and install various WordPress websites on 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 database’s data in the frontend of any application or website.

We will install the 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:

 Must Read: - How To Install Latest PHP 8.0.x On Linux System? 

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 PHP 7.4x:

sudo apt update
sudo apt install php7.4

Install PHP 7.4x 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 php7.4-imagick php7.4-xmlrpc php7.4-soap php7.4-intl php7.4-mysql php7.4-cli php7.4-ldap php7.4-zip php7.4-curl libapache2-mod-php7.4
Installing PHP modules on Lamp stack

Install Apache with PHP modules:

sudo apt install apache2

Enable PHP FPM services:

a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm

Restart or Reload the Apache server:

systemctl restart apache2
systemctl reload apache2

Checking PHP version:

php -value
checking PHP version on the LAMP stack ubuntu

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

FAQs about LAMP installation

How do I install PHP?

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

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 be called LAMP stack.

How do I install a lamp in Windows 10?

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

How do I check if a lamp is installed in Ubuntu?

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

What is meant by the LAMP stack?

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

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.

How do I know if PHP is installed?

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

Do you need to install PHP?

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

How do I start a lamp in Linux?

When you install the LAMP stack’s software, it automatically starts.

Which is better XAMPP or LAMP?

XAMPP and LAMP are both useful stacks; XAMPP includes more software than LAMP.

Is LAMP a framework?

LAMP is a group of software.


LAMP stack is beneficial 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 on a single server, then the LAMP stack would be helpful.

You can use these simple steps to install the LAMP stack in any Ubuntu system or Debian system, and it will work perfectly. By chance, if you have encountered an error, please put your comments in 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.

Pronay Sarkar

I am Pronay Sarkar, I love to write about tech and stuff. I am a college graduate from the University of Delhi.

Leave a Comment

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