Project Sunday: LAMP Stack with Raspberry Pi

Project Sunday: LAMP Stack with Raspberry Pi

And a few failures along the way, per usual

I have been wanting to take some time and write about my journey to create a LAMP stack with my Raspberry Pi 4, and today is the day!

I took a LOT of pictures and tried to capture the resources I used, as I made a few mistakes and hit a few bumps along the way.

First; what is a LAMP stack? A lamp on a stick? A stack of lightbulbs? It's just an acronym for Linux, Apache2, MySQL and PHP. You can read more here. At a basic level, the goal is the production of a web server that you build through the Apache service, requested through your web browser, and your PHP grabs data out of the SQL db. Linux serves as the frame for this to happen.

I changed mine a bit to use Python rather than PHP, and ended up using MariaDB instead of MySQL but they're pretty much synonymous.

So I started with a follow-along from Digital Ocean.

In my RPBI, for funsies, I made a new user account with root privileges. Because I also have a sick chicken right now, I named it in her honor. So my chicken helped with the first part of this project, you could say.

chicken.jpg Chicken Helpers

1 CreateAccount.jpg

Then, we were off to the races. I already had Python installed but I ran a --version check, just in case. So we went to mySQL next, which is where I discovered Debian systems prefer "Mariadb"... 2 SuccessfulInstallofMariaDB.jpg

So after some minor command changes, MariaDB was installed and I checked to make sure the database was 'active'. This would come in handy later in the project.... as it didn't stay that way.

3 MariaDBactive.jpg

I played around with installing Apache2 next, and didn't finish before the sleep monster hit me. So I came back to the project the next day.... except, I couldn't be at my RPBI - I was on my laptop for another "project" that didn't require my intellectual or tactile engagement. So... having already installed VNC on my iPhone, I remoted into my Pi to see if I could maybe finish the install from my phone.

I ran a couple of commands and ping'd google 77 times, but realized this would probably be a better job for SSH. I wanted to try PuTTy since I hadn't really used it before, so I grabbed it with Chocolately and tried my hand.

VNCPingForFun.png Hehehe

FindPutty.png Finding PuTTY

ChocoInstallPutty.png

Installing PuTTY

If this weren't multi-tasking and distracted enough, I logged back in through VNC to double check my Pi's configuration for SSH.

EnabledSSH.jpg

So, Chocolately installed PuTTY seamlessly, but there were some issues.

To make this work, I had already set up a static IP address for my Pi many moons ago, also a part of the Pi-Hole project. Here's how someone did something similar using Docker (a tool I love).

So we simply just put this little IP address here, it opens a handy window -and zing! We're in...... wait........no.

6 GetIntoFromPutty.png Getting in looks good in the GUI!

7 LogInFromPutty.png Oh this looks smooth!!

But unfortunately I got an "Access Denied" despite 5 attempts. So... I went command line. Straight to the terminal!
My sweet, OhMyPosh-ed terminal.... mmmm....

TroubleshootByPing.png I started by ping'ing my IP to make sure it wasn't a legit network error, and everything looked fine -so away I went from the comfort of my laptop.

I added my connection in, verified credentials, and started to check on wherever I left off last. 8 ApacheFromWindowsTerminal.png

It went okay at first; 9 Info update.png

Then I ran into some issues trying to restart the Apache2 service, and test connection.

troubleshootingAPache2.png Turns out I had 2 open "Listening" ports conflicting with Apache's service, so I had to kill one. This took a minute to figure out, hadn't done that before.

If you've ever opened a regular-shmegular Apache2 browser that isn't receiving anything particular -but it is alive; it looks like this:

SemiDeployed.png I can't remember when or why I had opened this other port but, I needed it to only listen to the new feed, with my Python file!

Eventually, I found some instructions and sudo sudo sudo to the magic. Other Apache2 probs

I worked on the Apache2 configuration file in my scramble to identify the issue, and also tried exporting my systemctl results to file in case I'd need that; in the event of total failure.

Apache spam: ApacheConfigFile.jpg ApacheRegistryUpdate.png ConfigTestinApache.png

Okay. So... let's kill that extra port and see what happens. killedPort80.png

Yep, that worked! Great.

Okay, let's fix this.

ApacheRunningNow.png

Success! However, at some point, I got my actual Python script file back... from the browser, as a download. Not gonna lie, I wasn't mad. Something was working.

I let time work its magic, and it came back to me alive and well after a forced restart log-in, cup of coffee, grumbling to self and chasing a sick chicken.

Then, I worked on verifying database & Python functionality. Was Maria still with us??

CheckDBSVCandRestart.png

I was missing some sudos and some root info (still a Linux beginner) but finally figured out what I needed to get in, and then played with tables, and databases for a few minutes. I am going to into this heavily later.

SHOWDBs.png

I made sure MariaDB could be restarted and I knew (sort-of) how to log back in.

18 FinalMariaDBFixed.png

And now, I wanted to check and see if my Apache had caught up. Was it going to work? Everything should be good now, right??

ScreenWhenConnectedSSH.png Not quite - here I was staring at an obvious whoopsie on my part. I missed the install of a python package earlier in the steps! No issues, of course. Just some pip -install from the SSH connected terminal to resolve my mistake.

installedPymySQL.png

Seconds later, that was finished and I tested functionality one (hopefully final) time:

IntendedResultWebpage.png

Success!

3 minutes of happy dancing ensued.

There are many ways to set up your own web server at home. The one I built is for testing, rather than production - but running a web server on a Pi is actually a really affordable, lightweight way to do it.

Please check out this and other projects on RBPIs for your own home lab and please share your journey!

I don't hide my mistakes (as you can see), and encourage you to keep trying if you're just trying to learn- it will almost always take a bit longer when you're starting out, but it's so much fun when you get it dialed in!

Plus, working with stuff like this from the CLI, or one computer to another, or having a script talk to a browser .... I mean, it's basically like wizardry, am I wrong?

This project was brought to you by:

  • Raspberry Pi 4 + (7" LED screen)
  • Murphy the Chicken
  • 8 cups of coffee
  • Lots of streaming music
  • 2 long naps
  • Command line tools in Debian/Linux, Powershell/Terminal (Windows) & SSH
  • Predator and 2 really big monitors
  • 1 iPhone 5 (not a joke)

Thanks so much for reading! Please reach out if you enjoyed this journey!