Install the latest LAMP stack on Ubuntu 16.04 Server

lamp stack

A guide on installing the latest Apache2, Mariadb-server, and PHP7+ on Ubuntu 16

Note: You will need sudo access for the commands in this article

Video Walk-through Available

Step 1: Update / Upgrade Ubuntu

First, update ubuntu’s package manager.

sudo apt-get update && sudo apt-get upgrade

Next we need to install some packages that allows us to add more repositories to apt

sudo apt-get install software-properties-common language-pack-en

After those have been installed we need to add a few repositories maintained by Ondrej.  They contain the latest packages as maintained by the Debian Apache/PHP/Nginx teams with a couple of compatibility patches on top.

sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/apache2
sudo add-apt-repository ppa:ondrej/nginx

Once the new repositories have been added we need to update/upgrade the package manager again.

sudo apt-get update && sudo apt-get upgrade

After the latest packages have been installed we are finally ready to start installing the stack.

First we have Apache

sudo apt install apache2

Followed by php7 and the most common extensions I usually require.

Note: You can install any version of PHP from 5.6 to 7.2 by replacing 
the version number you want with 7.0
It is also not recommended to use 5.6 as it is EOL, and 7.1/7.2 may not be
supported by all packages out there

sudo apt install php7 php7.0-bcmath php7.0-curl php7.0-cli php7.0-gdphp7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-zip php7.0-json php7.0-tidy 

sudo apt install libapache2-mod-php7.0

Last part of the stack is MySQL server.  Here we are going to be installing Mariadb Server 10.  It is a drop in replacement for MySQL Server 5.7 and is regarded as a faster, more secure alternative 

sudo apt install mariadb-server

Followed by setting it up for the first time

sudo mysql_secure_installation

Here is the basic walk-through on the setup:

Enter current password for root - Press the Enter/Return key

Set root password? - Y
Type in a secure password twice - You are going to want something
secure here especially if you plan on using a webgui to manage your

Remove anonymous users? - Y - This removed the default/test user

Disallow root login remotely? - Y - Makes root user only accessible from
localhost /

Remove test database and access to it? - Y - Remove test databases/tables, a security threat and not for production

Reload privilege tables now? - Y - Refreshes the authentication tables,
enforces the changes above

Congratulations, you have successfully install the LAMP stack.

2 Comments to Install the latest LAMP stack on Ubuntu 16.04 Server

  1. […] to perform, we can enable services to be monitored.  Right now since we have only have ssh and apache installed we will go ahead and enable those to be monitored as well as repeat […]

  2. […] *NOTE* This guide assumes you have already installed the LAMP stackfrom Install the latest LAMP stack on Ubuntu 16.04 Server […]

Leave a Reply

Your email address will not be published. Required fields are marked *