How to set up Raspberry Pi 3 LAMP web server

In the previous articles, I covered how to install Ubuntu and setup WiFi on Raspberry Pi 3. Now, it is time to setup a web server. LAMP stack is a popular choice for hosting dynamic web sites. LAMP is an acronym for Linux, Apache, MySQL and PHP.

With 1GB memory and 4 ARM cpu cores in Raspberry Pi 3, it is more viable to host LAMP stack on Raspberry Pi for home and small business.

Linux

Since Raspberry Pi 3 was just released last month, at the moment, there are not too many Linux variants ported. Ubuntu is one of the available ones at the moment. To install it, please follow the instruction here.

Apache

It is actually quite simple to install Apache web server. From your superuser account, run the followings

sudo apt-get install apache2 -y

The default home page is located at

/var/www/html/index.html

When you open the http://localhost in Firefox browser in Ubuntu, you will see the following page:

Apache2 installed on Raspberry Pi 3 with Ubuntu Linux
Apache2 installed on Raspberry Pi 3 with Ubuntu Linux

Alternative, you may find out the IP address of your Raspberry Pi 3 and open the home page by IP address like http://192.168.0.114

The following command reports the IP addresses.

ifconfg | grep "inet addr"

It returns 127.0.0.1 (local host), 192.168.0.113 (Ethernet)  and 192.168.0.114 (WiFi)

how to report ip address of local host in Ubuntu Linux
how to report ip address of local host in Ubuntu Linux

 

PHP

PHP is a server-side scripting language developed by Zend Technologies. It is widely used for web developement. To install PHP, run the following commands

sudo apt-get install php5 -y
php -v

It should look like the followings once it is successfully installed

Report PHP version in Linux
Report PHP version in Linux

 

To report more information about PHP installed, create a file as follows

sudo emacs /var/www/html/info.php

put the following line in /var/www/html.info.php  save it and exit out of Emacs

<?php phpinfo(); ?>

Now open the web page from your browser http://192.168.0.114/info.php
where 192.168.0.114 is the IP address of my Raspberry Pi 3

PHP information on Raspberry Pi 3 running Ubuntu Linux
PHP information on Raspberry Pi 3 running Ubuntu Linux

MySQL

Is it a widely used open source RDBMS (Relational Database Management System) on Linux and other operating systems.

Run the following commands to install MySQL

sudo apt-get install mysql-server -y

During the installation, you will be asked to create a password for MySQL

Setting MySQL password during installation
Setting MySQL password during installation

If this screen doesn’t show up, it is probably due to some package dependency issues. You may want to run the following commands to try installing MySQL again

sudo apt-get update
sudo apt-get install mysql-server -y

 

A few packages (like mysql-client, mysql-client-core and etc.) will be installed as part of process.

To check to see if mysql is running , issue the following command

sudo service mysql status

If it is not, try the following

sudo service mysql start

The status should look like this:

Reporting MySQL status
Reporting MySQL status

Run the following to open MySQL Montior

mysql -u root -p

It shows:

Login to MySQL Monitor
Login to MySQL Monitor

Congratulations!

By now, you have successfully installed LAMP web server stack on Raspberry Pi 3 running Ubuntu Linux. In the future, I will cover more on how to configure your LAMP stack.

 

 

  • charly

    Thanks for the great article(s)! Soon to receive a rpi3 hopefully, and eager to try this in there. In your opinion is the performance good enough for a home/development lamp server?

    • You are welcome. Yes, in my opinion, rpi3 is good enough for home/development lamp server because there are only a few users and a few sensors / actuators if your are into home automation.

      • charly

        Thanks Thomas. Indeed this would be nothing about home automation, just plain old php web application development, I want to avoid having my Windows computer with extra load and is nice to have it in a little box for space reasons. For now I have an old rpi (I think it’s the version 1) I’ll try it out until my rpi3 comes home.

  • Lew MUrray

    This no longer works because the latest Raspian release only has PHP7 in the repos.