User avatar
jack.chaney
Posts: 15
Joined: Sun May 31, 2015 5:17 pm

RPiLPP or, another way to spell LAMP

Fri Oct 09, 2015 1:29 pm

In the realm of IoT and web services there is a very popular model called LAMP. LAMP is an acronym that sands for Linux, Apache, MySQL and PHP. The model is used for many web service systems, most notably those using WordPress. WordPress is a good example of what is obtainable using PHP, and PHP is how, in WordPress, you can create custom components. The problem with the LAMP model is that which happens to all technological solutions, especially the really good ones, others follow. The other issue with really good technological solutions is they are not always one “size fits all”.
Being a really old guy who has been playing with Linux since Linus first posted his announcement (I still have a Yaggersyl CD of v0.99 in my stacks), I have used nearly all the packages at one time or another, and have gained some preferences over the centuries. Also, since I have been an embedded programming engineer for most of my working life, I carry a strong preference for smaller, lighter, and cleaner, when it comes to coding. I have strong feelings about not adding bloat, without a fair amount of consideration. As an embedded engineer, and part time teacher, I was drawn to the world of Raspberry Pi. And, after a bunch of poking, and testing, and breaking, and letting smoke out, I thought I would like to see if I could make a viable LAMP from a Raspberry Pi, to hang on my home network.
First things first, was the database manager. MySQL for a very long time was the web de facto selection for a dbms. But recent changes of licensing and dubious ownership of MySQL copies (something about open source assets), led me to investigate other dbms solutions. There has been a near feud between the two camps over which dbms is better, MySQL, and PostgreSQL. In actuality, from an operational level of size, speed, functionality, and admin tools, they are indistinguishable (that one is going to get me a lot of mail). The advantage of PostgreSQL is one of licensing, fully supported MySQL is no longer free. Since the demise of SUN (chief funder of the MySQL project), and some other legal operations, MySQL now requires a license for commercial distribution. So I decided to go with the elephant in the room (small pun).
So now my system would be LAPP not LAMP, also a common enough solution, that there are lots of web pages devoted to this variant. So to the next item, the web server. Apache is good, really, really, really good, but it tends to be a bit on the heavy side for something like a Raspberry Pi, there are a bunch of other packages floating around, that provide a good level of services and maintain a very small footprint, but it also needed to be compatible with CGI and PHP so it could also provide web services, instead of just static pages. Now, taking a step back for a moment, many readers will note that some of my statements are just the ramblings of an old man, and they are entitled to have their opinion as to its level of factual content. To which I state; I guarantee all my information to be 100% right or wrong. Also this is a solution, not the solution. So for a small lightweight web server I went with Lighttpd.
Still going with PHP for the last piece, which gets to the new acronym, which could have been LLPP, but since Raspberry Pi uses Linux (Raspbian) I decided to call it RPiLPP. So now we are up to the how to part of the story where we actually build our device. Being old and feeble, and not the sharpest pencil in the box, I like to keep things really simple and easy to repeat (because I often don’t get it right the first time). So the installation of all the parts is intended to be as simple as possible.
First, the obligatory:
sudo apt-get update; sudo apt-get upgrade

Then we will start by getting the dbms by just doing the installation first, and configure it in a little while:
sudo apt-get –y install postgresql

Sorry if that was less work than you planned. Next, install the web server:
sudo apt-get –y install lighttpd

Again, sorry for making this so simple, but as I alluded to earlier, this is about as complicated as I can handle. Last install is just a little more complex (because there are more parts), PHP:
sudo apt-get –y install php5 php5-common php5-cgi php5-pgsql phppgadmin

Everything should be running now. So let’s take a second to go over what we did, and what things we just added. The postgresql was the database engine, or database management system. It doesn’t have any database built yet, only the components for building and managing a database (or databases). The lighttpd is a webserver that listens to the network line for its address at port 80 for requests, and provides the web information in response. The PHP stuff is; PHP5 is the main package, the language interpreter, ‘common’ are the PHP libraries and language extensions, ‘cgi’ is the linkage library to the web server, ‘pgsql’ is the linkage library to PostgreSQL, and last phppgadmin is a web based interface for doing database administration.

Now that we have everything installed, we just need to configure a few things before we’re done. First get lighttpd working with php and so the phppgadmin package works right:
sudo lighty-enable-mod fastcgi-php
sudo lighty-enable-mod cgi

then reload lighttpd
sudo service lighttpd force-reload

and so the pi user can develop web pages without going sudo, we adjust permissions to add pi to the working group:
sudo chown www-data:www-data /var/www
sudo chmod 775 /var/www
sudo usermod –a –G www-data pi

Last we need to gain access to the database system. I tried to use the PhpPgAdmin package for this, but had problems getting it to work out of the box, and the front door method is easier for me, so:
Log on as root user
sudo su

then log in as postgres (the PostgreSQL user)
su – postgres

and start the shell
psql –U postgres

in the shell create the user (you)
CREATE USER pi WITH PASSWORD ‘xxxxxxxx’;
\q

The string of Xs is a password you select (and remember.

Last item to add the admin-ability to your site, the easy way is to make a symbolic link:
sudo ln –s /usr/share/phppgadmin /var/www/html/phppgadmin

All set! Enjoy!

Return to “Networking and servers”