This is my first post and I’m very excited!
I decided to write this post to help people who wish to have a free public server running linux with a working MEAN stack.

All you need is a credit card to start an AWS account.

AWS activation – Amazon subscription

  1. Go to Amazon AWS website
  2. Click on Get started for free and follow the steps to create a new account or use your amazon account if you already have one
  3. Just follow the steps to get your amazon aws account, you need to type your credit card info to complete subscription
  4. Once signed up, be sure to stay on the EC2 dashboard, you can surf by the Service menu

EC2 configuration – Let’s tune things up to get our server working

  1. Choose your favorite server location from the dropdown menu on the top-right of the page, near HELP and your account name
  2. Go to NETWORK & SECURITY > Key Pairs from the side menu, click on Create Key Pair button, type a name for you key-pair like "KeyPair1" and confirm
  3. Now your browser should download your <choosen_name>.pem key-pair file, keep it on a safe place on your computer, because you will not be able to download it again
  4. Go to NETWORK & SECURITY > Network Interfaces from the side menu, click on Create Network Interface button, type a description, choose a subnet and confirm
  5. Go to INSTANCES > Instances from the side menu, click on Launch Instance button, select Quick Launch Wizard, type a name, choose your favorite Linux Flavour (I use Ubuntu on the rest of the article), click Continue, Launch and at last Close Buttons
  6. Look at the assigned Security Group of your instance and keep it in your mind for a while
  7. Go to NETWORK & SECURITY > Security Groups, click on the security group used by your instance (I told you to keep it in mind) and then click on the Inbound tab from the bottom pane
  8. Now just select services you want your server will listen to, or curstomize a new one, and click Add Rule. If you are not sure, just select HTTP, press Add Rule button then Apply Rule Changes buttons
  9. This is the time for a static IP, wich Amazon calls Elastic IP, reach its panel from NETWORK & SECURITY > Elastic IPs
  10. Click on the Allocate New Address button, then just select your Instance from the drop-down list,thick Allow Reassociation and hit Yes, Associate button
  11. Once your configuration is complete, take note of your new assigned Elastic IP or copy it on the clipboard
  • If you get a Network Interface error while creating your Instance, try to click Edit Details Button on the second screen and then confirm and continue to follow the other steps

Server connection – Let’s ssh to your EC2 Instance

  • Ubuntu / Linux Mint / MacOSX

    1. Move your key-pair file in ~/.ssh folder
    2. Change rights of your .pem file for security reasons using chmod 600
    3. Add your key-pair file to the system keyring with ssh-add
    4. Launch terminal from the same folder where you stored your .pem key-pair file and issue the following, changing your-key-pair-file-name.pem with real name of your Keypair file:
      • Ubuntu:
      • MacOSX:
    5. Just run the following to ssh your EC2 Instance, replacing your-elastic-ip with your Instance real elastic IP:
    6. Answer yes to confirm that you can trust the connection
  • Windows

    1. Let’s download PuTTY installer from the official web site
    2. Launch the PuTTY setup, the only needed components are PuTTY and PuTTYgen
    3. Once you get PuTTY installed on your system, you need to convert the pem file, so launch PuttYgen and click the Load button
    4. A window should appear, switch the file type to All files (*.*), select your your-key-pair-file-name.pem and confirm
    5. Say OK if a message appear and click on the Save Private Key button, click Yes and type a name for your-key-pair-file-name.ppk
    6. Create a new shortcut of PuTTY on your desktop, rename it as My EC2 Server or whatever you like more, right click on it and open its Properties
    7. Append to the Target field a space and the following text: -i your-key-pair-file-name.ppk ubuntu@your-elastic-ip
    8. Clear the Start in fields and type into it the path where you stored you your-key-pair-file-name.ppk
    9. If a question appear, click yes to confirm that you can trust the connection
  • You can store the ssh command on a text plain file as a shell script to make it easier (Linux / MacOSX)
  • If you get an error, be sure to have chmod-ed your .pem file or try a different username like root or ec2-user instead of ubuntu
  • You can add an A record with the assigned Elastic IP on your DNS config panel, if you own a domain name, to reach your instance with something like myec2.example.com

Update & Fix – Place your doormat on the server

  1. Once you get connected to the server,update your linux-box and fix Perl local issues performing the following code:
  2. Answer Yes to any question to perform updates.

Installing MEAN – Ubuntu

  • MongoDB

    1. Import the official MongoDB public GPG Key
    2. Add official MongoDB repo to your server source list
    3. Update system dependencies and install official 10gen latest MongoDB stable release
    4. The mongodb service automatically starts once installed

    Just copy-past the following code on your terminal to have your MongoDB up and running in just few seconds!

  • NodeJS

    1. Add unofficial nodejs ppa to your server source list
    2. Update and install latest NodeJS stable release

    Just copy-past the following code on your terminal to get NodeJS installed on your linux-box!

  • MEAN package

    1. Install GIT
    2. Create ftp-users group
    3. Make a folder for projects in /var/webservices and change its owner to ubuntu and the ftp-users group
    4. Download the last release of MEAN package from linnovate’s github
    5. Extraxt package content
    6. Launch npm-install to download everything you need for your MEAN to work

    Just copy-past the following code on your terminal and hit Enter to get MEAN package download,extracted and npm-installed:

Mount your EC2 Instance – Browse server files from your pc

Since you need a way to upload and manage content, you need to mount your EC2 Instance to make it easier.

  • Ubuntu / Linux Mint

    1. Open a Nemo or Nautilus windows and go to File > Connect to server menu
    2. Just type your Instance’s Elastic IP as the server, add your server’s username and select SSH from the list of available Connection Types
    • If you get some errors be sure you had added your pem Key-Pair file to system as sayd on previous steps:
  • MacOSX

    1. Download and extract into your App folder FileZilla for MacOSX (intel) from the official website
    2. Launch FileZilla, go to File > Site manager, click on New Site button and type a name for your connection like myEC2
    3. On the right pane, just type your Instance’s Elastic IP as the server, select SFTP as Server Type, select Interactive from the list of available Logon Types, fill the User field with your server username and then click Connect button
    4. A pop-up message should appear, just check Always trust this host and click OK
    • If you get some errors be sure you had added your pem Key-Pair file to system as sayd on previous steps:
  • Windows

    1. Download and Install FileZilla for windows from the official website
    2. Once FileZilla is started, go to Edit > Settings menu
    3. Watching the Settings window, select Connection > SFTP page from the left pane
    4. Click Add Key file.. button, select your-keypair-file.ppk, confirm and click OK on the Settings window
    5. Go to File > Site manager, click on New Site button and type a name for your connection like myEC2
    6. On the right pane, just type your Instance’s Elastic IP as the server, select SFTP as Server Type, select Interactive from the list of available Logon Types, fill the User field with your server username and then click Connect button
    7. A pop-up message should appear, just check Always trust this host and click OK

Init script and nginx – Node App as service and reverse Proxy (ubuntu server)

If you want that your app would run automatically with nodejs on boot and standalone, so you need to follow some steps

  1. Write an upstart script in /etc/init/nodeserver.conf
  2. Install nginx
  3. Set nginx to start automatically with update-rc.d
  4. Create a rule config file for nginx in /etc/nginx/conf.d/meanserver.conf

Questo post รจ disponibile anche in: Italian