How to Install LAMP on Ubuntu


LAMP is a popular software stack that consists of Linux, Apache, MySQL, and PHP. It is used to run dynamic web applications and websites. In this article, we will show you how to install LAMP on Ubuntu 20.04 LTS.

Step 1: Update your system

Before installing any software, it is always a good idea to update your system to the latest version. To do this, open a terminal and run the following commands:

sudo apt update
sudo apt upgrade

This will download and install any available updates for your system.

Step 2: Install Apache

Apache is the most widely used web server software in the world. It is responsible for serving web pages and files to the clients. To install Apache on Ubuntu, run the following command:

sudo apt install apache2

This will install Apache and its dependencies. You can verify that Apache is running by typing your server’s IP address or hostname in your web browser. You should see the default Ubuntu Apache web page.

Step 3: Install MySQL

MySQL is a popular relational database management system that stores and manages data for web applications. To install MySQL on Ubuntu, run the following command:

sudo apt install mysql-server

This will install MySQL and its dependencies. You will be asked to set a password for the root user of MySQL during the installation process. Make sure you choose a strong and secure password.

After installing MySQL, you should run a security script that will remove some insecure default settings and lock down access to your database. To do this, run the following command:

sudo mysql_secure_installation

You will be asked to answer a series of questions. You can follow the recommended answers, but make sure you remember your root password.

Step 4: Install PHP

PHP is a popular scripting language that runs on the server side and generates dynamic web pages. To install PHP on Ubuntu, run the following command:

sudo apt install php php-mysql

This will install PHP and its module for MySQL. You can verify that PHP is working by creating a test file in the web root directory of Apache. To do this, run the following commands:

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

This will open a text editor where you can paste the following code:

<?php
phpinfo();
?>

Save and close the file by pressing Ctrl+X, Y, and Enter. Then, open your web browser and type your server’s IP address or hostname followed by /info.php. You should see a page with information about PHP.

Step 5: Congratulations!

You have successfully installed LAMP on Ubuntu 20.04 LTS. You can now start developing your web applications using this powerful software stack.