While aimlessly browsing through memes and other images of cats on reddit this past weekend, I came across a subreddit I had never seen before: redditdev. On this discovery, I realised for the first time that the reddit source code is open source, and even better, it’s written in Python! While I might have been slow to learn this fact, I was quick to test out this new found knowledge by immediately spinning up a VPS ready to deploy my own Reddit clone. This blog post is going to walk through the steps I took.
Thankfully, reddit have an easy ready-to-install script for Ubuntu 12.04. They recommend only running the installer on a fresh (non-production) copy of Ubuntu with a minimum of 4GB of RAM, so if you want to follow along, you can set up a VPS-6 or spec up a 4GB Blaze Cloud VPS with the Ubuntu 12.04 x64 template.
Once you’ve got your environment ready, SSH in as root and follow the simple installation instructions provided by reddit and summarised below.
- Download the installation script
- Make it executable
chmod +x install-reddit.sh
- Read and edit the script
The documentation on Github suggests you read through the installation script, there are various options which can be changed to suit your requirements including username, the installation directory and the domain. If you are deploying this code for production use, you may want to comb through and make any appropriate changes, for for the purposes of this article, we’ll just make the one required change, updating the host name. I updated this line to use the IP address of my VPS, you could (and probably should) use a proper domain (FQDN) if you have one available.
Change the following line:
to include your IP or host name:
Now that we’ve edited the file to reflect our environment, it’s time to run the install with the following command:
This is going to take a while as it downloads all the necessary packages and configures your VPS to run reddit, now’s a good time for a coffee break! Once you get back, you should now be able to browse to your empty but functional reddit clone by putting your domain or IP address into your browser.
If you want to install some sample data, you can run the below commands which will add some sample accounts, subreddits, links and comments. Again you may be waiting a while for the sample data to be downloaded and installed.
paster run run.ini r2/models/populatedb.py -c 'populate()'
The sample data will include an admin user called ‘reddit’ with the password ‘password’. You can update this users password by logging in to your install or if you haven’t installed the sample data, create a new user in the main web interface and give him admin permissions by editing the file ‘example.ini’ and adding the user on the ‘admins’ line.
admins = (your user here)
The final change you’ll probably want to make is updating the logo from the default reddit alien to something of your own. While the reddit source code is open, the alien is trademarked, so I’d recommend overwriting the following image.
Or alternatively, you can simply upload a new image and reference it in the following CSS file (under the #header-img tag).
Now we’re done! You can navigate to your newly installed reddit and start adding links, posts and comments to your heart’s content.