Run a web-scale app with the Raspberry Pi
Tags: raspberrypi, linux, microservices, beginners
Published: 2019-11-25 16:49:40

---
title: Run a web-scale app with the Raspberry Pi
published: true
description: How to manage your Heroku app from the Raspberry Pi
tags: raspberrypi, linux, microservices, beginner
cover_image: https://upload.wikimedia.org/wikipedia/commons/9/97/Raspberry-Pi-Zero-BR.jpg
---

### Editing and Redeploying

My [first article](https://dev.to/heroku/how-to-deploy-your-app-to-heroku-from-raspberry-pi-162k) covered how to deploy an app to Heroku using the $35 Raspberry Pi. But deploying is not the end: It is the beginning. 
![image caption](https://upload.wikimedia.org/wikipedia/commons/1/10/Raspberry-Pi-3.gif)

After deploying the first time, you might find bugs or typos, decide to add a feature or completely revise. In which case, you will need a process to commit those changes to Heroku.

#### My edits

The Python test app's python code is boilerplate stuff. Nothing that's really convenient to edit for the purpose of this tutorial. So let's just alter a couple things in the HTML templates for the app, so we can immediately see our changes. 

I've navigated to the directory python-getting-started/hello/templates, and double-clicked the files base.html and index.html. These files will open in the Geany editor by default. 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/lzvcu8f9cfp4y6f46wk0.png)

On line 4 of base.html, I changed the contents of the `<title></title>` tags to "Edited Python app for Heroku".

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/eb8lmlarr4321e893pu2.png)

And on line 11 of index.html, I changed the contents of the `<h1></h1>` tags to "It worked!"---Confidence breeds competence!

#### The flow

Now I will navigate to the root directory of my app in the terminal. Each time I make changes that I want to see reflected in the version hosted by Heroku, I will run the following commands in this order:

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/pqhpbnssk5gcya0pm6rj.png)

1. `git add .` This *adds* your changes to the local repository's index. (Use `git status` to see what changes are on the index. Whatever is indexed will be recorded with the next command.)

2. `git commit` This *commits* your changes by recording them to the local repository. This will open the editor you specified when you configured git. I am using nano to draft my commit message below.!![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/wnf2gicd6cd6to20wpx9.png)

3. `git push heroku master` This hands the updated repository over to Heroku for deployment. (Look familiar? It's the same command we used to deploy in the previous section.) As soon as this finishes executing, you can run `heroku open` to see your changes.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/lv7fu845erm1yhly1jqr.png)

Ta-dah! A Heroku app development flow is born.  

## Addendum: Local Hosting

To host your app locally, you need to have Postgres and some headers installed first. Run `sudo apt install libpg-dev postgresql` to do so. From there, the process takes just a few minutes. Let's get set up first:

### Step 0: Set Up

First, as always, navigate to your app's root directory. From there, we are going to create a Python virtual environment around the getting-started directory. Run `python3 -m venv getting-started` to do so. For your own app, you will create a virtual environment on the directory containing your WSGI. 

We should also make sure that /home/**user**/.local/bin (where **user** is your user name) is in our PATH environment variable before proceeding. You can check your PATH by executing `echo $PATH`. You can add the directory to your path for this session with `export PATH=$PATH:/home/user/.local/bin`, or for all your sessions (this will restart your Pi) with `echo "PATH=$PATH:/home/user/.local/bin" >> /home/user/.profile && sudo systemctl reboot`. 

### Step 1: Installing Requirements

Then we need to install our requirements locally. You need to run this command the first time, and whenever your requirements.txt changes: `pip3 install -r requirements.txt`. This will install everything listed in your requirements.txt file.

### Step 2: Create Databases

This next command only need be run once: `sudo -u postgres createdb python_getting_started`. For your own app, you will substitute the name of your app's migration database. If your app uses any more databases, you may want to create those as well.

### Step 3: Migration and Static Collection

Then we will migrate our git repository into the database we created in the previous step: `python3 manage.py migrate`; And run `python3 manage.py collectstatic` to collect the static elements of your app into a single directory for the web server. The manage.py file just lets us run django's core.management functionalities directly from the command-line. You should run these commands every time you make changes you want to see reflected locally.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/nn80ksejrovfna471cf3.png)

### Step 4: Host!

Finally, we run `heroku local` to start hosting our app locally on port 5000. 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/8gqbpupj8zl6qkhxaf0x.png)

Open a browser to localhost:5000 and you will see your app!

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/muem98pocwokckgyg23n.png)
We can see the changes made in the previous section, but this time the app is hosted on the RPi.

## Conclusion

Raspberry Pi is a fine platform for web development, especially in light of the coming internet of things. With the image of rooms thick with server racks in mind, hosting and developing web applications on the Raspberry Pi reminds us that the internet really does belong to everyone. If even this little "deck of cards" can host and deploy awesome web services, then nothing is stopping anyone from making their own. 

Good luck and Godspeed!


> This article was co-written and would not have been possible without the Linux wizardry of J. S. Rana. If you can believe it, she's looking for work right now! Please, get in touch if you'd like a Python, Linux, or Git genius on your team.
> Her email [jsrana@raydialow.xyz](mailto:jsrana@raydialow.xyz)
> Her [github](github.com/raydialow) and [blog](raydialow.xyz)