How To Install LAMP and dev-site on Ubuntu 18.04

LAMP stands for Linux, Apache,  MySQL and PHP


Make sure there is disk space! At least 150 MB

sudo apt update && sudo apt upgrade

Set host name

hostnamectl set-hostname bkhme

Update hosts file /etc/hosts. Add     bkhme


sudo apt install tasksel
sudo apt install apache2
sudo apt install mysql-server
sudo apt install php7.2 libapache2-mod-php7.2 php-mysql


sudo apt install php-curl php-json php-cgi


sudo gedit /etc/conf/apache2.conf &

Turn on KeepAlive (was already on in my test on Ubuntu 18.04)

KeepAlive On

For a 2GB Linode:

sudo gedit /etc/apache2/mods-available/mpm_prefork.conf &  add
<IfModule mpm_prefork_module>
        StartServers            4
        MinSpareServers         3
        MaxSpareServers         40
        MaxRequestWorkers       200
        MaxConnectionsPerChild  10000

Disable the event module and enable pitchfork (was already done in my test on Ubuntu 18.04)

sudo a2dismod mpm_event

sudo a2enmod mpm_prefork

Restart the apache server

sudo systemctl restart apache2
Copy server configuration for your example website
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/bkhme.conf

sudo gedit /etc/apache2/sites-available/bkhme.conf &

Replace with bkhme. Add directories

        Require all granted

	ServerName bkhme
	ServerAdmin bjorn@bkhme
	DocumentRoot /var/www/html/bkhme/public_html
	ErrorLog /var/www/html/bkhme/logs/error.log
	CustomLog /var/www/html/bkhme/logs/access.log combined

>>sudo mkdir /var/www/html/bkhme/{public_html,logs}

Disable default server and reload apache

sudo a2dissite 000-default.conf
systemctl reload apache2

Login to mysql and create a database

sudo mysql -u root

GRANT ALL ON webdata.* TO 'webuser' IDENTIFIED BY 'password';



Setup additional security

sudo mysql_secure_installation

sudo gedit /etc/php/7.2/apache2/php.ini &


max_input_time = 30
error_log = /var/log/php/error.log

Create log directory and give ownership to Apache system user

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

;Restart Apache
sudo systemctl restart apache2


If you plan on using your LAMP stack to host a WordPress server, install additional PHP modules: sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc
Test code for PHP file in /var/www/html/bkhme/public_html/phptest.php
    <title>PHP Test</title>
    <?php echo '<p>Hello World</p>';

    // In the variables section below, replace user and password with your own MySQL credentials as created on your server
    $servername = "bkhme";
    $username = "bjorn";
    $password = "continuous";

    // Create MySQL connection
    $conn = mysqli_connect($servername, $username, $password);

    // Check connection - if it fails, output will include the error message
    if (!$conn) {
        die('<p>Connection failed: <p>' . mysqli_connect_error());
    echo '<p>Connected successfully</p>';