Jan 15, 2015
After you've bought a VPS, it's time to set it up. First, you need to decide which operating system you are going to install. I chose Debian for two reasons - one because it's Linux and Linux makes for an excellent server OS in that once you set things up, it requires minimal maintenance. The other reason is that I'm very familiar with Debian based distros like Ubuntu and Linux Mint. Ubuntu was the primary OS on my laptop for years, and now Linux Mint has that position.
I could have chosen Ubuntu itself, as the 2014 release comes with 5 year support. But I wanted to play with Debian, so I chose it over Ubuntu. And even though Debian hasn't officially said that the current stable release will get long term support, their release cycle is very conservative and the releases are usually supported for a long time. It's better to install a release that is supported for a long period instead of choosing a cutting edge release which may require you to frequently upgrade your OS. Running a server should require minimal maintenance effort from you, unless playing with cutting edge stuff is your goal.
After deciding the OS, it's time to install it. Most likely your VPS provider has guides on how to do this. There are also plenty of guides available on the Internet. These are the guides I followed:
Getting Started - this information is specific to linode. Your VPS should have a similar guide.
Securing Your Server - how to create users, setup SSH keys, disable root login, setup a firewall, and installing Fail2Ban - which prevents dictionary login attacks.
Unattended upgrades - in line with our goal of having to do as little maintenance as possible, we want our server to automatically install package updates - which in a stable Debian release are mostly security updates.
Hosting a Website and installing LAMP. I only installed Apache. It is the most popular http server with a lot of features, so you may want to use that. nginx is another popular alternative which is faster than Apache, but to use Google's PageSpeed module, you have to manually build nginx from sources. I don't like having to manually build sources every time there's an update to either nginx or PageSpeed. If there are any security vulnerabilities, I'd like the OS to automatically install updates instead of me having to install them. Since the http server is the entry point for web traffic, it's important that it stays up to date.
For the database, I went with PostgreSQL as I had already used Mysql before and wanted to try PostgreSQL. Also, since I plan to use Java and not PHP, Mysql is not a requirement. The Java world, with it's emphasis on abstraction and ORM frameworks, is relatively database agnostic and gives you the freedom to chose your own database. Many PHP applications like Wordpress require Mysql.
Setting up an SFTP jail - you should use Secure FTP and never FTP to transfer files to your VPS. This guide tells you to setup a separate user to do that for security purposes.
That covers the base setup of our VPS. To run Java web applications, we are going to need Java and a web server like Tomcat. I'll cover that in future posts.
Jan 14, 2015
Before buying a domain you need to decide what domain name you want to use for your website. Decide on a few names beforehand as the name you want may not be available and so you will need to use an alternate name. Also decide what top level domain you want to use - like .com, .net, .io etc... After deciding on a few names, it's time to pick a domain name registrar. You can buy domains only through a registrar (Some hosting providers also sell domains).
There are a lot of domain name registrars in the market with very competitive pricing. Just shop around, and read a few reviews. Registrars who have poor service will usually have negative reviews. It's by searching on the Internet and reading reviews did I decide on using Hover as my domain registrar. Another option is to ask someone who you know who owns a domain name. And be wary of supercheap pricing. As it is, domains don't cost much and if you are only buying one or two of them, paying an extra $2-$5 an year doesn't really matter. The level of service tends to be proportional to the pricing.
Why buy a Virtual Private Server (VPS)
Before asking which VPS hosting service to use, is using a VPS worth it? Depending on your needs, it may not be. If you just want a simple site where you don't expect much traffic, you can go for shared hosting which is cheaper than buying a VPS.
But if you want complete control over your site and how it runs, or simply like playing around with a server, a VPS is your option. In my case, in addition to both those reasons, I also wanted to run a site using Java. There are very few shared hosting providers who host Java web applications. The majority of them concentrate solely on hosting PHP applications.
A caveat though - maintaining a VPS is serious work. You have to do everything yourself - install an operating system, install and configure a web server and a database, and the software for your site. And even if you have that technical know how, you may not really have the time to do all that. So consider that before buying a VPS. Shared hosting starts at $4-$5 a month (some even throw in the cost of domain registration in their price plans), whereas a VPS starts at $8-$10 a month. If you aren't going to fully utilize a VPS, there's no point in paying the extra money.
Choosing a VPS provider is a tad harder than chosing a domain registrar. A VPS costs more than a domain so you want to be sure that the money is well spent. Know that most personal websites/blogs don't need much hardware power. So don't be tempted to pay for more RAM or CPU. Disk space depends on whether you plan to use it for backing up your data. If you aren't going to, don't bother paying for all that extra disk space. A lean Linux install weighs in like 2-3 GB, with the web server, database and other softwares installed. And blogs with hundreds of posts and thousands to comments don't take up more than hundreds of MB of database space (unless your site is heavy on photos or video). So even a 20 GB hard disk space is plenty.
Jan 14, 2015
These series of posts document the steps I took to host this blog on my own Virtual Private Server (VPS). I'll keep updating this post as and when I make new posts on this topic.