Install LAMP on Ubuntu 16.04

LAMP stack is a popular open source web platform commonly used to run dynamic websites and servers. It includes Linux, Apache, MySQL, and PHP and is considered by many the platform of choice for development and deployment of high-performance web applications which require a solid and reliable foundation.

Update the software sources list:

sudo apt-get update


Install apache2.4 fro Ubuntu repository

 sudo apt-get install apache2

Edit the apacheĀ  configuration file to adjust KeepAlive settings

 sudo vi /etc/apache2/apache2.conf
  KeepAlive off

The default multiprocessing module for PHP isĀ  Prefork module, But apache uses Event module. So enable Prefork module and disable Event module

 sudo vi /etc/apache2/mods-available

Set values for mpm_prefork. These values are for 2GB Linode server

        StartServers            4
        MinSpareServers         20
        MaxSpareServers         40
        MaxRequestWorkers       200
        MaxConnectionsPerChild  4500

Disable the event module and enable prefork module

sudo a2dismod mpm_event
sudo a2enmod mpm_prefork

Restart Apache

 sudo systemctl restart apache2


Install Mysql package

 sudo apt-get install mysql-server

To connect to MySQL

 mysql - u root - p

View Databases

 show databases;

Create database

 create database test_db;

PHP 7.0

Install PHP and the application Repository also Apache support, and MySQL support

sudo apt-get install php7.0 php-pear libapache2-mod-php7.0 php7.0-mysql

To enable more descriptive errors, logging, and better performance edit the configuration file

sudo vi /etc/php/7.0/apache2/php.ini
max_input_time = 30
error_log = /var/log/php/error.log

Create the log directory for PHP and give ownership to the Apache system user

sudo mkdir /var/log/php
sudo chown www-data /var/log/php

Restart apache

sudo systemctl restart apache2

Leave a Reply

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