First thing is first. Update and install required applications.
sudo apt-get update;sudo aptitude install apache2 php5 php5-gd libapache2-mod-php5 php5-mysql hostapd dnsmasq
Network Configuration
sudo nano /etc/iptables.rules
sudo iptables -i wlan0 -t nat -A PREROUTING -p tcp --dport 53 -j DNAT --to-destination 10.0.0.1:53
sudo iptables -i wlan0 -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to-destination 10.0.0.1:53
sudo iptables -i wlan0 -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 10.0.0.1:80
sudo sh -c "iptables-save > /etc/iptables.rules"
sudo nano /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ssid=uff-da
channel=1
ieee80211n=1
sudo nano /etc/network/interfaces
auto lo
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
address 10.0.0.1
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
up iptables-restore < /etc/iptables.rules
sudo nano /etc/init.d/hostapd
DAEMON_CONF=/etc/hostapd/hostapd.conf
sudo nano /etc/dnsmasq.conf
log-facility=/var/log/dnsmasq.log
address=/#/10.0.0.1
interface=wlan0
dhcp-range=10.0.0.10,10.0.0.250,12h
no-resolv
log-queries
sudo update-rc.d hostapd defaults
sudo update-rc.d dnsmasq defaults
Apache Stuff
sudo nano /etc/apache2/sites-available/000-default.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
sudo service apache2 restart
Misc Web Server Stuff
.htaccess files control Apache requests in essence, and let you rewrite your requests based on patterns, great for when your OS is trying to detect if you are on a captive portal.
nano ./.htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule . /index.html [R=302,L]
If you want to redirect to a custom domain (since any domain goes to your server anyway) it doesn’t even have to be a real top level domain extention.
if($_SERVER['REQUEST_URI']!="/") {
header("Location: http://your.domain");
} else if($_SERVER['HTTP_HOST']!="your.domain") {
header("Location: http://your.domain");
}
Important Notes
If you need to run updates or fetch something from the web, it will always point to your local Pi, so you must run the command below to make it run like normal. There are probably better ways to configure the service with iptables or mac detection, but I have not looked into that.
service dnsmasq stop