This guide will discuss how you as a user can install and setup Apache, MariaDB and PHP ( LAMP Stack) on Ubuntu 20.04 (Focal Fossa) Linux system. LAMP is an acronym for – Linux, Apache, MySQL/MariaDB and PHP. LAMP Stack is not a single package but a set of open-source tools that are used to power web applications and websites. Each component can be used independently to serve an application.
Install LAMP Stack on Ubuntu 20.04 (Focal Fossa)
LAMP Stack comprises of the following open source software applications.
- Linux – This is the operating system hosting the Applications.
- Apache – Apache HTTP is a free and open-source cross-platform web server.
- MySQL/MariaDB – Open Source relational database management system.
- PHP – Programming/Scripting Language used for developing Web applications.
You can use a Virtual Machine on Premise, in the cloud or a dedicated server to install and configure LAMP Stack on Ubuntu 20.04 (Focal Fossa) operating system. A
Step 1: Update Ubuntu 20.04 (Focal Fossa)
Before we can start installation of LAMP Stack packages on Ubuntu 20.04, it is recommended to keep the repository and packages up to date. Run the commands below to update your system.
sudo apt update && sudo apt -y upgrade
Step 2: Install MariaDB Database Server
MariaDB is a relational database management system forked from MySQL. It is free and Open source. Install it using the guide below.
After the installation, ensure you secure the d
- Setting strong root password
- Removing anonymous users
- Disabling remote login for root user.
testdatabase and access to it
Run the command below to secure your database server.
$ sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
Remove anonymous users? [Y/n] Y
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
Dropping test database…
Removing privileges on test database…
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Test MariaDB database installation.
$ mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 67 Server version: 10.3.19-MariaDB-1 Ubuntu 20.04 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SELECT VERSION(); +-------------------+ | VERSION() | +-------------------+ | 10.3.19-MariaDB-1 | +-------------------+ 1 row in set (0.001 sec) MariaDB [(none)]>
Step 3: Install Apache Web Server
Apache Web server packages are available on Ubuntu 20.04 official repositories. All that’s needed is execution of install command with sudo.
sudo apt install -y apache2 apache2-utils
Confirm Apache build and version.
$ sudo apache2 -v Server version: Apache/2.4.41 (Ubuntu) Server built: 2019-08-14T14:36:32
Service is started automatically after installation.
$ systemctl status apache2 ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2019-12-24 11:17:28 UTC; 20s ago Docs: https://httpd.apache.org/docs/2.4/ Main PID: 721 (apache2) Tasks: 55 (limit: 614) Memory: 4.9M CGroup: /system.slice/apache2.service ├─721 /usr/sbin/apache2 -k start ├─723 /usr/sbin/apache2 -k start └─724 /usr/sbin/apache2 -k start Dec 24 11:17:28 ubuntu20 systemd: Starting The Apache HTTP Server… Dec 24 11:17:28 ubuntu20 apachectl: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.10.1.122. Se> Dec 24 11:17:28 ubuntu20 systemd: Started The Apache HTTP Server.
You can restart service or reload when a change is made by using systemctl command.
sudo systemctl reload apache2
sudo systemctl enable apache2
To enable the service to start at boot, use
sudo systemctl is-enabled apache2
To view Apache server full status, use
$ sudo apache2ctl fullstatus
Your output should be similar to below.
Open server IP address on your browser to see default Apache page.
Step 4: Install PHP on Ubuntu 20.04
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. The version of PHP installed on Ubuntu 20.04 is PHP 7.3.
sudo apt install php libapache2-mod-php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
Enable Apache module if not already enabled then restart the Web Server.
sudo a2enmod php7.3
Confirm your PHP version.
$ php -v PHP 7.3.11-0ubuntu1 (cli) (built: Nov 20 2019 14:21:42) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.11-0ubuntu1, Copyright (c) 1999-2018, by Zend Technologies
Create a php script to test your LAMP stack installation.
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php
Open your server IP and URL:
This gives a detailed information about PHP and Apache web server. This marks the end our guide on how to Install LAMP Stack on Ubuntu 20.04 Linux system.
Other interesting guides: