LAMP 2019Open Source

Building a LAMP Server (2019)

Let’s learn how to build a LAMP server (Linux, Apache, MySQL/MariaDB, PHP) mostly from source. Not only is this educational, but it allows developers to test multiple versions of databases, scripting languages, etc. I’m going to keep this simple so anyone who can use a computer can do it. For the most part, you can just copy/paste the commands I list.

First, I want to apologize for never completing the 2018 series. Between moving and health issues I kind of dropped the ball. This year I’m going to try to make things simpler.

Estimated time (for entire guide): 1.25 to 14.5 hours
* differs greatly depending on how much you want/need to install

Articles In This Series

I’ve broken down each step in a separate article for brevity.

  1. Introduction — this article
  2. Setup VM
  3. Install Linux
  4. Development Tools
  5. Apache HTTP Server
  6. MySQL/MariaDB
  7. Other Databases

Software Used

  • VirtualBox — an open-source hypervisor for running our server as a virtual machine. I chose this over VMWare Workstation Player mainly due to licensing restrictions with VMWare. But if you are willing to spend the money for VMWare Workstation Pro, you may get better performance with it.
  • Apache httpd — a web server.
  • MariaDB or MySQL — the most common database engines for web servers.
  • Various other databases as needed.
  • PHP — a server-side scripting language that still remains very popular.
  • Other scripting languages as desired.
  • Linux distributions covered:
    • CentOS — still my personal favorite for servers. Extremely stable.
    • Fedora Server — similar to CentOS, but more cutting-edge.
    • Ubuntu LTS Server — this may overtake CentOS in popularity for web servers in 2019.
    • Debian — the distro Ubuntu is based on. Some prefer Debian for various reasons.
    • openSUSE Leap — one of my oldest favorite distros. It was the first I became familiar with after Slackware.
    • Arch Linux — I don’t normally recommend it for servers, but it is a good educational experience to learn to use it.

Hardware Requirements

This varies greatly depending on what all you install. DBEs like Oracle use a lot more processing power and RAM than MariaDB. Most modern desktop computers will be able to install everything. You will probably need a good deal of hard drive space, especially if keeping all the source code (which I recommend). Ideally you should have a minimum of 200 GiB of free hard drive space, and 4-8 GB of free RAM.

Do You Need All This?

I’m covering a variety of scenarios so you can develop whatever type of web application you need. The bare minimum you need for a LAMP stack is an operating system, Apache HTTP Server, MariaDB (or some other database), and PHP. So you can skip sections which don’t apply to you.

There Are Simpler Guides Out There

This is true, but none of them that I’ve found fully address multiple platforms or database engines. If you want a simple LAMP stack, there are plenty of websites where you can download a virtual appliance. This guide is geared towards those looking to develop web applications that support a wide range of Linux distributions, DBEs, etc. It is also a great introduction to Linux.

Why Not Just Use a Package Manager?

There are a variety of reasons why using your Linux distribution’s package manager is not ideal. Pre-compiled binaries often are not as high-performing as packages you build from source. They are also often outdated and many contain bugs. Lastly, it makes side-by-side installations of multiple versions impossible (this is particularly important when you want to run multiple versions of PHP, MySQL, etc.).

Filesystem Hierarchy Standard

Most guides on compiling software under Linux ignore the Filesystem Hierarchy Standard. I won’t go into why it is important to respect this, but the main thing we want to avoid is installing anything directly to the /usr directory. This would cause the package manager to overwrite the compiled software. Some people get confused about the difference between /usr/local and /opt. Generally, any software you compile should be installed to /opt. But software which upgrades core operating system tools (like make) should be installed to /usr/local. So you can switch between tools provided by your distribution and the compiled ones. You should maintain your original source files in /usr/local/src to make it easier to reinstall or uninstall the packages you’ve compiled.

There are exceptions to these rules and you will often see people argue about which location is best to install software to. In my experience, the primary advantage of using /opt is that you can easily remove/reinstall software by deleting the appropriate subdirectory. The advantage of /usr/local is that it is automatically part of your path on most distributions for binaries and libraries.

Compiling Software (short version)

While the individual steps for every package may differ, the basic steps for compiling software are usually:

  1. Download and extract source code.
  2. Create an empty build directory beside the source directory.
  3. Run ../source_dir/configure from the build directory.
  4. Run make followed by make check or make test.
  5. Run make install.
  6. Move build directory to /usr/local/src and cleanup other files.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.