Running Standalone App on Raspberry Pi with Local Wi-Fi AP (Debian/Raspbian): Setting Up a Web Server
This article provides a step-by-step guide to running a standalone application on a Raspberry Pi with a Debian or Raspbian operating system and setting up a local Wi-Fi access point. We will also cover how to display the app results through a web server.
Prerequisites
Before we begin, ensure that you have the following:
- A Raspberry Pi board with Debian or Raspbian installed
- A monitor, keyboard, and mouse (for initial setup)
- A Wi-Fi router and network credentials
Step 1: Setting Up a Local Wi-Fi Access Point
To create a local Wi-Fi access point, follow these steps:
Step 1.1: Install Hostapd and iw
First, update the package list and install the required packages:
sudo apt update
sudo apt install hostapd iwStep 1.2: Configure Hostapd
Create a new configuration file for Hostapd:
sudo nano /etc/hostapd/hostapd.confAdd the following content:
interface wlan0
ssid My_WiFi_AP
wpa_passphrase My_Password
wpa_key_mgmt WPA-PSK
wpa_pairwise CCMP TKIP
wpa_group_cipher TKIPStep 1.3: Enable and Start Hostapd
Enable and start the Hostapd service:
sudo systemctl enable hostapd
sudo systemctl start hostapdStep 2: Installing and Configuring a Web Server
We will use the Lighttpd web server for this tutorial:
Step 2.1: Install Lighttpd
Install Lighttpd:
sudo apt install lighttpdStep 2.2: Configure Lighttpd
Create a new configuration file for Lighttpd:
sudo nano /etc/lighttpd/conf.d/00-info.confAdd the following content:
server.modules += ("mod_fastcgi")
fastcgi.server = ( "/" => ( ( "host" => "127.0.0.1"
, "port" => 8000
, "check-local" => "disable"
)
)
)Step 2.3: Enable and Start Lighttpd
Enable and start the Lighttpd service:
sudo systemctl enable lighttpd
sudo systemctl start lighttpdStep 3: Running Your Standalone App
To run your standalone app and display the results through the web server:
Step 3.1: Install and Configure FastCGI
Install FastCGI:
sudo apt install libfastcgi-dev libfastcgi++2 libfcgi-devStep 3.2: Compile and Install Your App
Compile and install your app using FastCGI:
# Replace 'your_app' with the name of your app
g++ your_app.cpp -o your_app -g -O2 -I/usr/include/fcgi
sudo make installStep 3.3: Run Your App
Start your app:
sudo nohup /usr/sbin/fcgi-exec your_app &Accessing Your App
Access your app through the web server by connecting to the Raspberry Pi's local Wi-Fi access point using a web browser:
Summary:
In this article, we covered how to run a standalone app on a Raspberry Pi with Debian or Raspbian and set up a local Wi-Fi access point. We also showed how to display the app results through a web server using Lighttpd and FastCGI.