You will learn how to install the LAMP stack on your Ubuntu VPS server and begin developing dynamic websites that can be hosted on a stable, fast, and secure server environment. Let’s get started…


Assuming that you have a running Ubuntu 22.04 Linux system with sudo (or root) privileged access. Access your system and open a terminal. It will be good to update the package manager cache and upgrade currently installed packages. To do this execute: Let’s begin the LAMP (Linux, Apache, MySQL, and PHP) stack installation on Ubuntu 22.04 Jammy Jellyfish Linux system.

Step 1: Install PHP (Programming Languege)

First, you need to decide on the PHP version to install on your system. You can also install multiple PHP versions on a single system. Currently the repository contains PHP 5.6, PHP 7.1, 7.2, 7.3, 7.4 and PHP 8.0, 8.1. The below instruction will install PHP 8.1. Please change the version as per your requirements. The ondrej/php PPA contains all PHP version’s for Ubuntu systems. So add this repository in your system with command below: Now update the apt cache and install PHP 8.1. This will install PHP on your Ubuntu system along with some useful PHP extensions.

Step 2: Install Apache (Web Server)

Generally, the PHP installation also installs Apache and its module on your system. Still, you can run the following commands to confirm the installations. This will install Apache and start the service. Now, you need to allow web server ports in the firewall. To allow ports 80 and 443 in the UFW firewall, execute the following commands. Open a web browser on your system and type the server’s IP in the address bar. You will get the default Apache server page

Step 3: Install MySQL (Database Server)

The default Ubuntu repositories contain MySQL 8.0. Which can be directly installed using the package manager. To install the available MySQL server version, execute the following command. Once the installation is finished, you can secure the MySQL server by executing the following command. This will ask for a few questions to secure the MySQL server. You have secured the MySQL server in the LAMP stack on Ubuntu 22.04 Linux system. Remember that the above password set for the root accounts is used for remote users only. To log in from the same system, just type mysql on terminal.

Step 4: Installing Other Required Packages

You may also need to install modules like MySQL and other extensions for PHP based on the application requirements. Use the following command to find our available PHP extensions. The above command will list all available PHP7 modules for installation, Let’s begin the installation of modules.

Step 5: Test LAMP Setup

You have successfully completed the installation of Apache, MySQL, and PHP on the Ubuntu 22.04 Linux system. To verify the PHP integration with Apache, create a PHP script (example: info.php) on the website document root and write the below content.

Now access this file in the web browser. It will so all the details about versions and installation.


This tutorial helped you to set up the LAMP stack on Ubuntu 22.04 LTS system. Now, you can host PHP-based web applications on your server.

How To Install LAMP Stack on Ubuntu 22 04   TecAdmin - 18How To Install LAMP Stack on Ubuntu 22 04   TecAdmin - 98