Laura Diane Hamilton

Technical Product Manager at Groupon

Resumé

How to Set Up a Hacker News Clone on AWS

The code that runs Hacker News is open source, so it's easy to build a similar site for a different vertical—or even for internal use within your company.

The hard part, of course, is building a community for your site.

First, launch a new AWS instance. I used a Micro instance running Ubuntu 13.10, but any of the Linux instances should work.

Ensure that your security group allows access via port 22 (SSH) from your ip address. (Do NOT allow SSH access to 0.0.0.0/0! This is very insecure.) Also, allow the world access to ports 80 and 8080. (Unless you are running the site for your company internally, in which case open access to your company's ip addresses.)

Now, you'll need an ip address ("Elastic IP") for your instance. In the "Elastic IPs" menu, click "Allocate New Address." Then Associate the new address with your AWS instance. If you don't set up an elastic ip for your instance, then your ip address will change every time you reboot the server. Warning: Elastic IPs incur additional charges.

Next, ssh onto your instance. ssh -i ~/.ssh/your_ssh_key.pem ubuntu@ec2-XX-XXX-XXX-XX.compute-1.amazonaws.com

Update the software. sudo apt-get update sudo apt-get upgrade

Install the necessary packages. sudo apt-get install git sudo apt-get install racket racket -v You should get a message that says "Welcome to Racket v5.3.4" (or a later version, depending on when you are reading this tutorial).

Now, in order to allow requests on the standard HTTP port, 80, let's set up some port forwarding. First, run this command to see if you have ip forwarding enabled already: cat /proc/sys/net/ipv4/ip_forward

If it returns 0, then ip forwarding is disabled. A 1 means it's enabled. sudo vim /etc/sysctl.conf In this file, uncomment this line: net.ipv4.ip_forward This will enable ip forwarding. Then, to enable the changes made in sysctl.conf: sudo sysctl -p /etc/sysctl.conf Now, let's check that ip forwarding is enabled: cat /proc/sys/net/ipv4/ip_forward That should return a 1 now.

Now, let's set up forwarding from 80 to 8080: sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

Next, we need to open the Linux firewall to allow connections on port 80: sudo iptables -A INPUT -p tcp -m tcp --sport 80 -j ACCEPT sudo iptables -A OUTPUT -p tcp -m tcp --dport 80 -j ACCEPT

Now install arc and run news. git clone http://github.com/arclanguage/anarki cd anarki bash arc.sh (load "lib/news.arc") (nsv)

Now think of a username for yourself and add it to the admins file. cd arc echo “yourusername” > arc/admins

Now, if you go to your public IP address (found in your AWS console) on port 80, you should see your new Hacker News clone.

If you have problems connecting, see if you can connect via port 8080. If you can connect via port 8080 but not port 80, then your ip address forwarding from 80 to 8080 is not working properly.

On your new site, create an account for yourself with the username that you just made an admin.

Now, manually give yourself some karma. At least 10 karma points. (You can give yourself as much as you want.)

Assuming you want your server to keep running when you close your terminal window, you'll want to close your current arc process and then start a new one using screen. screen mzscheme -f as.scm (load "lib/news.arc") (nsv) Now press CTRL+a d to detach the screen. Check in your browser that the website is still running.

Now you're all set! Enjoy.

You can take a look at my healthtech hacker news clone here. Please sign up and submit your favorite healthtech news stories!

Lauradhamilton.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com.