Skip to main content

Raspbian LAMP

Table of Contents


LAMP is an acronym for ‘Linux, Apache, MySQL and PHP’.

When I first started professionally working with Linux and Web/intranet development the ‘P’ was principally for Perl, but PHP has largely replaced use of the Common Gateway Interface (CGI) with Perl scripts.

Here is how to install everything you will need on a Raspbian Raspberry Pi to run a full ‘LAMP stack’ and tinker with Web development with a database backend, and dynamically rendered pages written with PHP.


First do an update to make sure your package database is synchronised:

sudo apt-get update

Apache Web Server

Installing the Apache Web server:

sudo apt-get install apache2

To enable the Apache Web server:

sudo systemctl enable apache2.service

And to start it, although it will start at next boot if you have enabled it:

sudo systemctl start apache2.service

The MySQL Server and Client

Installing MySQL:

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Immediately after you have successfully installed the MySQL packages you MUST replace the default root password, like this:

mysqladmin -u root password 'enter-your-good-new-password-here'

You should NEVER use the root MySQL user for anything other than administration tasks in MySQL.

Don’t confuse the above with the root user of your Raspberry Pi.

PHP Components

Install PHP components:

sudo apt-get install php5 php5-mysql libapache2-mod-php5

These two packages are optional. I find the twig template system very useful, and SQLite will make it possible to use that type of database in place of MySQL:

sudo apt-get install php5-twig php5-sqlite

Now edit the file:


And uncomment the line which reads:


Note that this should not be needed anymore as conf.d is now used.

Test PHP

Edit the file:


And enter this as the contents:

<?php phpinfo(); ?>

You will need to use sudo to create and edit files in /var/www/html

After this, if you point a browser at your Pi like this:


You should see a page with a bunch of PHP stats.

If your Pi is called something else or you know the IP address enter that in place of ‘raspberrypi’.

Apache Modules for CGI Scripting

If you want to write CGI script in Perl:

sudo apt-get install libapache2-mod-perl2

And for CGI script in Python:

sudo apt-get install libapache2-mod-python

SQLite Database Client

If you are mucking about with SQLite databases you will want the SQLite command-line client for manipulating and creating databases:

sudo apt-get install sqlite3

CPAN Modules

These three CPAN Perl modules will be useful for CGI scripting with Perl:

sudo cpan install DBI
sudo cpan install DBD::mysql
sudo cpan install DBD::SQLite