Running A Local PLAMP Stack
By: Matt Holcombe
Tags: Raspberry Pi, Api Server, Pair App

Here’s a neat spin on the traditional LAMP setup, use a Raspberry Pi instead. It shouldn’t take more than an hour for apache, php, & mysql to happily be serving your LAN.

Quick Note: Being that this is my first personal post, there’s still a bit of figuring out a format / presentation for future articles and content. I’m going to keep the “bulleted list” style for now, but it may change in the future.

The Reasoning:

Needing a separate, reliable, and easily accessible web based JSON api for my React project being developed on my MacBook Pro running + debugging on its http://localhost:3000 . There’s only 4GB of RAM so the page file is going nuts, like millions of reads & writes.

New Skills Acquired:

The bind-address line in my.conf Set to 0.0.0.0 to allow more than just localhost to connect

Set to to allow more than just localhost to connect MySQL user access more precise that just ‘user’@’%’ . Which means allow connections from anywhere (‘%’).

Using subnet mask 255.255.255.0 worked, however ‘192.168.1.%’ had no effect

worked, however ‘192.168.1.%’ had no effect Refreshers on apache conf, mysql setup, network admin, git

History:

Skip the next couple paragraphs to Hardware Reqs / Setup to jump right in, or keep reading to know my motivations. Stay awhile, and listen to my story…

Started out running everything on local MBP, server stuff from homebrew installs. Surprisingly easy to get up and going, as opposed to manually editing the MacOS apache configs. Back in the day, all you had to do was create a Sites folder in your home directory, then turn on “web sharing” from the system prefs. In fact, the special folder icon is still there as of MacOS Catalina. Go ahead and try it, make a Sites folder mkdir -p ~/Sites to see for yourself. I was able to get homebrew’s apache to serve from there and then symlink out to the actual project folder EVENTUALLY.

So then I moved backend to the 2009 iMac running Snow Leopard Server, who’s strongest suite is the AFP & SMB file sharing service. Yes its that old. Couldn’t get the address to work right with what to serve. The Bonjour name like iMac-2009.local and its LAN address, even damn localhost wouldn’t play nice with PHP. Just when I thought all was fine & dandy, sometimes rebooting would screw up a previously working configuration.

Finally moved PHP back to my MBP, left the MySQL database as it was on the iMac OSX Server for a bit, then just decided to go all in with the Pi route.

Hardware Reqs / Setup:

Used a Raspberry Pi1-b (any model will do I think) with “Buster” Lite

Ability to assign a static IP address to the Pi (by logging into router/gateway)

Hardwired to the LAN w/ afore mentioned static IP from the router (can’t have wifi dropouts / address changes / etc)

5v / 2A micro USB for power

16GB SD card (> 8GB should be fine)

Keyboard & monitor /cables (Until ssh is turned on)

Initial Procedures:

Flash SD card with balenaEtcher or whatever works. Loved “ApplePiBaker”, but it always loses permissions & fails now trying to write :(

Boot it up, start w/ entering raspi-config

Update raspi-config

Change password

Change hostname to plamp

Enable SSH interface

Change locale ( en_US UTF8 ) / keyboard type (Generic 101 US) / set timezone US/EST or ( America/New York )

) / keyboard type (Generic 101 US) / set timezone or ( ) Exit raspi-config w/ reboot yes

Software Installs:

Install apache

sudo apt install apache2 -y

Append to the end of /etc/apache2.conf

ServerName plamp

Restart apache

sudo apachectl restart

Check for apache’s default index.html in browser

http://localhost OR http://plamp OR http://{IP_ADDRESS}

in browser OR OR Install php & extras

php php-curl php-jd php-mbstring php-zip

& extras Add yourself ( pi ) to www-data group

sudo usermod -a -G www-data pi

) to group Change all of default site’s ownership to www-data

sudo chown -R www-data:www-data /var/www/html

Set permissions "wr- wr- --r" on default site directory

sudo chmod 664 /var/www/html

on default site directory Set permissions of the default site directory contents

sudo chmod 774 -R /var/www/html/

Test your permissions by creating PHP file

echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

Check page phpinfo.php in browser, delete / hide when done

http://localhost/phpinfo.php

in browser, delete / hide when done Install MySQL

sudo apt install mariadb-server

Initialize / secure MySQL, change root password & yes to all questions

sudo mysql_secure_installation

password & yes to all questions Enter MySQL console

sudo mysql -uroot -p

Setup users & database in MySQL console

Import sql file from previous host

sudo mysql -uroot -p plamp_db < plamp_db.sql

Final Changes & Confirm: