How to get started with Amazon Web Services: Part 2: Starting the server

Riddhiman Adib
My Online Cafe
Published in
9 min readSep 11, 2016
Image Credit: Business vector designed by Freepik

In the 1st part, we started an Amazon EC2 instance, with an IP address that looks something like 52.11.222.333, don’t worry if your’s doesn’t look like this, it’s just a sample. We’ll start this part from there and set up a LAMP server. In the next part, we’ll be syncing Amazon RDS and S3 with it.

What is a LAMP server anyway

LAMP Stack

LAMP is an open source Web development platform that uses Linux as the operating system, Apache as the Web server, MySQL as the relational database management system and PHP as the object-oriented scripting language. (Sometimes Perl or Python is used instead of PHP.)

In layman’s term, your PC works as a web server, when you have this stack set up and the server (in this case, Apache) running. After setting this up, your PC will be having LINUX as its OS, will be able to handle HTTP requests (thanks to Apache), store and handle relational databases (Thanks to MySQL) & run scripts in the server written in PHP (or Python).

Some of you might have already used WAMP or XAMPP in their windows PC. LAMP has basically the same stack, only difference is Linux OS in place of Windows. There are other variations out there, like LEMP (Linux+Nginx+MySQL+Python/PHP), or MEAN (MongoDB+ExpressJS+AngularJS+NodeJS) etc. Different server setup serves different purposes. In this case, we’re moving forward with LAMP.

But before setting up the server, we need to connect to EC2 instance so that we can control it and use it to setup LAMP. So, our basic steps in this tutorial:

  1. Use PuTTY to access Terminal of EC2 instance.
  2. Use Filezilla for secure file transfer.
  3. Setup LAMP server.

Okay, back to tutorial.

Part 2: Take control of your instance

Image Credit: Business vector designed by Freepik

Use Putty to use Terminal of your Instance

As opposed to how much we are used to use GUI (Explorer in Windows, or in simple term, “My Computer on Desktop”) to control everything in Windows, in the Linux world, we generally use the Terminal to order and communicate with the OS. We need to access the terminal of the EC2 instance for further use.

  1. Get PuTTY: Download and install PuTTY & PuTTYgen from the download.
PuTTY download page

2. Get Public IP: Note down the Public IP of the EC2 instance from the Amazon console (from the Public IP column).

Amazon EC2 Console

3. Locate Private (.pem) Key: Remember, in number 6 in the last tutorial, we mentioned to keep the private key file secured. We will need the key file (with file extension .pem) here to connect to EC2 instance. Locate the file.

4. Enable SSH: If you have followed earlier part of the tutorial, you have already enabled SSH as well as HTTP inbound rule enabled for your instance. To check again whether they are enabled or not, go to EC2 console, open instances list & click on whatever security group is listed on the column “Security Groups”. This will open Security group console. Now, with your security group selected, look at the lower part, click on Inbound tab, and check if it has both SSH & HTTP listed.

Inbound Rule for EC2 Instance

If it’s not, click on the drop-down “Actions” on the upper part, click on “Edit inbound rules” and add the missing options.

Option to change Inbound rules

5. Open PuTTYgen: We’re going to convert our .pem key to .ppk key using PuTTYgen to connect with EC2 instace via PuTTY. Now start PuTTYgen. (for example, from the Start menu, click All Programs > PuTTY > PuTTYgen).

6. Key Type: Under Type of key to generate, select SSH-2 RSA.

7. Point it to your .pem file: Click Load. By default, PuTTYgen displays only files with the extension .ppk. To locate our .pem file, we select the option to display files of all types. Select your .pem file for the key pair that you specified when you launch your instance, and then click Open. Click OK to dismiss the confirmation dialog box.

8. Save the private key: Click Save private key. PuTTYgen generally displays a warning about saving the key without a passphrase. Click Yes. We’re going to specify the same name for the key as the .pem key. PuTTY automatically adds the .ppk file extension. (“A passphrase on a private key is an extra layer of protection, so even if your private key is discovered, it can’t be used without the passphrase. The downside to using a passphrase is that it makes automation harder because human intervention is needed to log on to an instance, or copy files to an instance.” — Amazon AWS Doc)

9. Ready to connect: We’re now ready to connect to EC2 using PuTTY.

10. Start PuTTY: Open PuTTY.

11. Setup the PuTTY session: This is a big step, so follow carefully. Select Session in PuTTy. In the Host Name box, enter user_name@public_IP. In our case, user_name is ubuntu, and public_IP is your instance’s IP address. So, it’s something like this, ubuntu@52.11.222.333. Port is 22. Connection type is SSH. At the left side, go to Connection->SSH->Auth. Then at the right side, in the field for private file for authentication, select the .ppk file generated earlier in step 10. At the left side again, click the very first option Session to get back to earlier view, type a name for this connection, e.g. “Amazon EC2 Connection” in the Saved Session blank field and finally click Save. This will save our whole setup and make it easier to connect to the server seamlessly in future sessions.

PuTTY

12. Start the session: We’re all ready to connect to EC2 instance. Just double click on the earlier saved session named Amazon EC2 Connection, or whatever you named it. If it asks to verify your pc’s RSA fingerprint, accept it. You’ll see a black console that verified your username as ubuntu and connected via the key generated. This key authenticates your access to the Server. Keep this .pem and .ppk key very very secure, because anyone with this key can access your server.

13. Check terminal: You can enter any command in the terminal to check if it’s working correctly. For example, let’s type ls -all and press enter to view the folder directory structure. Or, type whoami and press enter to see your username, in this case, ubuntu.

So, finally, we’re now able to access our EC2 instance. Feel free to try out any linux commands you know. If you want to access EC2 instance anytime again, just start PuTTY and double click on your saved configuration. You’ll be back to the terminal again.

Don’t feel awkward if you can’t see any Desktop or GUI to control the server, I have felt it too, but it goes away with time. After a certain time, you’ll find yourself using the cmd prompt even in Windows too. :D

File Transfer: Use Filezilla to upload/download files to your instance

Now that we can control it, what if we want to upload files to/ download files from our server? We will use FileZilla for file transfer with our EC2 instance.

  1. Download Filezilla from here.

2. Open Filezilla and click on File > Site Manager.

Filezilla Screenshot

3. Click on New Site & add a new site with the following parameters:

Host: Public IP Address (or your public dns name of ec2 instance)

Protocol: SFTP

Logon Type: Key File

User: ubuntu

Key File: locate and select the .ppk key file used earlier

4. Press Ok & Connect. You can rename the saved state by right clicking on it, and changing it to your suitable name.

Server connected

You should be able to view directory structure in the right panel. The left panel is your PC’s directory. You can now upload/download any file you want to your EC2 instance.

Start server: Install LAMP server

Okay, we’re now at the final section of this part of the tutorial. We’ve already setup connections with our EC2 instance, as well as we can control it via Terminal using PuTTY as well as we can see and transfer files using Filezilla. Woohoo!

Now it’s time we setup our EC2 instance with LAMP server.

  1. Open PuTTY and connect to our instance.
  2. Enter the following commands one after another:
sudo apt-get update
sudo apt-get upgrade

3. Now enter this & press enter:

sudo apt-get install lamp-server^

Note down the usernames & passwords while installing, specially the username and password of MySQL. We’ll need this later for logging-in in Database. I’m not going into details with this part, because our tutorial is not targeted for LAMP installation, rather getting started with EC2. You can get tons of tutorials online for setting up LAMP. After setting up MySQL, you can access the db system using any MySQL client like MySQL Workbench, HeidiSQL etc. Remember, MySQL is installed only locally. This is not an Amazon RDS setup.

4. Okay, now seems like everything is in place. Now, in your browser (of any PC), enter the IP address of your EC2 instance (sample: http://52.11.222.333). If it shows a page like the following, you’ve successfully setup your EC2 instance as a server.

LAMP default homepage

Congratulations!

Extra: Setting up PhpMyAdmin

Now, this part is optional, needed only when you want to access MySQL with PhpMyAdmin. Type this in the terminal:

sudo apt-get install phpmyadmin

After the installation has finished, we need to execute a few commands to allow for us to access PhpMyAdmin in the browser. We need to change apache configuration by executing the following command.

sudo nano /etc/apache2/apache2.conf

This will bring up the apache2 config file, go down to the bottom of the file. There we will paste the following:

# Include web access to phpmyadmin
Include /etc/phpmyadmin/apache.conf

and hit ‘CTRL’ + ‘X’ to exit then enter ‘y’ to save, then exit.

Restart apache for changes to take effect.

sudo service apache2 restart

Now, go to link IP/phpmyadmin (sample: http://52.11.222.333/phpmyadmin) to see if everything works fine.

This is the end of this part of this series. This part was probably a bit long, but we’ve mostly wrapped up our works, and in the next part, we’re going to just link RDS and S3 altogether with EC2 instance. Stay tuned!

--

--

Riddhiman Adib
My Online Cafe

Postdoctoral Researcher. Tech Enthusiast. Occasional Blogger. Self-proclaimed Musician. more at: adib2149.github.io