How to Install LAMP Stack on Ubuntu 22.04


Easily deploy your favorite applications in seconds at an unbeatable price for your next projects.

Installing LAMP Stack on Ubuntu 22.04

The LAMP stack is a popular open-source platform used for web development. It consists of four main components: Linux, Apache, MySQL (or MariaDB), and PHP. In this guide, we will walk you through the steps to install and configure LAMP stack on Ubuntu 22.04.

Step 1: Update System Packages

Before installing any new software, it's always recommended to update the system packages to their latest versions. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade

Step 2: Install Apache Web Server

Apache is a powerful and widely used web server. To install Apache, run the following command:

sudo apt install apache2

Step 3: Install MySQL Database Server

MySQL is a popular relational database management system. You can install MySQL or its fork, MariaDB. To install MySQL, run the following command:

sudo apt install mysql-server

During the installation process, you will be prompted to set a root password for MySQL.

Step 4: Install PHP

PHP is a server-side scripting language used for dynamic web content. To install PHP, run the following command:

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

Step 5: Configure Apache to Use PHP

By default, Apache does not recognize PHP files. To enable PHP processing, we need to modify the Apache configuration file. Open a terminal and execute the following command:

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

Find the line that looks like this:

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

Move the "index.php" file to the beginning of the list, so it looks like this:

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

Save and close the file. Then, restart Apache for the changes to take effect:

sudo systemctl restart apache2

Step 6: Test the LAMP Stack Installation

To verify that your LAMP stack is working correctly, you can create a simple PHP script and access it from your web browser. Create a new PHP file called "info.php" using the following command:

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

Add the following PHP code to the file:

Save and close the file. Now, open your web browser and enter the following URL:


You should see a page that displays detailed information about your PHP installation.

Congratulations! You have successfully installed and configured the LAMP stack on Ubuntu 22.04. You are now ready to develop and host your web applications.

Refer A Friend
Get $25

Installing LAMP Stack
Ubuntu 22.04

Why Customers Love Us

What our customers say about us

Ready To Get Started For Free?

Create your free account today.