How to Install a LAMP Stack on Ubuntu 19.04

First, check for any pending system upgrade.

apt update
apt upgrade

Installing Apache

apt install apache2

To configurare Apache.

 vi /etc/apache2/apache2.conf

File contents:

KeepAlive On
MaxKeepAliveRequests 50
KeepAliveTimeout 5

NOTE: apache.conf file contains information about apache configuation in that,

  • keepAlive will make website run faster by better utilization of server side memory[helps to reuse the connections]
  • MaxKeepAliveRequests it will restrict maximum number of request during connection.[it can be changed by user rquirements]
  • KeepAliveTimeout it defines three things: The total amount of time it takes to receive a GET request. The amount of time between receipt of TCP packets on a POST or PUT request The amount of time between ACKs on transmissions of TCP packets in responses.

To config multi-processing module in prefork module.

 vi /etc/apache2/mods-available/mpm_prefork.conf

File contents:

 <IfModule mpm_prefork_module>
        StartServers              5
        MinSpareServers           5
        MaxSpareServers          10
        MaxRequestWorkers        150
        MaxConnectionsPerChild   0
</IfModule>

NOTE: Can edit above based on your requirements.

To enable Firewall

To check ports which are enabled for "apache full Profile".

ufw app info "Apache Full"

Output:

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

NOTE: If ports are 80 and 443, then it is full enabled apache profile.

To enable HTTP and HTTPS Traffic.

ufw allow in "Apache Full"

To disable event module and enable prefork.

a2dismod mpm_event
a2enmod mpm_prefork

Restart apache.

systemctl restart apache2

Installing MySQL Server.

apt install mysql-server

To configurare MYSQL:

Login to Mysql shell.

mysql -u root

To Create Database.

CREATE DATABASE testphp;
GRANT ALL ON testphp.* TO 'client' IDENTIFIED BY 'password';

Exit shell.

quit

To configure additional security option.

mysql_secure_installation

NOTE: It will ask for set new password can skip and it will prompt for several permission can press "y" for yes and enter.

Installing PHP, Apache and MySQL support system.

apt install php7.2 libapache2-mod-php7.2 php-mysql

To installing cURL,JSON and CGI support.

apt install php-curl php-json php-cgi

To configurare PHP:

Open php.ini file and modify follwoing content.

vi /etc/php/7.2/apache2/php.ini

File content to modify:

error_reporting = E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR
max_input_time = 30
error_log = /var/log/php/error.log

NOTE: php.ini file contain other information also only search for above information and modify.

To create log directory and give permission to apache syatem.

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

Restart Apache:

systemctl restart apache2

Test the LAMP Stack.

Run the following command to display php information:

echo "<?php phpinfo(); ?>" > /var/www/html/phptest.php

And open your browser in local system and enter follwoing url.

http://ip_address/phptest.php

If LAMP Stack is installed correctly the browser will load php webpage.