LAMP STACK

The following is a guide to the LAMP stack, what it is, and why you need to know it. You will not be required to set-up a LAMP stack, but it is strongly recommended that you do. In either case, you will be required to at least know what it is. The following applies to Web Programming courses ITSE 1301, 1311, 2302, and INEW 2334.


This is not intended as a complete set of instructions and solutions. This is a guide and introduction to get you pointed in the right direction.


What Is It?

LAMP stands for Linux, Apache, MySQL, and PHP. Together, they provide a set of software for serving web applications via the HTTP protocol. Each component contributes essential capabilities to the stack:

  • Linux: The operating system. Linux is a free and open source operating system (OS) that is the de facto standard on the Web. Over 85% of all web servers are Linux servers. You cannot be a Web developer and not know Linux. Linux runs on any standard PC (Intel based computers). Even if you work in other stacks such as MEAN or Java EE it is highly likely they are also running on a Linux server. If you want to be a Web developer, unless you intend to work for Microsoft for your whole life, you need to know Linux. Even Apple runs Linux internally for their servers (not Mac OS).
  • Apache: The Web server. The Apache Web server processes HTTP requests and serves Web assets via HTTP so that Websites and Web applications are accessible through any browser connected to the Internet. There are other Web servers but Apache is by far the most used.
  • MySQL: The database. MySQL is an open source relational database management system (RDMS). With MySQL, you can store all your applications data in a format that is easily queried using SQL (structured query language). MySQL is by far the most used database in Web applications and is the de facto standard for RDMS on the Web.
  • PHP: The serve-side programming language. PHP is an open source interpreted language that works internally to Apache (i.e. it's built into Apache) to process information on the Web server. PHP is a fully functional, object oriented, extremely robust programming language, and is by far the most used language on the Web. Alternatively, you can use other languages within a LAMP stack, such as Perl, Python, Ruby, etc. but those are still considered part of a LAMP stack.

How Does It Work?

Here is a great simple short video explaining LAMP. You should watch this first before reading further.

At a very high-level, the LAMP stack order of execution shows how the stack works. The process starts when the Apache web server receives requests for web pages from a user’s browser.

If the request is for a static asset like an image, an HTML file, or a client-side JavaScript file (a JS file is a static asset from the sever's perspective), Apache simply serves that asset back to the browser. This is known as a static Web page or static asset.

If the request is for a PHP file, Apache passes the request to PHP, which loads the file and executes the code contained in the file. PHP also communicates with MySQL to fetch any data referenced in the code. PHP assembles assets and data to create the HTML that browsers require to display web pages. This is known as a dynamic Web page and can change with each run of the code depending on the functionality of the PHP code.


Set-Up Your Own LAMP Stack

You can (and should) set up your own LAMP stack on your own development computer. If you set up your own LAMP stack you can develop all your code on your computer without using an external Web server. This saves a lot of time in development and allows you to use a great deal more developer tools because you have direct control of the environment. You can even set up virtual hosts so that you can host multiple Web site projects at once and switch between them seamlessly.

MAC Users: If you have a Mac then you already have a Unix-based computer. Linux is also Unix-based. So, if you have a Mac, you have the option of creating a MAMP environment directly on your computer instead of a LAMP environment in a VM. If you would like to do this, try this tutorial or search for how to set up a apache mysql php on Mac and good luck (I don't do Mac, so you're mostly on your own on this one, but I will try to answer simple questions if needed).

Windows Users: While not recommended, you can also set up a WAMP environment. This is LAMP, but the OS is Windows. This is not recommended simply because 90% of all professional web servers are Linux and unless you are going to work for Microsoft, you should learn Linux. With that said, WAMP does work. If you would like to do this, you can search for how to set up a apache mysql php on Windows and good luck (I don't do Windows, so you're mostly on your own on this one, but I will try to answer simple questions if needed).


Step One: Choose Your Linux Environment

The first thing you need is a Linux install. Linux, like any operating system, has to work alone. In other words, you cannot have Mac OS or Windows and have Linux running directly on the same hardware at the same time. You have several environmental options for getting Linux installed.

  • Native Install: You can simply get rid of Windows on your PC and run Linux instead. There are a few different ways to do this but once you do, you can't go back to Windows (not easily anyway). You cannot do this on a Mac, it must be an Intel based PC. This is the "hardcore" option. When you do this, you're committing to a Linux computing lifestyle. Many computer scientists and serious scientific programmers and engineers do this. Most programmers do not.
  • Dual-Boot: This method allows you to install Linux side-by-side with Windows and when your computer starts (boots) it will ask you which one you want to use. You can only use one at a time, but you can always restart and switch OS's as needed. Many programmers do this, but it gets old going back and forth. This is typically the option for people who mostly want to use Linux but want to keep Windows around for things like gaming and some Windows-only applications. Again, this will not work on Mac.
  • Virtual Machine: You can install virtualization software which will allow you to create a simulated PC on your computer. That simulated PC will run in a window on your computer. Inside that Window will be an entire simulated PC and PC environment with simulated RAM, hard drives, drivers, and whatever else you like. Inside this simulated PC, you can install Linux and it will work like a stand-alone computer "inside" your actual computer. This works on both Mac and Windows. This is by far the most common way programmers work and it has many advantages. However, it's primary disadvantage is lack of efficiency and lack of access to real hardware. For example, for gaming or GPU programming this will not work since the virtual PC does not have access to the real graphics processor. If efficiency and access to real hardware is not a concern, this is probably the best option. Here are a couple top choices for VM software:

Step Two: Choose Your Linux

Linux is unlike Windows and Mac OS in almost every way. Windows and Mac OS are proprietary. There is only one most recent version of each. They are primarily designed as consumer products (especially Mac OS). They are constrained by the companies that own them.

In contrast, Linux is open source, free, and exists in dozens of different "flavors." Some companies have created proprietary versions but those aren't important for this discussion. You can reprogram, modify, and "hack" Linux all you like. Linux is not primarily designed as a consumer operating system (but that's changing slowly), it's a serious, industrial-strength server and developer operating system. Linux also forms the basis for countless other operating systems such as Android, Playstation, most IoT devices, embedded systems, etc. As such, you have a lot of choices. Here are the most popular to get started:

  • Ubuntu: Ubuntu has emerged as the clear leader in blending industrial-strength Linux power with a user friendly interface. The community is huge and versions are well supported. If in doubt, go with Ubuntu.
  • Linux Mint: Mint is a Linux distribution built on top of Ubuntu. It uses Ubuntu’s software repositories, so the same packages are available on both, but this distribution has its own identity and many prefer it.
  • Debian: Debian is an operating system composed only of free, open-source software. It’s known for moving much more slowly than distributions like Ubuntu or Linux Mint. This can make it more stable and conservative, which is ideal for some purposes.
  • Fedora: Fedora is a project with a strong focus on free software (you won’t find an easy way to install proprietary graphics drivers here, although third-party repositories are available). Fedora is bleeding edge and contains the latest versions of software.

Step Three: Install the AMP Components

Once you've chosen your working environment and your Linux version, and you've installed Linux according to your version's instructions, you can install the AMP pieces. That discussion is too complex for this guide but there are many good online resources. The following are a couple for Ubuntu. If you want another install, just search for yours with the search terms "How to install LAMP on <insert your Linux version here>". Of course you will have to be good with the command prompt, so make sure you understand that first.