3

I'm trying to host a very simple web page (to get user input), on the Raspberry pi. I want the user to be able to access this simple web page directly from it's smart phone or browser.

I guess I'm supposed to make an Ad-Hoc network! any help on how can i achieve this?

1

6 Answers 6

5

I'd actually go with Lighttpd rather than Apache on the Pi as it's lighter, and then I'd use a RT5370 WiFI USB dongle to start an access point rather than use Ad-Hoc as Ad-Hoc can have issues with some devices.

  1. You'll need to install hostapd and lighttpd
  2. Configure a static IP address for wlan0
  3. Configure hostapd accordingly, I have some instructions on my blog here -> http://sirlagz.net/2012/08/09/how-to-use-the-raspberry-pi-as-a-wireless-access-pointrouter-part-1/
  4. Place files into the /var/www folder (IIRC, that's where lighttpd points to by default)
  5. Point any web browser to the static ip you have configured, and you should get pages !

Additionally, once it's all setup, I would make sure that security is up to scratch and harden the configuration if it's going to be publicly accessible.

1

This is a quick n dirty way but should be suitable for a secure adhoc.

Install apache2 (a easy webserver for small amounts of users with lots of support) from the terminal ( sudo apt-get install apache2).

Throw your web files into /var/www/

Get your wifi adapters ip via terminal (ifconfig)

Share the ip to all so they can connect.

Done. As the previous answer stated, if your going to host this publicly then I reccomend looking into securing apache.

1

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 + INSTALL Apache ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

sudo apt-get install apache2 apache2-utils

to test apache is working:

open your browser and visit http: //localhost you should see the index.html page (from /var/www) displaying "it works!" on your browser

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 + HOTSPOT CONFIGURATION ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

-- Install Softwares

1) install the software [you need internet for that] sudo apt-get install hostapd isc-dhcp-server

required packages (make sure are installed 'bridge-utils' 'iptables') they are installed by default with the raspberry pi wheezy.

2) download the hostapd driver. Lest's do it now since your wlan0 is activated. wget http://www.adafruit.com/downloads/adafruit_hostapd.zip

-- Set up DHCP server

1) edit /etc/dhcp/dhcpd.conf: {this allows wifi connections to automatically get IP addresses, DNS, etc.}

sudo nano /etc/dhcp/dhcpd.conf

make sure you have the following configuration:

--->

ddns-update-style none;

option domain-name "local"; option domain-name-servers 8.8.8.8, 8.8.4.4;

default-lease-time 600; max-lease-time 7200;

authoritative;

log-facility local7;

subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.100 192.168.1.200; option broadcast-address 192.168.1.255; option routers 192.168.1.1; }

<---

2) edit /etc/default/isc-dhcp-server

sudo nano /etc/default/isc-dhcp-server

scroll down to INTERFACES="" and update it to say INTERFACES="wlan0"

-- Configure Access Point

here we gonna choose the network name (ex: MEGA)

1) Create a new file in /etc/hostapd/ called hostapd.conf:

sudo nano /etc/hostapd/hostapd.conf

(past the following in that file):

--->

interface=wlan0 driver=rtl871xdrv ssid=MEGA hw_mode=g channel=6 macaddr_acl=0 ignore_broadcast_ssid=0 auth_algs=1

<---

2) edit /etc/default/hostapd {to tell the Pi where to find this configuration file}

sudo nano /etc/default/hostapd

add the path to the DAEMON_CONF="/etc/hostapd/hostapd.conf"

Don't forget to remove the # in front of it

-- Set up wlan0 for static IP

1) turn off wlan0: sudo ifdown wlan0

2) here we need to modify the /etc/network/interfaces files

** NOTE: this file will be generated automatically by the JAVA software so you can skip this step

!THE FILE WILL LOOKS LIKE THIS AT THE END !--->

auto lo iface lo inet loopback

iface eth0 inet dhcp

allow-hotplug wlan0

iface wlan0 inet static address 192.168.1.1 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255

<---!

3) Assign a static IP address to the wifi adapter: sudo ifconfig wlan0 192.168.1.1

-- Update hostapd

you must update the hostapd or you will get an invalid driver error

0) install the unzip package # sudo apt-get install unzip

1) unzip the downloaded hostapd driver unzip adafruit_hostapd.zip

2) backup the original: sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG

3) replace the new one: sudo mv hostapd /usr/sbin

4) set it up so its valid to run with sudo chmod 755 /usr/sbin/hostapd

-- Test it!

0) turn on wlan0: sudo ifconfig wlan0 up

1) make sure hostapd service is running sudo service hostapd start

you can chekc it's status if running or not: sudo service hostapd status

2) make sure isc-dhcp-server service is running (VIP) sudo service isc-dhcp-server start

you can chekc it's status if running or not: sudo service isc-dhcp-server status

3) start the wifi broadcasting sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf

4) for debugging run the following command {to watch the system log data, handy for checking and debugging whats going on} tail -f /var/log/syslog

5) try to connect to it from another computer. to access the hosted web page go to 192.168.1.1

-- ERRORS FIXING

in case you got an error in starting the hostapd service or the wifi broadcasting: saying that /usr/sbin/hostapd doesn't exist {and you know that it exists} that means the version of the hostapd is not compatible with the machine SOLUTION: install different hostapd driver that is compatible with the wifi dongle and the board

NOW YOU OPEN ANY BROWSER AND GO TO 192.168.1.1 YOU SHOULD SEE YOUR APPLICATION ;)

0

Step 1: Create and test web page. You will need apache (sudo apt-get install apache2), and packages to support any scripting languages/DB's you are using, PHP, MYsql, etc. Google will help you through this setup.

Step 2: setup network, either Ad-Hoc, or if you have it at your disposal, I would recommend a wireless router, with the Pi hardwired (or wireless, your choice) to it. Regardless of which interface you use, you will want to give it a static IP address.
If you choose Ad-Hoc, Google is your friend. Look up Debian Ad-Hoc configs, and figure out how you want/need to set it up. There are multiple ways of doing this and each one has its place. (I assume you are using Raspberian, built on Debian)

Step 3: Connect your client computer to the proper network, and browse to your page and make sure it does what you need it to.

Step 4: Depending on what environment you are deploying this, you will want to harden the device. Close off all unused ports, verify file permissions in your www directory, things like that. Google Hardening Apache for more info.

Good Luck!

0

How install Apache2 + PHP-FPM on Raspberry Pi and more tutorials http://raspberry-hosting.com/faq/how-install-apache2-php-fpm-raspberry-pi

1
  • You should include the important information from that link to avoid link-rot.
    – syb0rg
    Jan 17, 2014 at 23:52
0

I would definitely propose that lighttpd is a far better web server than Apache for the Pi. Also take a look at the monkey http daemon it has a build especially made for the Pi and appears to have the same general configuration as Apache does if you are more comfortable with it. I have posted about this here: http://c-mobberley.com/wordpress/index.php/2014/01/15/raspberry-pi-light-weight-http-daemon-monkey/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.