© Jonathan Bartlett 2019
J. BartlettBuilding Scalable PHP Web Applications Using the Cloudhttps://doi.org/10.1007/978-1-4842-5212-3_1

1. Introduction

Jonathan Bartlett1 
(1)
Tulsa, OK, USA
 

“The cloud” is the new technology buzzword. It seems like everyone is talking about “moving to the cloud,” but few people really know what that means, least of all how to take advantage of it. With every technology shift, there are people who think that the new technology will solve all of their problems, without even taking inventory of what those problems are. Many technologies make promises, and some of those are even true, but for them to come true, you have to use the technology in the right way.

This book is primarily for developers who want to start moving their apps to the cloud, and want to know how to get started and different options available to them. Secondarily, this book is for managers who want to be conversant in cloud technology and ideas, in order to better understand the options available and how different development decisions will affect them. This book has a focus on PHP, but, even if PHP is not your intended deployment language, this book will tell you what you need to know to architect a cloud application in any language or platform.

This book will talk about several different cloud options, but will focus on developing for Linode and similar clouds, the reasons for which we will see in Chapter 2.

Please note that this book makes many comparisons between specific infrastructure vendors. I do not represent any particular company, nor do I warrant that these comparisons are foolproof or permanent. They are, however, the results of my experience and my knowledge at the time of writing, and I have attempted to do all due diligence to provide factual information as best I can. Nonetheless, while the general considerations discussed in this book are unlikely to change, the specific vendors, products, and how they measure up are likely to change over time.

Additionally, while the general outlines of the tasks for setup, programming, and configuration are likely to remain the same for a long period of time, the specific steps and screenshots may differ from this book as products and platforms change. Nevertheless, the steps presented here should remain a reliable guide for what types of things you should expect from different cloud vendors.

1.1 Prerequisites

This book has very few prerequisites. Even if you aren’t familiar with the specific tools we are using, this book has enough step-by-step instructions that you should be able to follow it fairly easily.

Since it is a book on web applications, it assumes that you are familiar with the absolute basics of HTML, CSS, and the basics of how the Internet works (i.e., domain names, IP addresses, etc.). If you are not familiar with these things, you should put this book down and pick up a copy of my earlier book, New Programmers Start Here. New Programmers Start Here doesn’t hit every topic you need to know, but if you understand its concepts, you should be able to work through most of the examples in this book.

The code in this book is based on PHP, but the code is simple enough that you should be able to follow it no matter what language you are familiar with. PHP was chosen because it is easy to write short, understandable web applications with PHP. For instance, in my job, I almost always program in Ruby on Rails. However, it is almost impossible to understand a Rails application without already being familiar with the entire Ruby on Rails system. PHP, on the other hand, is less “magic” than Rails, but that makes it more obvious to the reader what is happening. With PHP, especially at the level which this book uses it, I’m confident that anyone who has experience with any programming language will be able to follow what is happening.

This book also presumes that you have a basic familiarity with databases and SQL. This is not an absolute requirement, but the database code itself is left largely unexplained. However, the SQL code should be self-evident to anyone with even a passing knowledge of SQL.

Finally, this book uses Linux as the operating system of choice. However, even if you don’t know anything about Linux, this book gives you every command you need to type, so you don’t actually have to know anything about Linux to use this book. Appendix A has a list of common Linux commands for reference if you want to know more.

The reason that Linux was chosen was because it is a very easy operating system to install and use in a cloud environment. While it is possible to use Windows in a cloud environment, Linux was built from the ground up for this type of application. The command line, while seemingly arcane, actually makes server management fast and painless.

Additionally, because Linux, PHP, and PostgreSQL (our database system) are all free software, there are no licensing considerations for their use. You just install what you need and move on with your life. You don’t need to worry about who you need to pay when. You don’t need to worry about whether your usage matches your license for the product. You don’t need to worry about someone auditing your business to verify compliance. With free software, software is just a tool—you can install it and forget it.

I don’t have a problem with proprietary software in principle, but, because it introduces a ton of extra management issues, I try to avoid it if possible. I am not against people being paid for their work, but I do take a principled stand against never-ending, needless headaches, which is what you wind up with when you rely too much on badly licensed proprietary software.

This book focuses on the CentOS 7 Linux distribution because CentOS tends to be a fairly stable and robust Linux distribution that is supported by most vendors, and many other Linux distributions use CentOS as a starting point.

1.2 Typographical Conventions

This book uses a few, simple typographical conventions you should be aware of. When referring to code, typed commands, URLs, or any other text meant for typing, the book uses a font that looks like this: type me here. Names of programs which are the same as their command name (which you would type in to use) are also written in that way, as are usernames and filenames.

However, many things that you type will need to be replaced using your own values, such as the IP addresses for the machines that you deploy. These things that need to be replaced are given by words with all uppercase letters. For instance, to go to your own web site, you would type into the browser http://YOUR.DOMAIN.HERE/, where YOUR.DOMAIN.HERE refers to your own web site’s domain name. The meaning of these and what they should be replaced with are described in the text.

Note that PHP actually has a few default variable names that are all uppercase that we will be using. Therefore, $_GET, $_POST, and $_FILES are all real variable names in PHP and should not be replaced.

This book describes how to use a variety of third-party services. When describing the menus, buttons, and field names of user interface elements on various web sites, these items will usually be placed in double quotes. For instance, to print out a file from most programs, you would go to “File” and then click “Print.”

1.3 Typing or Downloading the Code

This book focuses around a simple guestbook application, building and rebuilding it using different application architectures. The entire code for the application is in this book. Honestly, I think it would do you a lot of good to type out all of the code in this book yourself. There isn’t very much, and it would help you think about what you are building. However, I understand that this can get tedious when you are just trying to work the examples, and having complete, working code is very helpful when trying to solve problems.

Therefore, all of the code for every variation of the application we cover in this book is available for download from www.github.com. Each branch in the repository represents a different modification to the application in the book. Using the repository, the only changes you would need to make are the environment-specific changes mentioned in the text of the book, such as setting the IP address of the database server. These are also in the README file for each branch.

You can download the code at

https://github.com/johnnyb/cloud-example-application

If you do type in the code yourself, pay close attention to where the spaces are used in the program. The code is written exactly as it should be typed, with line breaks where they should be unless indicated elsewhere by the text. Putting spaces and line breaks in the wrong place or leaving them out where they should be is a surefire way of messing up the code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.199.130