Amazon AWS EC2 LAMP Quickstart Guide – 5 steps in 10 minutes

We’ve heard some people are having a few small issues with getting AWS up and running. I’ve whipped up a quick guide to get you up and running, for FREE, on AWS within a few minutes. Let’s get started.

1.) Sign Up with Amazon AWS

First you need to get signed up on Amazon in order to use their accounts. Head on over to http://aws.amazon.com/ to create an account. Creating an account is 100% free, even though they do ask for your credit card. Click on the ‘Get started for free’ button in the middle of the page. From there you’ll be taken through a quick registration.

2.) Launch Your Instance

There are are tons of different instances you can choose from.  For this tutorial we’ll just give you a simple Ubuntu 12 image.  Click https://console.aws.amazon.com/ec2/home?region=us-east-1#launchAmi=ami-3bec7952 this will take you to the launch instance screen:
choose-instance
Click on “Continue”.  On this screen for now just make sure that the Instance type (top right of screen) is “T1 Micro…”.  This is their free tier.  You get 720 hours of run time for free on it.  The other options on this screen allow you to customize the number of instances and their location, but for now just click “Continue”.
Selection_002This screen is the advanced options screen where you can select some extra options such as the kernel and monitoring for the instance.  The defaults here are fine, so just click “Continue”.
Selection_003This screen will let you configure the storage for your instance, again the defaults are fine just click “Continue”.
Selection_004This screen you can put different tags on your instance.  If you have a ton of instances it can be helpful to tag them, however as this is your first and only instance, no need to do anything other than click “Continue”.
Selection_005

This screen is important.  You are going to setup your SSH keys to access the server here.  Amazon does not launch the server with passwords, instead is uses https://wiki.archlinux.org/index.php/SSH_KeysSSH Keys.  These let you identify with the server without having to specify a password.  Read up on them, their really helpful.

You’ll want to click “Create a new Key Pair”.  Amazon does not currently let you upload your own public ssh key, you must use one stored on your account.”     Enter whatever name you want for the pair and click “Create & Download your Key Pair”.  This will download a file to your computer.

Selection_006

You’ll be automatically advanced to the next screen when is has downloaded.   Here you’ll configure which security group you want the server to be in.  A security group is pretty much just a set of firewall settings. Use the “default” group.  Click “Continue.”
Selection_007

It’ll allow you to review your settings and you can click “Launch”
Selection_008

3.) Connecting to your Instance

Your instance is now being launched.  You’ll see a “pending” on the screen under state until it is fully up and running.
Selection_009
Once it is running the state will change to “running”.  Click on the server.  At the bottom of the screen you’ll see information about the server.  At the top of it under the top line “EC2 Instance ….” there is a  URL.  This is your servers public DNS record.  You’ll use this to connect.
Selection_010Before you can connect to your server you need to update your default security group to allow SSH.  On the left side of the window click on “Security Groups”.   Click default.  In the bottom pane click “Inbound”.  Select “SSH” in the dropdown for “Create a new rule:”.  Click the “Add rule” button.  Then do the same but for “HTTP”.  At this point click “Apply Rule Changes”.  If you do not do this, it will NOT save your updates.
Selection_012Now open your terminal.  Navigate to where you downloaded the file from earlier. Now it is time to SSH into your server.  You may encounter a permission error, if you do run the chmod command from the gist below.
Congratulations, you’re now on your own server!

4.) Installing the Basics

Now that you are on your server you need to install the LAMP stack.  The next steps we’ll do is have you become the super user, run apt-get and install the LAMP software.  apt-get is a package/software manager.

5.) View Your LAMP Server

You’ve now setup MySQL, Apache2, and PHP.  You can verify Apache is running by going to your public DNS in your browser.  You should see the following screen.
Selection_013

Congratulations!

You now have a fully functional LAMP web server.  To modify the files that are being served you’ll need to go to the webroot on the filesystem at “/var/www”.

Don’t forget to turn your instance off, as once your free tier runs out they will charge you.  When you turn off your instance you will not be able to recover anything on it, so make sure if you have any files you want to keep you download them first.

Congrats on launching a LAMP server on AWS.  Good luck and let us know if we can help you out on AWS or your next project!

Want to learn how to do other things on AWS?  Leave us a comment and we’ll do our best to help out!

Symfony2 and Ordering of Relations and Collection Form Fields

Recently I was working on a project where I kept finding myself ordering a relation over and over by other than something than ID order (ie id= 1,2,3,4,5). For example, I always wanted my relation to be ordered by the ‘name’ field, rather than the ID or order it was inserted into the DB. Let’s take this schema as an example:

The issue is each time I attempted:

I wanted the output to be in alphabetical order for example. To make this the default for that relation you can add the following annotation to your ‘Post’ entity:

Now if you do “$post->getPostAttachments()” they’ll be automatically in order. The ‘@ORM\OrderBy’ column takes care of the ordering automatically. You can specify as many columns on the relation as you’d like there. In addition, this will make it so that all form collections on post with post_attachments are also ordered by name, rather than ID. This affects the relation call every time. If you are only looking into having it some of the time, look into using the repository to do the ordering for those calls.

Behat and Symfony2 – A Simple Gotcha

Recently we were using Behat on a new project with the Symfony2 extension. It took a bit to get it up and running correctly as the docs (for the extension setup) seem to be incorrect. First place the behat.yml directly in the project root. Second, when using the “@” notation to reference your bundle you need to be sure to enclose it in quotes. For example, ‘bin/behat –init “@MyBundle”‘. Without the quotes it will not be parsed correctly and will not setup the structure as you want.

If you are running into the following error:

Most likely the initial setup didn’t go correctly. We kept having that issue whenever we added the behat.yml to our root directory, but then didn’t use the quotes to enclose the @MyBundle. Hopefully this saves you the headache!

I’ve shot over a pull request to the main behat repo for the extension so it hopefully will be fixed soon:

Happy testing!

Custom Templates with jQuery File Upload

Recently I was working on a project which was using the jQuery File Upload Plugin to do multiple file uploads. I needed to show the progress of each upload (in this case just images). Looking through their documentation it shows how to a few ways to do custom templates. By default it uses the Javascript Templates Engine for all of its templating. I wanted to use just a div on the page for my template. Here’s how I ended up doing it.

First My basic markup for the html:

Basically my “#template” div was a hidden div on the page which I used as the photo being uploaded. Now for the javascript:

It ended up being pretty simple and self explanatory. The ‘progress’ function is called each time there is a progress update. You can do more advanced templates using their templating engine, however as I was adapting the code to an existing layout and was on a time constraint this was the route I took.

Hope this saves you sometime if you are looking to just quickly add a progress template for the uploaded images.

Gmail Reporting Tons of Used Space? This may help!

Recently I had to upgrade my Gmail account for additional storage. I was nearing the 8 free gigs of data they give you and didn’t want to keep seeing the big red “Buy more storage!”. I bought the $5/year 20 gig plan. A few weeks later I noticed that my Gmail was now reporting i was already using ~18 gigs of my total 30 gigs of data. I couldn’t believe it, how did I manage to more than double my used Gmail space within 2 weeks? I had used Gmail for 8 years to get to 7 gigs of data.

After looking around there didn’t seem to be anyone who could report the problem, nevertheless have a fix. I then tried to empty my Trash, which at the time said ~200 messages. As soon as I emptied it my used space dropped to 7.3 gigs, which is what I expected.

Long story short, it would appear that Gmail has a bug in reporting the number of actual messages in the trash, or doesn’t truly ’empty’ it unless click it. If you think you are using much less space than it is reporting, try emptying your trash manually. It worked for me and a number of other guys in the company.