The LAMP Stack :: Part IV :: P Is For PHP

The LAMP Stack :: A Short Explination :: Part IV :: P is for PHP

And lastly, PHP. PHP is a high-level interpreted language. The acronym stands for “hypertext preprocessor”. So it should really by HPP, but it’s not because originally it stood for “personal home page”. I learned that one just about a year ago. Anyhow, it is interpreted meaning that you do not need to compile the program before your visitors use it. You can write programs in compiled languages for the web, but I think for the most part, compiled language programs are for your computer, or run on a server as a standalone program. I have seen a few websites that were written in C++ and then compiled and put in the web directory’s cgi-bin directory. The cgi-bin directory is a special directory that is setup (some configurations differ) to run server-side scripts.

PHP is where you would write your programs that actually do your work for your website visitors. You can have a plain ‘ol website that shows some stuff as an .html page. That page would just be a file sitting on the server that sends out it’s entire contents. But if you wanted people to log into the site, you would need some programming to process information that visitors would put into forms on your website, check a database to see if they are one of your users, and then send them to a page a visitor could normally not get to. You may just simply want to say something like “You’re computer’s IP address is %%SERVER[‘remote_ip’]%%”. You can do that by doing this:

<p>You’re computer’s IP address is <?=$_SERVER[‘REMOTE_ADDR’];?></p>

There are literally an endless amount of things you can do with PHP. It’s a very powerful language and has just a ton of built in features.

Basically, any language you can kick out what apache can server to the web. PERL (being another interpreted language like PHP) scripts that I have run in the past out to the web via apache just need a one header line to start it off like this:

#! /usr/bin/perl
print “Content-type: text/html\n\n”;
// kick out the rest of your awesome PERL website

You can see more on how to do that on my other blog post PERL :: Saying Hello World - I’m Just Getting Started. Joe, you’ve already seen it.

Another example of a compiled website that I ran across before was a site written in .NET. I do have to note that I do not play in the .NET word; never had the liking for anything Windows, really. This information is from about 7 years ago: This is Window’s programming that gets compiled and sent to the web as an entire thing. What I mean by that is the whole website of various pages and functions are all one network of files. The bad thing we ran into with that is if there is an error on one page, it killed the whole website.

PHP has become quite popular in the past decade or so. Many popular websites and frameworks are built on the language such as Facebook, Wikipedia and YouTube started as PHP. Frameworks like WordPress (which makes up a healthy percentage of blog and other sites out there today), Drupal, Joomla and the ever-so-horrible Magento are also written on PHP.

Before I was talking about machine code and that I would touch back on that in this section. Here we go then. I will explain a scenario that sums up how a PHP script gets processed. This is a simplified version of the process because, honestly, I’m kind of tired of this blog post. Just kidding; because there are many different configurations and setups that could vary this process, but I think this will layout the basic process in most situations.

  • A website visitor visits your site and directly calls the php script
    For instance, they could visit

  • Apache finds the file and sees that it’s a PHP script and runs it using PHP.
    On Windows, it runs php.exe and on *nix, it will run the binary like /usr/bin/php

  • The PHP program compiles your code into opcode. Opcodes are instructional codes sent to the machine

That is really simplified. Here’s a pretty good blog post of someone else’s that explains more about opcodes and includes the instructions on how to view them if you so desire:

That about does it for me. I hope you enjoyed this short explanation. If you have any questions, feel free as always to ask below.


Recent Posts