Setting up a LAMP stack on a Raspberry Pi with Pantavisor

 

Updated November 2021

Pantavisor and Pantacor Hub together allows developers to create, and deploy many different types of containerized apps to your IoT devices. Pantavisor is the framework for containerized embedded Linux development. It connects embedded devices, and containerizes and modularizes both the embedded firmware and user-land. In this tutorial, we’ll show you how to install Pantavisor onto a Raspberry Pi, claim your device and then make it accessible from the Pantacor Hub dashboard. Lastly, we describe how to set up a LAMP (Linux, Apache, MySQL, PHP/Perl/Python) stack on your Raspberry Pi and prepare it for app development with Pantavisor. 

Before you begin this tutorial, sign up to Pantacor Hub. It’s open source and free to use. 

Follow the below steps to set up LAMP stack in your Pantahub device(RPI3)

Step 1: Flash your Raspberry Pi 3 with an initial stable image.

First download the Raspberry Pi 3 image. This image comes with Pantavisor pre-installed and is the easiest way to start working with the framework. 

Click to download.

unxz the device image:

Run $ unxz rpi3_initial_stable.img.xz

Flash the image into sd card using Raspberry Pi Imager

Step 2: Boot your RPI3

Insert your sd card and supply the power

Step 3: Detect & Claim your device

Connect a LAN cable between your RPI3 & computer/Router.

Open your terminal & run:

$pvr scan

Claim your device:

$ pvr claim -c grossly-pleasant-polliwog https://api.pantahub.com:443/devices/5f0316884f8811000a191ab3

Log into Pantacor Hub and check for the newly claimed device in the dashboard.

Step 4: Clone the device to your computer

$ pvr clone https://pvr.pantahub.com/sirinibin/vastly_measured_caribou/0 vastly_measured_caribou

Step 5: Add a new app named “apache-php” & Deploy to the device

Move to device root dir:

 `$ cd vastly_measured_caribou`

Add new app “apache-php” into the device:

$ pvr app add apache-php --from=arm32v7/php:7.2-apache

Deploy the changes to the device:

$ pvr add .
$ pvr commit
$ pvr post

Check the device status changes in Pantahub.com dashboard & wait for the status to become “DONE

Status 1:


Status 2:


Status 3:

Status 4:


Verify the “apache-php” installation: 

Access the device IP: http://10.42.0.231 in your web browser. lamp-stack-IoT-pantavisor

Now you can see that the Apache server is started serving on port 80 in your RPI3 device. But it is showing as “Forbidden” because there is nothing to serve.

Step 6: Serve a php script using the newly installed apache2.4 server

Add your ssh key to your device user meta data using pantahub.com dashboard:

Note: the key name you should use is pvr-sdk.authorized_keys

SSH to the newly created app container “apache-php”:

 $ ssh -p 8222 php-apache@10.42.0.231

Install vim editor:

$ apt-get update
$ apt-get install vim

Place a PHP script index.php inside the apache Document Root folder:

$ cd /var/www/html
$ vim index.php
<?php
phpinfo()
?>

Access your device IP: http://10.42.0.231/ in your web browser:

Step 7: Add “mysql” app to the device & deploy the change

Add “mysql” app:

$ pvr app add mysql --from=yobasystems/alpine-mariadb:arm32v7 --config-json=<(echo -n -e '{
"Env": [
  "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
  "MYSQL_DATABASE=testdb",
  "MYSQL_USER=testuser",
  "MYSQL_PASSWORD=123",
  "MYSQL_ROOT_PASSWORD=123",
  "MYSQL_CHARSET=utf8",
  "MYSQL_COLLATION=utf8_general_ci"
]
}')

Deploy the changes:

 $ pvr add .
 $ pvr commit
 $ pvr post
Step 8: Add “adminer” app to the device for managing the mysql database

Adminer is a dashboard app which can be used to visually manage the mysql database

By default Adminer will be server through port 8080

Add “adminer” app:

pvr app add adminer —from=arm32v7/adminer

Deploy the changes:

 $ pvr add .
 $ pvr commit
 $ pvr post

Access the Adminer dashboard by using http://10.42.0.231:8080/

Log into the Adminer dashboard by entering the below mysql credentials:

 Server:10.42.0.231
 Username:root
 Password:123

Now you can easily Create/update/delete mysql databases/tables through Adminer. Deploy your custom LAMP app source code into the dir: /var/www/html of Docker image:arm32v7/php:7.2-apache and update the Docker image tag in src.json then run: 

pvr app update apache-php --from=arm32v7/php:<NewTag>

 

Final Thoughts

In this tutorial, we described how to deploy a containerized version of an entire LAMP stack onto your Pantavisor-enabled device and made it ready for the IoT app of your dreams. 

Note that Pantavisor doesn’t run Docker containers natively, but it does use Docker images as a great source of root file systems for containers that are run by the Pantavisor with LXC.

Take a deeper dive into managing Pantavisor Linux with Pantabox.


We’re really excited for you to try Pantabox and Pantavisor Linux and we’d love to hear your thoughts. Try one of the guides or join us in the Pantavisor community forum.

Facebook
Twitter
LinkedIn