We need to setup a webserver for our Raspberry Pi. It will host both scripts and web interface. Keeping things separated will help in the future.
Our chosen service is Lighttpd, but we start as usual with:
sudo apt-get update
sudo apt-get upgrade
Next we can start adding things…
sudo apt-get install lighttpd
At the end, we need to enable it to start at boot. You will be asked a few times Pi password.
systemctl start lighttpd
systemctl enable lighttpd
A check is recommended before going forth. Check Lighttpd status and get your Pi local IP adress with:
systemctl status lighttpd
Within your LAN, if you type that adress in a browser you should visualize a placeholder page.
Once verified that everything works it’s time to install PHP.
sudo apt install php7.0
sudo reboot now
Almost there… just some permissions to set up…
sudo chown www-data:www-data /var/www
sudo chmod 775 /var/www
sudo usermod -a -G www-data pi
There it is! Under /var/www there is a ‘html’ folder. Our web interface will be built inside that folder. To simplify FTP transfers and have everything in one place, we will add a folder within /var/www called scripts.
sudo mkdir /var/www/scripts
sudo chmod 777 /var/www/scripts
sudo chown www-data:www-data /var/www/scripts
In this last folder we will add scripts that are used by the Pi to communicate with other elements of Botler1.
To test PHP, delete the index file in the ‘html’ folder:
sudo rm index.lighttpd.html
sudo nano index.php
In this editor just write “<?php phpinfo(); ?>”. If everything works as it should, when reaching the webpage (previously a placeholder) you should get this: