-
Notifications
You must be signed in to change notification settings - Fork 1
Install PhpPiratebox on Raspberry Pi
#PhpPiratebox on Raspberry Pi installation guide
##0. Requisites This tutorial has been tested with this hardware:
- Raspberry Pi model B.
- A SD card with Arch Linux (Image of 2013-07-22).
- TP-Link TL-WN722N (Atheros chipset).
Instructions may be differ on other Raspberry Pi models or Linux distributions.
##1. Install Lighttp webserver and set up PHP.
- Log in as root.
-
Connect Raspberry Pi to the internet via ethernet port, we're going to install programs.
-
Upgrade system:
pacman -Syu
-
Install the packages Lighttpd, PHP, and fastCGI:
pacman -S lighttpd php-fpm fcgi
-
Edit /etc/lighttpd/lighttpd.conf:
nano /etc/lighttpd/lighttpd.conf
-
Find the line that starts with
mimetype.assign
and add".css" => "text/css",
after parentesis.mimetype.assign = ( ".css" => "text/css", ".html" => "text/html", ".txt" => "text/plain", ".jpg" => "image/jpeg", ".png" => "image/png", "" => "application/octet-stream" )
-
Write this at end of file:
server.modules += ( "mod_fastcgi" ) index-file.names += ( "index.php" ) server.error-handler-404 = "/404-redirect.php" fastcgi.server = ( ".php" => ( "localhost" => ( "socket" => "/run/php-fpm/php-fpm.sock", "broken-scriptfilename" => "enable" )) )
-
-
Configure services to start when booting up system:
systemctl enable lighttpd php-fpm
-
Start the services:
systemctl start lighttpd php-fpm
##2. Download and configure PhpPiratebox.
- Install unzip:
pacman -S unzip
-
Go to /srv/http:
cd /srv/http
-
Download PhpPiratebox files:
wget -O phppiratebox.zip https://github.com/Branyac/PhpPirateBox/archive/master.zip
-
Unzip files:
unzip phppiratebox.zip
-
Move files to web server root:
mv ./PhpPirateBox-master/* ./
-
Optional: remove non-necessary files:
rm -rf phppiratebox.zip PhpPirateBox-master/
-
Edit config.php.example, set up the local domain, upload path, and file for wall messages:
nano config.php.example
. In this case the domain isphppiratebox.local
, the files are saved at/phppirateboxdata/uploads/
, and messages at/phppirateboxdata/messages.json
.$phppiratebox_domain = "phppiratebox.local"; $upload_folder_path = "/phppirateboxdata/uploads/"; $wall_messages_file = "/phppirateboxdata/messages.json";
-
Rename
config.php.example
toconfig.php
:mv config.php.example config.php
-
Optional: Create data folders and setup correct permissions:
mkdir /phppirateboxdata && mkdir /phppirateboxdata/uploads && chmod -R 777 /phppirateboxdata
-
Configure Php to allow writing in php piratebox folder:
nano /etc/php/php.ini
- Find the line that starts with
open_basedir
and add the folder, for example in this case looks asopen_basedir = /phppirateboxdata/:/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/
-
Optional: Arch Linux Php default settings limit file uploads to 2 megabytes. You may want to increase the limit, this is done changing
upload_max_filesize
andpost_max_size
values in/etc/php/php.ini
. In this case the limit is increased up to 50 megabytes.upload_max_filesize = 50M
post_max_size = 50M
-
Reload Php to apply changes:
systemctl reload php-fpm
##3. Set up wireless access point
- Check the wireless card is connected.
-
Install hostapd:
pacman -S hostapd
-
Edit
/etc/hostapd/hostapd.conf
:-
Delete the example content and open the file:
mv /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.old && nano /etc/hostapd/hostapd.conf
-
Write this:
interface=wlan0 driver=nl80211 ssid=PhpPiratebox auth_algs=1 channel=1 hw_mode=g wpa=0 ignore_broadcast_ssid=0
-
-
Configure hostapd to start when booting up system:
systemctl enable hostapd
-
Restart hostapd:
systemctl restart hostapd
##4. Static address, dhcp server, and HTTP redirection.
- Create a network profile for wireless access point:
-
Create file at
/etc/netctl/wlan0.profile
:nano /etc/netctl/wlan0.profile
-
Write this:
Description='PhpPiratebox network interface' Interface=wlan0 Connection=ethernet SkipNoCarrier=yes IP=static Address=('192.168.0.1/24')
-
-
Enable network profile:
netctl enable wlan0.profile
-
Reboot Raspberry:
reboot
-
Install dnsmasq and iptables:
pacman -S dnsmasq iptables
-
Edit
/etc/dnsmasq.conf
:-
Delete the example content and open the file:
mv /etc/dnsmasq.conf /etc/dnsmasq.conf.old && nano /etc/dnsmasq.conf
-
Write this:
interface=wlan0 listen-address=192.168.0.1 dhcp-range=192.168.0.10,192.168.0.254,5m no-resolv address=/#/192.168.0.1
-
-
Configure to start dnsmasq when booting up system:
systemctl enable dnsmasq
-
Open /etc/sysctl.conf and change
net.ipv4.ip_forward = 0
tonet.ipv4.ip_forward = 1
:nano /etc/sysctl.conf
-
Configure redirection on port 80:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.0.1
-
Save the config to
/etc/iptables/phppiratebox.rules
:iptables-save > /etc/iptables/phppiratebox.rules
-
Create a service that will restore iptables when booting up system:
-
Create file
/etc/conf.d/iptables
:mkdir /etc/conf.d && nano /etc/conf.d/iptables
-
Write this:
IPTABLES_CONF=/etc/iptables/phppiratebox.rules
-
-
Configure to restore settings when booting up system:
systemctl enable iptables.service
-
Reboot raspberry:
reboot
.
##5. Check installation PhpPiratebox is ready. Connect to "PhpPiratebox" wireless access point, no password needed. Some operating systems may open automatically the browser after connecting to the access point if not open your web browser manually and go to any web address, you always will be redirected to http://phppiratebox.local.
###Enjoy your PhpPiratebox!