Chapter 9:
ROUTER WITH DYNAMIC WEBSERVER
Building on the concepts discussed in previous sections about creating an access point and a basic captive portal, this alternative approach offers a more dynamic and interactive solution. It's ideal for mobile access points, delivering engaging content to customers, including interactive elements and feedback collection through a database, even in offline environments.
Setting up the Captive Portal: Begin by running the following commands to install an alternate captive portal system:
sudo -i curl -H 'Cache-Control: no-cache' -sSL https://raw.githubusercontent.com/tretos53/Captive-Portal/master/captiveportal.sh | sudo bash $0
To customize the SSID during installation:
curl -H 'Cache-Control: no-cache' -sSL https://raw.githubusercontent.com/tretos53/Captive-Portal/master/captiveportal.sh | sudo bash $0 SSID_OF_YOUR_CHOICE
This setup ensures that the wireless network does not provide direct access to the Raspberry Pi's computing resources. Access can be granted through a separate network interface. Source for installation script: Captive-Portal on GitHub.
Web Server and Dynamic Content: The NGINX web server is utilized to serve dynamic HTML content. This allows for linking to web pages and databases for a richer user experience.
Install PHP for server-side programming:
sudo apt-get install php -y
cd /var/www/html/
sudo rm index.html
sudo nano index.php
Enter the PHP test script:
<?php echo "hello world"; ?>
Restart NGINX to apply changes:
sudo service nginx restart
Database Setup: For database management, install MariaDB (a MySQL variant) and phpMyAdmin for web-based database administration:
sudo apt install mariadb-server php-mysql
sudo service nginx restart
sudo mysql_secure_installation
Follow the prompts, entering 'Y' for all options.
Set up a database user:
sudo mysql --user=root --password
create user admin@localhost identified by 'your_password';
grant all privileges on *.* to admin@localhost;
FLUSH PRIVILEGES;
exit;
Install phpMyAdmin:
sudo apt-get install phpmyadmin -y
Select 'Yes' for dbconfig-common, then enable mysqli:
sudo phpenmod mysqli
sudo service nginx restart
Access phpMyAdmin through: http://ip/phpmyadmin. If needed, link the phpMyAdmin folder to the web directory:
sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin
Source for LAMP server setup: Random Nerd Tutorials.
This comprehensive setup allows for a robust, interactive captive portal experience, suitable for dynamic content delivery and customer engagement in various scenarios, including mobile or offline environments.