Configure CoffeeBot’s Web Server
We need a way for customers to tell TurtleBot that they want coffee and manage the coffee queue if multiple people want coffee simultaneously. There are multiple ways to do this, but considering this series is targeted at web developers, we’ll use a LAMP stack.
What is LAMP?
LAMP is an acronym for Linux, Apache, MySQL and PHP. In other words, it includes everything you need to run a web server and a database.
Creating a Web Server
You could create a local web server and have customers connect to that. But, instead of converting an existing computer to a web server, let’s spawn an instance in the cloud.
Amazon web services (aka: “AWS”) offers free micro-size Ubuntu web servers for 1 year. You’ll need to type in your credit card number but as long as you cancel in the first year and don’t use more resources than offered in their free plan your card will not be charged.
If you don’t already have an AWS account, click “Create Free Account” on this page. Once you’ve finished signing up, click “Launch Management Console”.
Creating Your CoffeeBot’s AWS Instance
- Log in to the AWS management console.
- Click “EC2″.
- Click “Launch Instance” button.
- Select “Ubuntu Server 14.04″. (Tip: This is the same distribution of Linux on your computers, so it should act similarly.)
- Select “t2 micro”. (Tip: Make sure it says “free tier eligible” so you won’t be charged.)
- Next: “Configure Instance Details”.
- “Review and Launch”.
- By default HTTP is off. Without this no one can access your server via a web browser.
- Under “Security Groups” click “Edit Security Groups” and select “Add Rule”.
- From the pulldown menu select “HTTP”.
- Click “Review and launch”.
- Select “Launch”.
- A key pair will give you the credential file required to SSH into your server.
- Create a new key pair.
- Key pair name “turtlebot_new”
- “Download Key Pair”
- Save it in your downloads folder.
- Click “Launch Instances”.
- Select “View Instances”.
Determining Your Public DNS
Your instance’s public DNS is how your customers (and TurtleBot) will connect to the server. Let’s go ahead and copy it for later use.
- Log in to the AWS management console.
- Click “EC2″.
- Click “Running Instances”.
- Select the checkbox to the left of the instance.
- The “Public DNS” value is available at the bottom right.
TIP: We haven’t installed the LAMP stack on your server yet, so if you call the IP, nothing will happen.
SSH in to AWS Instance
IMPORTANT: Change [PUBLIC_DNS]
to the value you copied earlier.
In a terminal window run the following:
When it prompts:
Type yes.
Installing the LAMP Stack
Shell (ssh) in to your server, then run the following commands:
Install Apache
Install MySQL
When prompted, set the root password of MySQL to “turtlebot”.
TIP: This is a terrible password, so feel free to set it to another value–but you’ll need to modify the config.php file cloned from github in a later step.
Install PHP
Give Ubuntu user rights to /var/www/
Restart Apache
NOTE: In the video we tried service apache2 restart
but this fails. stop
and start
succeeds.
Clone PHP files
NOTE: In the video I first tried “git clone” without “sudo”; “sudo” is required.
Clone Web App
The web app is very similar to the browser extension but will allow your customers to request coffee directly from their smartphone. We’ll discuss this in more detail later, but for convenience let’s go ahead and clone it as well.
(Optional) Set MySQL root password
If you didn’t set the MySQL root password to “turtlebot”, you need to edit the configuration file. If you did set the MySQL root password to “turtlebot”, skip this section.
Scroll down to:
and update the value.
Then ctrl + x to exit and y to save.