Today I set out to accomplish two tasks 1) to cut down the size of the Raspbian install and 2) setup the LAMP (Linux Apache MySQL PHP) stack on it. After setting this up you will quickly see that using RPi to host a dynamic webpage on the internet probably won’t be your best option but there are still functional uses such as a small internal web server or maybe a web interface for your next hardware hacking project using the GPIO pins. Unfortunately in my testing Apache is just too slow on the RPi so we will be using Nginx and SQLite instead of Apache and MySQL. I also did some testing with lighttpd and, while I don’t have hard numbers to back me up, Nginx felt the fastest of all three web servers.
In my quest to put Raspbian on a diet I stumbled across this. It appears CNXSoft has already done what I set out to do so why try to reinvent the wheel. Go here and download the image and load it onto an SD card.
Now that we are booted into our new slim Raspbian image we are going to tweak the performance a bit. Here you can find a well written, easy to follow guide on how to squeeze more performance out of your system. From here on out I will be giving you the step-by-step that will result in you having a functional LAMP stack installed on your RPi.
Once installed and you have run raspi-config you will want to select
expand_rootfs and after that completes reboot
Install rpi-update, required bins, run the update with a 240/16 memory split, and reboot
1 2 3 4
Remove the extra tty’s
Enable a 512MB swapfile
Change the size of the swapfile from 100MB to 512MB
Initialize the swapfile
Enable the swapfile
Optionally you can disable IPv6 but for my deployment I left it enabled.
Install and start Nginx
Install PHP and SQLite, then modify config.
Add index.php to line with index, to look like:
Add or uncomment lines:
1 2 3 4 5
Make sure to uncomment the last } as I forgot the first few times. Now we should be able to reload Nginx and PHP should be live.
From here we can generate a PHPinfo page to verify and you should be all set!