LAMP

LAMP

This tutorial explains how to setup a Linux, Apache, MariaDB, PHP (LAMP), server.

Apache 2

Opening an web browser and entering a computer's IP in the URL bar is likely not to result in anything. This is because the computer isn't equipped with any software designed to handle requests from the web browser. A web server must be running of the computer so as to serve webpages in response to requests from a web browser. The two most popular web servers currently are Apache 2 and NGINX. This tutorial explains how to install the former. Apache can be installed using apt-get:

sudo apt-get install apache2

Once installed, apache will serve content stored in /var/www/html

PHP

Pages served by apache are commonly .html files. The HTML code fully describes the content of the page. Thus, the content will not change unless the HTML code does. Here, content is said to be static. However, sometimes, content needs to be dynamic. For example, a discussion forum keeps evolving as users post messages. For this purpose, PHP is used. It can be installed with apt-get:

sudo apt-get install php libapache2-mod-php

MariaDB

Very often, websites need to store and organize information. This is done using a database. Databases are managed by Database engines. The most popular one is probably MySQL and its fork, MariaDB. For this tutorial, MariaDB will be used. It can be installed using apt-get:

sudo apt-get install mariadb-server php-mysql

MariaDB secure installation

Once setup, MariaDB must be setup so as to increase security:

sudo mysqlsecureinstallation

The same actions can also be performed through command line:

sudo mysql -uroot -p$mariadbrootpassword -e "UPDATE mysql.user SET Password = PASSWORD('$mariadbrootpassword') WHERE User = 'root'"sudo mysql -uroot -p$mariadbrootpassword -e "DELETE FROM mysql.user WHERE User=''"sudo mysql -uroot -p$mariadbrootpassword -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')"sudo mysql -uroot -p$mariadbrootpassword -e "DROP DATABASE IF EXISTS test"sudo mysql -uroot -p$mariadbrootpassword -e "FLUSH PRIVILEGES"

Thus, a LAMP server can serve dynamic web pages with content coming from Databases.