You might have just started building your dynamic web application in PHP, and you want to set up the LAMP Stack. LAMP term comes from the Linux Operating System, Apache server, MySQL database, and PHP language. Let’s get started with the installation of LAMP Stack on Ubuntu 20.04.

First of all, you should have sudo privileges on your system or log in as a root to perform the following tasks:

Update the System’s Package Repository

To get started with all the installation, it is the best practice to update the APT cache repository first so that all the latest applications can be installed smoothly.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image1-39.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

Once the apt-cache is updated, we are ready to move forward with the LAMP Stack installation.

Let’s first install MySQL.

Install MySQL on Ubuntu 20.04

Since MySQL is mostly used as a database with PHP and used to manage and store data to install MySQL on your ubuntu system, type the command given below.

$ sudo apt install mysql-server mysql-client

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image3-35.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

It will ask you to take additional disk space for the package to install, so press “y” to continue installing MySQL.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image2-37.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

Once MySQL is installed, check the version by typing this command.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image5-26.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

And to check that MySQL’s service is running or not on your ubuntu system, type this command to check the status.

$ sudo systemctl status mysql.service

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image4-30.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

If it is not active, you can start it by using the start keyword in the above command like this

$ sudo systemctl start mysql.service

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image7-20.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

To login to the MySQL’s shell, type the following command

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image6-24.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

It won’t ask you for any password for the first time.

Once you log in to MySQL’s shell, you can set up your password or perform any function related to the database in it.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image9-19.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

Now let’s exit through it and install the Apache 2 web server on the Ubuntu system.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image8-21.png" data-lazy- height="71" src="data:image/svg xml,” width=”326″>

Install Apache Web Server on Ubuntu 20.04

Apache 2 is a web server that handles the servers for hosting web applications. To install Apache 2 on your ubuntu system, run this command.

$ sudo apt install apache2

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image12-13.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

It may also prompt for taking a grant of additional disk space for the Apache’s installation, so press “y” to continue the installation process.

Once, Apache 2 web server is installed as well; you can check the status by typing the following command.

$ sudo systemctl status apache2

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image10-16.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

If it is active and running, then you are good to go with the installation of PHP; otherwise, start using the command

$ sudo systemctl start apache2

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image11-16.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

After starting it, let’s install the PHP now,

Install PHP on Ubuntu 20.04

PHP’s latest stable version can easily be installed on ubuntu from the APT package repository by typing the command given below in the terminal

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image13-13.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

Press “y” to continue the process if it prompts for taking additional disk space for installing PHP.

After the successful installation of PHP, you can check the version by typing the command

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image14-13.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

PHP version 7.3.4 is installed.

Install PHP Extensions

Now if you want to install some other basic PHP extension as well, which are required for the phpMyAdmin, For example,

  • php-curl
  • php-gd
  • php-mbstring
  • php-mysql
  • php-zip
  • php-json
  • php-xml

You can do so by typing the following command.

$ sudo apt install php-curl php-gd php-mbstring php-mysql php-zip php-json php-xml

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image15-12.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

Allow it to take additional disk space for the extensions to install by typing “y” and hitting the “Enter” button.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/image16-9.png" data-lazy- height="533" src="data:image/svg xml,” width=”786″>

This command will install all the required PHP extensions for running the phpMyAdmin.

So this is how you can install all the required packages on Ubuntu 20.04 and set up the LAMP Stack for building your dynamic web application.

Conclusion

This post contains the step by step guide to install and set up the LAMP stack on Ubuntu 20.04 LTS.

About the author

<img alt="Shehroz Azam" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/7011409B3A384F43A8417D1DAC68D179-150×150.jpg6016537cbfbdc.jpg" height="112" src="data:image/svg xml,” width=”112″>

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.