Way back when (between the mid ‘90s to mid 00’s) I was an Apple Mac user. I got to experience Mac OS 7 through to the early versions of Mac OS X, and I enjoyed the transition to OS X thanks to the Unix undercover and terminal fun that could be had.
I’ve recently gone back to OS X (thanks to an offering of a cheap Mac Book) and have started playing around with terminal again. As much as I enjoy Ubuntu and it’s BASH, I do feel that terminal on a Mac runs smoother as a shell environment.
This week whilst poking around a local charity shop (I enjoy charity shop bargains) I found a book on PHP from 2002. I often pick up charity shop books, even older tech books just to see if they contain any knowledge/information I have not found from another source. In this case the PHP book was less a source of information (unless you are on Windows XP and struggling installing Apache) and more a source of inspiration.
I got home and decided that my Raspberry Pi 3 was being under utilised unlike it’s sibling (a Raspberry Pi 2) which is currently a motion sensor home CCTV controller. The PHP book inspired me to use the Pi as a web server (internally at home). As part of LAMP the Pi already completes the L (Linux) and just needs A (Apache), M (MySQL) and P (PHP).
Not wanting to use up desk space with a monitor, keyboard and mouse connected 24/7 to the Pi I decided to try and do most of the implementation of the rest of LAMP on the Pi via my new Mac.
I connected the Pi up, enabled SSH (changing the default password) and then fired up Terminal on my Mac. SSH (Secure Shell) is a great way to run shell commands remotely on another computer. My first issue – I didn’t like having to tell terminal to do SSH to my Pi. I know there is probably a way to run a log script when I start a terminal session but instead I decided to use some tech that I have used years ago on Mac OS….AppleScript!
I fired up Script Editor on my Mac and tested my rusty know how:
tell application “Terminal”
do script (“ssh USERNAME@IP ADDRESS OF PI;”)
do script (“PASSWORD”) in window 1
The script does have the issue that my Pi username and password are stored in plain text, but Script Editor allows me to save the script as an application on my desktop and it works.
After a few apt-get installs for Apache, MySQL and PHP, my Pi was ready. I fired up nano and created a quick index.html file in /var/www/html/ of my Pi, then loaded up the browser on my Mac and navigated to the IP of the Pi – boom, webpage works.
I set up a quick SQL database (named pisite) and then tested some PHP:
$servername = “localhost”;
$username = “username”;
$password = “password”;
$conn = new PDO(“mysql:host=$servername;dbname=pisite”, $username, $passwor$
// set the PDO error mode to exception
echo “Connected successfully”;
echo “Connection failed: “ . $e->getMessage();
<?php $testvariable = “
Hello Universe as a variable!
Next up I might try a local install of WordPress or see if I can transplant my chat bot idea to run off the Pi on an internal webpage….
2 thoughts on “Where I Set Up LAMP on a Pi…”
Comments are closed.