Top things to do after setting up EC2 AWS server?

5 points by vtempest ↗ HN
The top three things to do after setting up ec2 server is setup a username password login and enable lamp web server as well as to assign a domain name

5 comments

[ 3.6 ms ] story [ 25.0 ms ] thread
(comment deleted)
The top three things to do after setting up ec2 server is setup a username password login and enable lamp web server as well as to assign a domain name Setup password login

Login to your EC2 via ssh

ssh -i /path/to/your/Awskey.pem ubuntu@54.84.42.20 then set

sudo adduser alex Set a password

sudo visudo Add this line

alex ALL=NOPASSWD:ALL Beneath the root ALL=(ALL):ALL line, and ctrl x to exit and enter y to save

sudo nano /etc/ssh/sshd_config Find this line and modify it to say yes

PasswordAuthentication yes Then exit and save with ctrl+x and press y to save

sudo service ssh restart Now you can login as ssh alex@54.84.42.20

Setup websites

If you've just booted your ec2 server, you will need to first update packages before you can use them

sudo apt-get update && sudo apt-get upgrade Type y when asked to install.

sudo tasksel install lamp-server Create mysql root passwords when asked

Now open permissions to your root folder

sudo chmod 777 /var/www In order to enable .htaccess on ubuntu server, type

sudo a2enmod rewrite Then type

sudo nano /etc/apache2/sites-enabled/000-default.conf or

Make these modifications, change AllowOverride to All and ErrorLog to use the /var/www root. If you can't find these here, check the /etc/apache2/apache2.conf file

AllowOverride All

ErrorLog /var/www/error.log Ctrl+X and y to save

To install phpmyadmin, type

sudo apt-get install phpmyadmin Then press space to asterisk apache2, tab and enter, then yes and set a password for the phpmyadmin to access the databases. Now accessible at siteip/phpmyadmin

In the AWS EC2 Instance console, make sure the security group assigned to your instance has under the inbound tab port 80 HTTP enabled. Only port 22 is open by default. Find out your security group name listed when you click on your instance, then go to the Security Groups link on the sidebar of ec2 and modify that security group by clicking on it, inbound tab, edit, add rule, select http. Now when you click on your ec2 instance it shows a Public DNS like this ec2-54-85-204-200.compute-1.amazonaws.com, type that into your URL bar and you should be able to see index.html located on /var/www

when you login, if you want the default directory to always be /var/www then type

sudo nano ~/.bashrc And add to the very bottom:

cd /var/www Register a domain

Go to your ec2 manager and click elastic IPs on the sidebar, Allocate a new address, then associate address and select your running instance to be associated with that address. Test it out by typing that ip address into your url box, index.html should show up.

Now go to Route 53 under the aws console dropdown and click Create Hosted Zone, name it your site's name .com, then go to record sets, create record set Type: A with the Value of the Elastic IP you got before.

Now copy the Name Server values, which look like ns-1877.awsdns-42.co.uk. ns-1149.awsdns-15.org. ns-923.awsdns-51.net. ns-216.awsdns-27.com.

Go to godaddy or 1and1 and buy a domain for $10, then under DNS management for that site domain, edit DNS servers to be custom and enter all four of those Name servers. Give it an hour for it to update redirection.

How to backup you web code on git:

cd ~/.ssh ssh-keygen -t rsa -C "yourname@example.com" vi ~/.ssh/id_rsa.pub #copy this into a new key https://github.com/settings/ssh #now create a new git repo https://github.com/new cd /var/www sudo apt-get install git git init git add * git commit -a -m "init" git remote add origin git@github.com:yourname/repo.com.git git push -u origin master

How to backup your code on git:

cd ~/.ssh

ssh-keygen -t rsa -C "yourname@example.com"

vi ~/.ssh/id_rsa.pub

#copy this into a new key https://github.com/settings/ssh

#now create a new git repo https://github.com/new

cd /var/www

sudo apt-get install git

git init

git add *

git commit -a -m "init"

git remote add origin git@github.com:yourname/repo.com.git

git push -u origin master

The super-short must-do list for any new cloud server, not just EC2:

- Add a non-root user

- Add that user to the sudo group

- Update and then upgrade all packages

- Install fail2ban

- Log out and do all future work as the non-root user