Setting up a LAMP Stack on Ubuntu 18.04 LTS

From Thom's wiki
Jump to navigation Jump to search

This document is work in progress



But we are going to do some additional things:

  • Optimize SSL handshakes
  • Add HTTP/2.0 support


Installing Ubuntu

Install a Mailagent

To make your website to be able to send e-mails, you most likely have to install an mailagent

 sudo apt install postfix


Install Apache

 sudo apt install apache2


Installing MariaDB or MySQL

There is a battle which one is better MySQL or MariaDB. I do prefer MariaDB, because it is 100% open source.

To download and install mariaDB follow the instructions at MariaDB Repositories Setup Tool


Installing PHP

At the moment of this writing PHP 5.6 is depreciated. PHP 7.0 means a huge performance upgrade from PHP 5.6. PHP 7.1 will also deliver a major performance boost over PHP 7.0. And PHP 7.2 will again deliver a performance boost over PHP 7.1. Ubuntu 18.04 LTS is shipped with PHP 7.2

PHP 7.2 can be installed as follows:

 sudo apt install php7.2 libapache2-mod-php7.2 php7.2-opcache php7.2-mysql php7.2-gd php7.2-intl php7.2-mbstring


Get a Let's encrypt SSL Certificate

Add HTTP/2.0 support to Apache

In my experience when you run heavy websites, like the Magento webshop, you can cut loading times of your website by about 50% by enabling the HTTP/2.0 protocol. The HTTP/2.0 protocol is an major update to the over 20 years old HTTP/1.1 protocol. For more information please read HTTP/2.0 Wikipedia page.

Use the following commands to enable HTTP/2.0 on your Ubuntu 18.04 LTS LAMP stack:


Enable the http/2.0 module:

 sudo a2enmod http2

Disable the standard mod_php module:

 sudo a2dismod php7.2
 sudo a2dismod mpm_prefork
 sudo a2enmod mpm_event proxy_fcgi setenvif
 sudo apt install php7.2-fpm

Start the php7.2-fpm service:

 sudo systemctl start php7.2-fpm

Enable the php7.2-fpm service to start at boot time:

 sudo systemctl enable php7.2-fpm

Enable the php7.2-fpm service for use with Apache:

 sudo a2enconf php7.2-fpm

Edit your configuration files in /etc/apache2/sites-available. The HTTP/2.0 protocol only works over SSL (TSL) secured connections, so you only need to alter every virtualhost container. Add the following statement after every <VirtualHost *:443> line:

   Protocols h2 h2c http/1.1

Now restart Apache

 sudo systemctl restart apache2

Test your website to check wether http/2 is working using the KeyCDN http/2 test tool