LAMP – Linux, Apache, MySQL, PHP

LAMP is a term commonly given to a configuration of a linux based web server. It is based on:

  • L inux – The operating system. Raspbian is a flavor of linux.
  • A pache – The Web Server Software – allowing html and other types of content to be served up.
  • M ySQL – A popular, free and vary capable Database.
  • P hp – A scripting language that is suited for Web Development.


Ensure Raspbian is fully up to date. If you don’t know how then check out my guide here: Updating Raspbian.

Install Apache

sudo apt-get install apache2

Install MySQL / MariaDB

MariaDB 10.1 is now the default mysql server in Raspbian Stretch. It should be installed with

sudo apt-get install mariadb-server

you should then secure your installation by running:

sudo mysql_secure_installation

Although you will be invited to set a root password, MariaDB trusts the OS authentication over socket authentication. Therefore you can log on to mysql without a password using:

sudo mysql -u root

I recommend you then create another ‘administrator’ user with all privileges. In this example the user is called pi-resource. Once you have the SQL prompt up:

CREATE USER 'pi-resource'@'localhost' IDENTIFIED BY 'some_password';
GRANT ALL PRIVILEGES ON *.* TO 'pi-resource'@'localhost' WITH GRANT OPTION;

Install Php

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

Note that:

  • php7.0 is the main php programme
  • libapache2-mod-php7.0 is the module that links Apache with PHP allowing Apache to render PHP content
  • php7.0-mysql is the library that enables PHP to interface with the MySQL database

You can check what other modules are available for download with:

sudo apt-cache search php7-*

Whilst PHP7.2 is the latest version, the current version of Raspbian (Stretch 4.9) does not support it without a bit more hacking – so unless you really need 7.2 I highly recommend you stick with 7.0 for now.

Quick Test

Using an internet browser, if you now browse to your Raspberry Pi (in this example mine is on you should see the Apache2 default page being served up:

apache2 default web page
apache2 default web page