Setting up Apache 2, MariaDB 10.x, PHP 7.x and phpMyAdmin on Ubuntu 16.04 — LAMP

Requirements

Install Apache

sudo apt install apache2 -y

# Confirm installation:
apache2 -v

# Outputs:
# Server version: Apache/2.4.18 (Ubuntu)
# Server built:   2017-09-18T15:09:02

Whitelist Apache from ufw Firewall

# Get name of Apache2 app
sudo ufw app list

# Outputs:
# Available applications:
#   Apache
#   Apache Full
#   Apache Secure
#   OpenSSH

# to get info for each
sudo ufw app info "Apache Full"

# Outputs:
# Profile: Apache Full
# Title: Web Server (HTTP,HTTPS)
# Description: Apache v2 is the next generation of the omnipresent Apache web
# server.
# 
# Ports:
#   80,443/tcp

# Add to firewall
sudo ufw allow in "Apache Full"

Confirm that Apache was whitelisted from firewall by visiting your server’s public IP address via browser:

http://your.server.ip.address

Update Global ServerName to suppress warning on apache2 config test

If you want to your domain to use the server’s public folder, use it as ServerName, for this guide, we will use the IP Address of the server

# Get IP Address
curl https://canihazip.com/s

sudo vim /etc/apache2/apache2.conf

# Set
ServerName replace.with.your.ip.address

# Test
sudo apache2ctl configtest

# Restart apache
sudo service apache2 restart

Install MariaDB

sudo apt install mariadb-server -y

# check version:
mysql --version

# Outputs:
# mysql  Ver 15.1 Distrib 10.0.31-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

# Setup install
sudo mysql_secure_installation

be guided by the following answers when prompted

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!

Remove anonymous users? [Y/n] Y
 ... Success!

Disallow root login remotely? [Y/n] Y
 ... Success!

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reload privilege tables now? [Y/n] Y
 ... Success!