Controlling the LEDs remotely with SSH is pretty cool but the interface (console) isn't very user friendly and typing the commands every time is long and annoying. That's why we need a graphical interface for our project.
Programming an app for each OS (IOS, Android, Windows phone, Mac, Linux, Windows,...) would be too long and would require to know a lot of different languages for nearly nothing. It would also require to do an application running on the Raspberry Pi. Making it this way would be overkill and time wasting.
We indeed need to install a web server on the Raspberry Pi. In our case, we don't need a MySQL database, only a HTTP server and its PHP extension.
After updating your Raspberry Pi with the "sudo apt-get update
" command, type "sudo apt-get install apache2 php5 libapache2-mod-php5
" to install Apache HTTP server and PHP5 extension. You can now test if your server is working by typing the IP of your Raspberry Pi in your browser. You should now see a "It works!
" page with two other lines. If you don't, then check your board's IP, try re-installing Apache or rebooting your Raspberry Pi. This page is showing that your Apache server is working properly but not its PHP extension. To check it, navigate to your "/var/www/
" directory by using the "cd /var/www/
" command. If you use the "ls
" command, you should have only one file named "index.html
". This file corresponds to the "It works!
" page. You can now delete it ("sudo rm index.html"
) and create another one called "index.php
" (use "sudo nano index.php
"). Then type the following text:
After saving it using ^o (Ctrl + o), exit nano editor with ^x (Ctrl + x). Now if you refresh your browser, you should see a long page with lots of information about your server and PHP. If you don't, check the index.php
file, try re-installing PHP or try to understand the error displayed instead of the page (Google it if necessary).
If both pages were correctly displayed, then you now have a fully functional Apache/PHP server but using nano every time is annoying and not very comfortable. We indeed need to transfer files from your computer to your Raspberry Pi. You may want to install a FTP server but it isn't necessary, you can already transfer files using the SFTP protocol. All you need is an SFTP client on your computer. I'm personally using WinSCP for Windows but there are Cyberduck for mac and Filezilla for Linux. If you try transferring files before reading what's next, you'll probably have issues such as "access refused" or "cannot write here". It's due to the fact that the user pi isn't owning the www directory. Indeed, if you try the "ls -l /var/www
" command, you'll see that only root (the super user) is owning the www directory. You can (like I did) use the "sudo chown -R pi /var/www
" command to change it or create a group named www-data in which you place the pi user then use the "sudo chown -R www-data /var/www
" command. The -R
flag is standing for recursive, it means that the user/group isn't owning only the directory itself but also everything inside (index.php as example).
You now have your server ready to work and to receive web pages. Have fun with it if know HTML, CSS and PHP.