How to Setup a LAMP Stack with MySQL HeatWave – Part 1/5

September 7, 2022 | 7 minute read
Stuart Davey
MySQL Principal Solution Engineer
Text Size 100%:

Introduction

This is the first in a series of blogs that detail how to setup and use a LAMP Stack that makes use of MySQL HeatWave in the Oracle Cloud.

  • Part 1 (this part) will set the scene by detailing what a LAMP stack is and what deployment options are available in the Oracle Cloud. It will also set out the architectural vision for the LAMP stack this series of blogs will build.
  • Part 2 will build the infrastructure (network, application server, database server) in the Oracle Cloud.
  • Part 3 will install and configure the remaining LAMP stack software.
  • Part 4 will install additional software to assist in developing web applications.
  • Part 5 will consider how to make the stack more scalable, available and secure.

 

What is a LAMP Stack?

LAMP is an acronym that stands for Linux, Apache, MySQL and PHP. These technologies collectively form a stack to build, deploy and manage web applications. The LAMP stack is perhaps the oldest of all web development frameworks and is still one of the most important with some commentators suggesting that up to 50% of all new web developments either use the LAMP stack or a variant of the LAMP stack.

The stack can be visualized as follows:

LAMP Stack

 

The stack begins with a server and some storage. On the server a Linux operating system is installed. The Linux operating systems allows the other stack components to read from and write to the storage as well as make and receive network calls. MySQL is then installed. This is the stack’s database server and will store web application state (e.g. user details, store inventory, etc.). PHP is layered on top. It is responsible for implementing the business logic of our web application. As part of that logic PHP will use the underlying database to store data and later retrieve it when requested. Finally, we have the web server, Apache. This is responsible for receiving http(s) requests (e.g. a request for a web page) and responding to them (e.g. returning the requested web page). When a request is received by Apache it will determine whether the request needs processing by PHP and forward it accordingly. A request to PHP may require the services of the database, in which case it will communicate with the MySQL database. MySQL will return its results to PHP. PHP may further process these results before returning its data (typically in the form of a web page) to Apache. Apache will then package this as an http response and send it to the requestor. 

A LAMP stack has a flexible architecture: the database server can be stored on a separate server to the application server (Apache and PHP). Splitting the components in this manner has a number of benefits:

  1. The database and application server components can be independently scaled as required.
  2. The stack can be made highly available. The application server component can be installed and load balanced across many hosts. If one of these hosts goes down then the load balancer redirects requests to survivors. The database server can be implemented as a highly available cluster; if any node in the cluster goes down, requests are re-routed to surviving nodes.
  3. Security can be massively improved by simply firewalling off the database server from internet facing components (i.e. the application server)

 

What is MySQL HeatWave?

MySQL HeatWave is a fully managed database service that enables customers to run OLTP, OLAP, and Machine Learning workloads directly from their MySQL Database.

Being a service most of the administration tasks are done for you leaving you to concentrate on your database schema. Given the purpose of this series of blogs is to detail how to build a LAMP stack from the ground up only the basic MySQL Database Service will be discussed;  OLAP and Machine Learning are beyond its scope. 

 

LAMP Stack Deployment Options in the Oracle Cloud

Currently (July 2022), there are three options:

  1. Build your own from the ground up.
  2. Use the EMEA MySQL Community Manager’s Terraform scripts to automatically build and deploy a LAMP stack.
  3. Use an Oracle Marketplace Image.

This series of blogs will follow the first option: build your own. This will give the reader a full insight into how stack should be deployed and works. Further, if the reader follows these blogs they will be fully in charge of their own destiny both in terms of software versioning, security and cost.

The second option is a really good way to deploy a LAMP stack. Its only drawbacks are that it does not currently deploy the latest versions of Apache and PHP, and it is not clear whether its scripts will be maintained going forward. If you are happy with this approach and prefer it to building your own then please see the Community Managers blog.

The third option would seem to be the easiest way of deploying a LAMP stack. However, it has commercial, security and scalability limitations:

  1. It attracts a charge over and above that which must be paid for any chargeable items of cloud infrastructure. At the time of writing (July 2022) this charge is $0.05/hour. This may not seem much but it soon adds up: $1.20/day; $8.40/week; $36/month (30 days) and $438/year (365 days).
  2. You may be precluded from using this image due to your country and billing currency.
  3. The stack is deployed on a single server and so won’t readily scale.
  4. The versions of software used in the stack are becoming old. You cannot specify versions upon install.
  5. MySQL Community Edition is used rather than the MySQL Database Service. This means you will have to do all the administration for the database (e.g. upgrades, backups, etc.) and support will be purely community based.
  6. Additional work is required to secure the stack – particularly with respect to the phpMyAdmin application that is pre-installed.

 

Architectural Vision

The first thing we need to consider is the infrastructure architecture:

  1. We will separate out the application server parts from the database server in order to:
    1. Provide greater security: the database will be firewalled off into a security zone that is not accessible from the internet. We will open ports in the firewall to allow the application server to communicate with the database server.
    2. Make provision for future scaling.
    3. Make provision for high availability
  2. We will use the Oracle Cloud (OCI)
    1. OCI is the most modern and secure of all public clouds. It is also the most competitively priced. Note that Oracle also often offers generous free trial periods – please see https://docs.oracle.com/en-us/iaas/Content/FreeTier/freetier.htm for details.
    2. Using OCI means we can benefit from using the MySQL Database Service. The MySQL Database Service is a fully managed Oracle Cloud Infrastructure native service, developed, managed, and supported by the MySQL team in Oracle. Oracle automates tasks such as backup and recovery, and database and operating system patching. You are responsible solely for managing your data, schema designs, and access policies.

Our logical infrastructure architecture design will look like this:

LAMP Stack Logical Infrastructure Architecture

 

With respect to software the latest stable versions for Apache, PHP and MySQL will be used. MySQL is being implemented as a service, and the service always provides the latest stable version (8.0.29 at the time of writing, July 2022). Apache 2.4 and PHP 8.1 are the latest stable versions and shall be used. The Linux operating system to be used will be Oracle Linux 8. Note: OL8 is compiled from Red Hat 8 source code and effectively is Red Hat without the Red Hat branding. Therefore, the commands and work flows in this series of blogs should be applicable to all other variants of the Red Hat operating systems (i.e. Red Hat, Fedora and Centos). If you use Ubuntu then you should still be able to follow the work flow but there will be some differences when installing and using software, for example: repository access (apt as opposed to dnf/yum with OL8), as well as package and application names (e.g. apache2 as opposed to httpd with OL8).

In order not to over-complicate things, administration will be done from the application server. In the first instance the only additional software to be installed will be MySQL Shell; this will allow the upload of a test schema to the database.

Once the stack is in installed and operational, further software will be installed:

  • Git – to allow developers to manage their source code (i.e. versioning/change tracking, working collaboratively, etc.).
  • Certbot – is a free, open source software tool for automatically using Let’s Encrypt certificates on manually administered websites to enable HTTPS.

In terms of this blog series Git will be used to access the source code of a simple demonstration web app on GitHub. Certbot will be used to provide a TLS/SSL certificate so that users of the web application can access it securely. 

 

Summary and Next Steps

In summary we have learned what the LAMP stack is and we have a clear architectural vision as to what we are going to build. All that remains is to press on with the second part of this series of blogs.

Continue to Part 2.  You can also watch the recording below.

LAMP Stack Logos

Stuart Davey

MySQL Principal Solution Engineer


Previous Post

MySQL Window Functions Part 1

Scott Stroz | 12 min read

Next Post


How to Setup a LAMP Stack with MySQL HeatWave – Part 2/5

Stuart Davey | 27 min read
Oracle Chatbot
Disconnected