Set up LAMP stack in a Pantahub device(RPI3 B+)
Tags: linux, pantahub, rpi3, lamp
Published: 2020-07-08 13:07:46

### Step 1: Burn the RPI3 initial stable image into your sd card.
  
#### a) Download RPI3 image
  Click to download: https://pantavisor-ci.s3.amazonaws.com/pv-initial-devices/tags/012-rc2/162943661/rpi3_initial_stable.img.xz
 
#### b) unxz the device image
  Run `$ unxz rpi3_initial_stable.img.xz`
 
#### c) Burn image into sd card using  Raspberry  Pi Imager 1.2
 
  ![](https://i.imgur.com/3tnobOw.png =400x300)


### Step 2: Boot your RPI3 
      
#### a) Insert your sd card and supply the power
  ![](https://i.imgur.com/x4WF2Tz.jpg =400x300)

### Step 3: Detect & Claim your device

#### a) Connect a LAN cable between your RPI3 & computer/Router.
  ![](https://i.imgur.com/Y6q6J0o.png =400x300)
  
#### b) Open your terminal & run `$pvr scan`
  ![](https://i.imgur.com/ISfbb6S.png)

#### c) Claim your device
   `$ pvr claim -c grossly-pleasant-polliwog https://api.pantahub.com:443/devices/5f0316884f8811000a191ab3`
   
  ![](https://i.imgur.com/GjOewdI.png)
   
#### d) Log into Panthub.com and check whether the newly claimed device appeared in the dashboard or not.
  ![](https://i.imgur.com/rZ8z3nx.png)
  ![](https://i.imgur.com/VwMHYrH.png)

 
### Step 4: Clone the device to your computer

`$ pvr clone https://pvr.pantahub.com/sirinibin/vastly_measured_caribou/0 vastly_measured_caribou` 
  
  ![](https://i.imgur.com/InFhYYH.png)

### Step 5: Add a new app named "apache-php" & Deploy to the device
    
#### a) Move to device root dir
     `$ cd vastly_measured_caribou`

#### b) Add new app "apache-php" into the device
  `$ pvr app add apache-php --from=arm32v7/php:7.2-apache`
  
  ![](https://i.imgur.com/f06Bc6o.png)

#### c) Deploy the changes to the device
 ```
 $ pvr add .
 $ pvr commit
 $ pvr post
```
  ![](https://i.imgur.com/P0fMK3f.png)

#### d) Check the device status changes in Pantahub.com dashboard & wait for the status to become **"DONE**"
  Status 1:
  ![](https://i.imgur.com/eCtxpPt.png)
  Status 2:
  ![](https://i.imgur.com/rmpqCdE.png)
  Status 3:
  ![](https://i.imgur.com/cmz5jqU.png )
  Status 4:
  ![](https://i.imgur.com/K4jfved.png)

 
#### e) Verify the "apache-php" installation
   
  Access the device IP: http://10.42.0.231  in your web browser.
  ![](https://i.imgur.com/vwme17p.png)
  
  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
   
  
#### a) 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`
  
  ![](https://i.imgur.com/jsLHM1I.png)
     
  
#### b) SSH to the newly created app container "apache-php"
     $ ssh -p 8222 php-apache@10.42.0.231
  ![](https://i.imgur.com/kuDp74E.png)
  
#### c) Install vim editor


  ```
  $ apt-get update
  $ apt-get install vim
```


#### d) Place a PHP script index.php inside the apache Document Root folder
  ```
  $ cd /var/www/html
  $ vim index.php
  <?php
  phpinfo()
  ?>
 
```
#### e) Access your device IP: http://10.42.0.231/ in your web browser
  ![](https://i.imgur.com/ZuOysqK.png)

  
  
### Step 7: Add "mysql" app to the device & deploy the change
    
#### a) 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"
]
}')
```
    
![](https://i.imgur.com/EGIfR7E.png)

#### b) Deploy the changes
  ```
   $ pvr add .
   $ pvr commit
   $ pvr post
```
  ![](https://i.imgur.com/BvbwaID.png)


### 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
>   
#### a) Add "adminer" app
   
   pvr app add adminer --from=arm32v7/adminer
   
   ![](https://i.imgur.com/FxcLAC3.png)

#### b) Deploy the changes
  ```
   $ pvr add .
   $ pvr commit
   $ pvr post
```   
   ![](https://i.imgur.com/QZ0obSy.png)

#### c) Access the Adminer dashboard by using http://10.42.0.231:8080/
![](https://i.imgur.com/hDWhu3T.png)

#### d) Log into the Adminer dasdhboard by entering the below mysql credentials

```
 Server:10.42.0.231
 Username:root
 Password:123
```
![](https://i.imgur.com/YGzaZ2o.png)

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

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