How to Install LAMP Stack on Ubuntu 20.04

Install LAMP Stack on Ubuntu 20.04

In this article, we will have explained the necessary steps to install and configure a LAMP Stack on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

LAMP is a complete package to run any web application on a server. LAMP signifies the Linux, Apache, MySQL, and Php. Apache is used as the webserver for hosting an application whereas MySQL is used as systematic data storage of application and Php is a popular server-side scripting language that is used for web development as well bridging the gap between application and the database.

Install LAMP Stack on Ubuntu 20.04

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install Apache.

Apache Webserver packages are available on Ubuntu 20.04 official repositories. All that’s needed is the execution of install command with sudo:

sudo apt install apache2 apache2-utils

After it’s installed, Apache should be automatically started. Check its status with systemctl.

systemctl status apache2

Step 3. Install MySQL.

The next component of your LAMP Stack on Ubuntu 20.04 is MySQL. Begin by updating the repositories and installing the MySQL package:

sudo apt install mysql-server

Once the package installer has finished, we can check to see if the MySQL service is running:

sudo service mysql status

After that, you should now run mysql_secure_installation to configure security for your MySQL server on Ubuntu 20.04:

sudo mysql_secure_installation

Step 4. Install PHP.

Now that we have both Apache and MariaDB installed, the missing piece is PHP. We will install PHP and standard extensions which are commonly used. Enter the following command to install PHP7.4 and some common PHP modules:

sudo apt install php7.4 libapache2-mod-php7.4 php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache

Once the PHP packages are installed restart the Apache service with:

sudo systemctl restart apache2

Check PHP version information:

php --version

Step 5. Testing PHP

Now you should create info.php file to test php to do so type following:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Then open the following link in your web browser and we will be able to see all the information about PHP and its other configurations: http://your-domain/phpinfo.php (replacing your IP address with the one above).

That’s all you need to do to install Apache, MySQL, PHP (LAMP) Stack on Ubuntu 20.04. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.