Set up LAMP(Linux, Apache, MySQL, PHP) Stack on Ubuntu 22.04

LAMP (Linux, Apache, MySQL, PHP) is a combined package that is used in the Linux distributions to manage static and dynamic websites. Dynamic websites are used to make online stores in which different types of information are taken from the users needed to store somewhere. To keep all this information, the MySQL database is used. Moreover, the Apache web server is utilized to run the website.

The LAMP can be installed in Ubuntu by following some simple steps, which are discussed in detail in this blog.

How to Set up LAMP (Linux, Apache, MySQL, PHP) Stack on the latest Ubuntu 22.04?

If you are planning to manage dynamic websites, you have to install LAMP by following the steps mentioned below.

Step 1: Update and Upgrade packages

how to handle linux files and direc...

Firstly, update and upgrade all the available packages in the default repository of Ubuntu:

$ sudo apt update && sudo apt upgrade -y

Step 2: Install Apache Webserver

The most used web server nowadays is Apache which can be installed from the package available in the repository of Ubuntu by running the command:

$ sudo apt install apache2 libapache2-mod-php8.1 -y

Step 3: Install MySQL

Use the MySQL database management system to manage the website data and install it with the help of the provided command:

$ sudo apt install mysql-server -y

Step 4: Configure Firewall

For using Apache, we have to allow port 80 and port 43. To firstly install “UFW” on your system:

$ sudo apt install ufw -y

Then, enable it UFW by running the command:

$ sudo ufw enable 

Allow incoming and outgoing connections for the port 80 and 43:

$ sudo ufw allow 80 && sudo ufw allow 43

Check the status of the UFW using the command:

$ sudo ufw status

Step 5: Install PHP

To Install PHP on Ubuntu, first add the “ondrej” PHP repository on Ubuntu using the add-apt-repository command:

$ sudo add-apt-repository ppa:ondrej/php

Then, install PHP on Ubuntu using the command:

$ sudo apt install php8.1 -y

Next, some important modules of PHP with the mentioned-below command:

$ sudo apt install php8.1-mysql php8.1-curl php8.1-xml -y

Step 6: Verify LAMP Setup

After performing previous steps, confirm that Apache web server, MySQL, and PHP all are working altogether by displaying a PHP Welcome page on localhost. For this, we will create a PHP file using the below-mentioned command:

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

In the opened file, add the given code and press “CTRL+O” to save it:

<?php

phpinfo();

?>

Open the web browser to go to the localhost address and run created PHP file:

$ localhost/phpinfo.php

As you can see, we have successfully set up the LAMP stack on our Ubuntu 22.04 system:

We have compiled the easiest method to set up LAMP on Ubuntu 22.04.

Conclusion

To set up the LAMP(Linux, Apache, MySQL, PHP) stack, firstly install Apache with the “$ sudo apt install apache2 libapache2-mod-php8.1 -y” command. Then, install the MySQL server using the “$ sudo apt install mysql-server -y” command. After that, add the “ondrej” PPA repository and install PHP by running the “sudo apt install php8.1 -y” command. This guide provided the method to set up the LAMP stack on Ubuntu 22.04.