Skip to content

Instantly share code, notes, and snippets.

@elijahc
Last active May 30, 2023 05:34
Show Gist options
  • Save elijahc/acb19b7ec770fb61f8f11a1a8f41ba4d to your computer and use it in GitHub Desktop.
Save elijahc/acb19b7ec770fb61f8f11a1a8f41ba4d to your computer and use it in GitHub Desktop.
Setup Raspberry Pi 2/3 to host control website over wifi

Install hostapd and lighttpd (high performance hosting)

$ sudo apt-get install hostapd lighttpd

Edit interfaces to load your wlan interface on boot

# Add the following (and consider making a backup of interfaces):
allow-hotplug wlan1
iface wlan1 inet static
address 172.24.1.1
netmask 255.255.255.0
[...]

$ cat /etc/network/interfaces
[...]
auto wlan1
iface wlan1 inet static
address 10.0.0.1
netmask 255.255.255.0

Declare DAEMON_CONF in /etc/default/hostapd

$ cat /etc/default/hostapd
[...]
# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration
# file and hostapd will be started during system boot. An example configuration
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz
#
DAEMON_CONF="/etc/hostapd/hostapd.conf"
[...]

Edit /etc/hostapd/hostapd.conf to your preference. Mine is included as an example below

$ vim /etc/hostapd/hostapd.conf

Setup dnsmasq so that the RPi can assign IP addresses to connected clients

$ sudo apt-get install dnsmasq

# Barebones dnsmasq config
$ vim /etc/dnsmasq.conf

Start hostapd and dnsmasq to confirm you can connect to the network and get assigned an IP address

$ sudo service start hostapd
$ sudo service restart dnsmasq
#/etc/dnsmasq.conf
# Listen on interface wlan0
interface=wlan1
listen-address=172.24.1.1
bind-interfaces
server=8.8.8.8
domain-needed
bogus-priv
# It also sets the subnet mask to 255.255.255.0 and specifies a lease time of 12 hours.
dhcp-range=172.24.1.50,172.24.1.150,12h
# /etc/hostapd/hostapd.conf
# Basic configuration
interface=wlan1
channel=8
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
# WPA and WPA2 configuration
ssid=kalimos
# Setup a hidden network
ignore_broadcast_ssid=1
# Hardware configuration
driver=rtl871xdrv
ieee80211n=1
hw_mode=g
device_name=RTL8192CU
manufacturer=Realtek
# /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
allow-hotplug wlan1
iface wlan1 inet static
address 172.24.1.1
netmask 255.255.255.0
network 172.24.1.0
broadcast 172.24.1.255
# /etc/lighttpd/lighttpd.conf
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
)
server.document-root = "/var/www/html"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.port = 80
index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )
# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment