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

APACHE

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

MYSQL

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_reporting = E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR
error_log = /var/log/php/error.log

Add this to mysqld.cnf

sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

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

One thought on “Install LAMP on Ubuntu 16.04

Leave a Reply

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