Skip to content

Quick and Dirty PHP Lab:

IBM7094

“Hey Bill, load the PHP 5 tapes on bank 4. Maybe it will be ready by tomorrow morning…”

New Employer: “How much do you know about PHP? We’re going to need you to work with PHP and Symfony.”

Me: “Give me the weekend and I’ll get back to you on Monday.”

Sometimes you need to learn things quickly and that involves setting up a lab to read documentation, execute tutorials, and experiment with ideas. The great thing about open source is that learning materials are readily available. Taking what I had on hand, I cobbled together a PHP lab over the weekend. Now, to be clear, I’m not defining π here; the lab I’m about to describe isn’t complicated for anyone with a basic understanding of networking and system administration. But I was pretty proud of getting it up and running with minimal effort. I have to admit that I felt a wave of satisfaction once I saw it working. It was one of those, “huh! I guess I’m not an idiot after all,” moments. So, let’s take a look at this thing.

Objective: develop skills with PHP

PHP, for those who don’t know, is a general purpose scripting language that can do a lot of things, but is mostly used to execute server-side tasks. So, if we are going to learn anything about it, we need to have a web server first for a web client to query content from. This server and client need to be able to get to each other across a network. With a LAN, server, and client in place, we should have a functioning PHP lab.

Requirements: web server running PHP, web client with a browser, Local Area Network

php-lab

Here are the physical components. Most important is the Vim coffee mug: a gift from a dear friend.

Running Ubuntu 14.04 LTS on my laptop means that getting a web server up and running isn’t difficult. In fact, the web server Apache appears to be running by default and serving content from the directory /var/www/html. Using the package manager Apt-get, I ran through a basic LAMP (Linux Apache MySQL PHP) installation guide which installed PHP 5 and MySQL. Then, I created a phpinfo() file at /var/www/html/phpinfo.php and successfully tested that PHP was working. I also downloaded the PHP manual in the form of an HTML document and placed it at /var/www/html/phpmanual on my web server. The web server is good to go.

Using my tablet as the web client doesn’t require any effort: the browser software is already installed. But, I DO need to have LAN for the client and server to talk to each other over; this is a bit trickier because I don’t have much in the way of traditional networking resources in my apartment. But I do have a cell phone, and that cell phone supports creating a wi-fi hotspot which is basically a wireless LAN. So, I turned off data to my mobile provider because once the laptop, or tablet, saw that it had a gateway to the outside world, they would try to run all kinds of update processes over the Internet—checking for email and such—and this would have clobbered my poor pre-paid data connection.

php-lab-diagram

Here’s a logical diagram of the lab, picture being worth a thousands words and all. Notice that the cell phone is acting as a wireless switch; it’s handling all traffic between web server and client.

Once the hotspot was active, I connected the laptop and tablet to the network. Then, the moment of truth, I fired up the browser and pointed it toward the laptop, using the URL http://192.168.43.203/phpmanual and…it worked! The PHP manual sprang up on my tablet. Some times a hack is satisfying, no matter how small.

The tablet is serving two purposes here: 1) it is acting as a second monitor so that I don’t have to switch between any applications on the laptop, and 2) it allows me to test PHP scripts served from the laptop. On the laptop I have two windows open: 1) a BASH shell running Vim, and 2) Anki for writing up note cards. I’ve blogged about Anki before here, if you’d like to know more.

A brief defense of Vim: Okay, I’m not one of those people that defends my text editor with religious fervor. “Always use the right tool for the right job”, is what I say. If Notepad does what you need, cool. If you really like Emacs, knock yourself out. I like to use Vim for one simple reason: if you want to keep your Sys Admin skills sharp, you should be using Vim. The Vim learning curve is steep…really steep; it goes far beyond user unfriendly. For anyone who doesn’t know that I’m talking about, Vim is a text editor that allows you to create a plain text document. Pretty basic stuff. The thing about Vim, though, is that it was written back in the bad old days before the Graphical User Interface(GUI). Vim doesn’t know what a mouse is, and it doesn’t care. So, this means that in order to use it with any proficiency, you have to master a whole load of cryptic key commands to move the cursor around the screen or execute operations. So, why use it? Well, when you’re a Sys Admin, you’re going to have to log into all kinds of servers, of all ages and OSs, and most of the time you won’t have a GUI available. Because Vim is so old and standard, you can be sure it will be available on any Unix or Linux system you happen upon, no matter how old, big, or small. So, I like to keep my Vim skills sharp and use it whenever I can. Even if it makes life a little harder.

Praxis: The proof is in the puffing, as they say. With the lab in place, I fire up the browser on the tablet and navigate to the PHP manual. While reading through the manual, I can write up note cards in Anki for later review. When I get to the point of actually trying out PHP scripts, I create a directory for the test scripts on the web server at /var/www/html/phptest. Suppose I want to write your typical PHP, “Hello World”, script—not sure why, but every tutorial out there kicks things off with a “Hello World” script; at this point, it’s tradition—first, I fire up my text editor and write the script in the phptest directory; after I’ve saved the script, I open a new tab of Firefox on the tablet, navigate to http://192.168.43.203/phptest/helloworld.php, and see if it worked; I can then continue to modify the script on the laptop, save again, and refresh the page on the tablet to immediately see the results.

Conclusion: In less time than it took me to write this article, I was able to build a great learning resource with freely available software and technology that I already had. This is what I love about tech in general and open source projects in particular: everything you need to learn it and use it is just sitting there, waiting to be uncovered. PHP first came into the world in 1994, at the dawn of the web and browsers; Rasmus Lerdorf, the original author, cobbled together some tools to help him track the statistics of his on-line resume. And, when Mr. Lerdorf decided to publish the code to the world, the world ran with it. 19 years later, a guy like me can access tons of great documentation, painlessly install the software, and start learning the language in a weekend with no outside help, without having to pay a dime. All I need is patience and the motivation to learn.

We usually focus on the negative aspects of the Internet: trolling, cyberbulling, criminals with their scams; we don’t often talk about this amazing global community of people who work hard and then give their work away because they want knowledge to be free. Just think about that for a minute.

 

Post a Comment

You must be logged in to post a comment.