Home News WebDev Links About Garden Notes LAMP Stack Using Git Using SSH/SFTP Linux Commands

Dynamic Websites Using the LAMP Stack

What is a Dynamic Website?

Probably the first question should be, why do we need anything more than simple html code and css style sheets for our website? The answer is that if your website is only a few, relatively static pages, then html plus css will do just fine.

If, however, you want a site that is regularly updated or that changes its pages based on user interaction -- in other words, a dynamic website, then simple, static html won't stand up well to the test.

Suppose, for example, you have a news site with a number of articles being contributed frequently by a variety of journalists. Just updating the front page would be difficult enough, essentially requiring rewriting the page's html for each new article. If in addition you want users to be able to choose which articles they want to see (say by subject or author or date), then the task of presenting the data with html alone becomes near impossible. You need the server to be able to generate the html dynamically.

Model-View-Controller (MVC)

Software designers confronted this problem by separating design into three parts, which they termed:

So this Model-View-Controller approach separates the data from the logic and from the presentation format. Wikipedia has lots to say about this, here.

What this lets developers do is put the site's content (the articles in our example) into a database and use the views both for input from the user, e.g., selection of articles by some criteria, and for formatting the data being returned to the user, e.g., her requested articles. The controller is the engine that interprets the user input, fetches the appropriate data from the database and sends it back to the user formatted by one or another of the view templates.

So, How Do I Get Started?

The LAMP Stack

This is where the so-called LAMP stack comes into play. LAMP refers to a group of programs that you can install on a webserver which together allow you to design and build dynamic websites. LAMP is an acronym originally standing for Linux Apache MySQL and PHP, though today it has broadened to include many alternatives. Wikipedia's article on LAMP is informative.

Some Options for Installing

There are a huge number of different approaches to intalling the LAMP stack, including where you install it (local computer, remote server), the operating system (Windows, Mac, Linux, etc.), the web software (Apache or nginx or other) and the database (MySQL, SQLite, and a myriad of others).

This site, How to Install LAMP (Linux, Apache, MySql & PHP) on AWS EC2 with Ubuntu 18.04 does an excellent job of walking you through the steps from creating an AWS EC2 server instance from scratch all the way to confirming the webserver and PHP are working and accessible from the internet. It leads to the following components:

I will add details about adding a contact management system package.

PHP Language

As noted above, PHP is a scripting language that has grown with the web to be very popular for generating dynamic websites. If installed as detailed above, script files are typically saved on the server in webroot (something like /var/www/html) in files with the .php extension. When a user goes to one of these files in his browser (url like "http://mysite.com/index.php"), apache reads the file, recognizes the "<?php" tag and passes the commands off to the php interpreter. Output from the php interpreter is returned to apache which then responds with the resultant html to the browser request.

In computer terms, PHP is fairly old, dating back to 1994. Its originator, Rasmus Lerdorf, wrote several CGI programs in C to address some of his needs for his personal website. He has said that he never intended it to be a full computer language, but that it just grew organically which led to a somewhat jumbled structure in its earliest versions. Major updates, however, culminating with the current version 7, moved it strongly into the modern era with greatly improved performance, better consistency and much improved OOP capabilities. Wikipedia's PHP article provides more detail on this history.

The following resources will help you get started with PHP:

PHP Frameworks

So, to build your new dynamic website using your LAMP installation, you just have to fire up your code editor and whip out the PHP code for the controller, the database schema, the templates, and so on, right? Well, yes, but why re-invent the wheel.

There are a lot of advantages to be had from using web frameworks, since they do a lot of the basics for you, right out of the box. Here are some articles about frameworks. The first is more general, covering a variety of languages while the second focuses on PHP frameworks:

PHP Content Management Systems (CMS)

To gain even more of a head start on your dynamic web site, if your goal is a content management system, there are quite a number of open-source systems that are in active development that work well on the LAMP stack, including such popular systems as Drupal, Joomla and WordPress. You can find a fairly exhaustive list on this Wikipedia page.

The benefit of using one of these is they provide even more of the infrastructure tailored to the CMS process.