This guide demonstrates how to install LAMP Stack ( MariaDB ) on Ubuntu 20.04 server which use’s Apache as a server, to use Ngnix as a server we need to Install LEMP Stack on Ubuntu version’s 20.04 / 18.04

Here is the detailed step by step process to install LAMP Stack on Ubuntu version 18.04 / 16.04

1. Installing Apache Web Server

Apache web server is one of the most popular web servers in the world, there active community and detailed documentation over server eventually makes it a great choice for hosting a website.

Install Apache using ( Advanced Package Tool ) apt:

sudo apt update
sudo apt install apache2

The sudo (Super User DO) command allows you to run programs with the security privileges.

Once you’ve entered command, apt will display you about the packages it will install and how much extra space they’ll take up. Press Y and hit ENTER to continue, and the installation will proceed.

Finally installation of apache is done. You can now verify that by visiting your server’s public IP address in your web browser.

http://your_server_or_ip_address

You will see the default Ubuntu 18.04 Apache web page, which is there for informational and testing purposes. As a result, web page should look something like below:

Apache2 default page

This page indicates that your web server is active.

2. Installing MariaDB

Now it is time to install MySQL database where your site can store information.

Install MariaDB using ( Advanced Package Tool ) apt:

sudo apt install mariadb-server mariadb-client

This command will show you a list of the packages that will be installed, along with the amount of disk space they’ll take up. Enter Y to continue.

Once MariaDB installation is complete, we should run a simple security script to remove some dangerous defaults and lock down access to your database system.

sudo mysql_secure_installation

Now configure the VALIDATE PASSWORD PLUGIN.

Note: Always use strong passwords for database credentials.

Type Y to enable, or any other key to continue without enabling and for rest of the question’s press “Y” enter.

Command photo copy for reference

Login as MariaDB root user.

sudo mysql -u root -p
Connecting to MySQL using a blank password.
use mysql;

update user set plugin='mysql_native_password' where user='root';

flush privileges;

quit;

3. Installing PHP and Modules

PHP is a server side scripting language which helps your code to communicate MySQL database and get information to display it on a web page or to enter given information into database.

Install PHP using ( Advanced Package Tool ) apt:

In addition, include some helper packages this time so that PHP code can run under the Apache server and talk to your MySQL database:

sudo apt install php libapache2-mod-php php-mysql

This should install PHP without any problems.

To check the PHP version that we have installed, run the following command:

php -v
PHP 7.4.3 (cli) (built: Mar 26 2020 20:24:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Testing PHP Page:

For testing the PHP, we will place one PHP file on to the default document root of Apache.

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

Now open a web browser and type the following into the web address to access the test page:

http://Your IP Address/info.php

The page will look like below.

Info.PHP page

Conclusion:

This brings us to the end of the guide ” How To Install LAMP STACK On Ubuntu 20.04 “. You can now host your website in the server. One of the popular thing you can do is install WordPress and design your own website or blog for your business.

To manage MySQL with GUI, we need to install phpMyAdmin. Operations such as the management of databases, tables, indexes, permissions, and so on are executed with the graphical user interface of phpMyAdmin.

Hope this tutorial is helpful and comment down if you have any query or issue.