As I blogged about a few days ago I've fallen out with my web host. This tends to happen every few years; the standard of "cheap but reliable" hosting has taken a dive. Especially in the area of customer service (I don't ask much, just that you read my support requests!).
This is a pretty lengthy post, so bear with it!And, so, I decided to switch out to another provider. Which is where it got interesting. For a few years I have run a dedicated machine next to my shared hosting - for testing, game servers and, occasionally, web hosting. It was the latter that got me thinking. I use the dedicated box to host sites with, say, background processes or limitations that mean a shared host is no use.
Why couldn't I switch to hosting all of my own sites?
So I've given it a go.
For those who like that kind of thing (so, most of you) this is how my old host (Servage) pissed me off: bad customer service.
A few weeks back a programming mistake (and, I argue, a configuration mistake on their part) locked up the shared server - so they suspended my account. Which consisted of returning a Servage suspension page and a 404 header. Oh, and they never told me (apart from a cryptic copy of a "top" output) what the issue was.
They then proceeded to not read my support requests and act like I was a criminal :) so screw 'em.
Hosting your own sites is actually pretty easy; VPS's are easy and cheap to purchase nowadays and the tools are few clicks a way. Here is my ingedient list:
- VPS's (I use Gandi; so far they have been excellent)
- DNS (DynDNS provide for my main site, more on that below, but other sites are self hosted using PowerDNS)
- A Web Server (no contest: Nginx)
The most important thing is to PLAN your approach to this; I made several mistakes with the first few sites transferred leading to annoying down time.
Hosting is the easiest part of the puzzle (and will be specific to your language choices/needs).
Most of my code is in PHP so I was after an LNMP (Linux, Nginx, MySQL, PHP) stack - guides to which are only a Google away. There are a couple of ways you can pipe Nginx into PHP but I chose the Fast CGI route in the end which is proving stable (go with what you prefer). After a little deliberation I decided to install pretty much all of
One good idea I had was to set up a sub-domain for every VPS; that way you can host Mysql and other services under that name (i.e. no need to make them available under your hosted domains).
Iit is worth setting up some form of caching with PHP (I recommend Xcache). While most of my PHP code ran fine Wordpress slowed to an absolute crawl. Xcache brought what can only be described as "astonishing" speed improvements.
Oh and if you do use Gandi you have to install sendmail manually to get mail() working (I was stumped by this for ages thinking it was a problem with PHP)
DNS was the most difficult part of the setup. In my previous setup most of my domains were registered with Fast Hosts (they still are as it happens) and Servage provided my DNS.
One major problem with self-hosted DNS is that fact that you need to register "glue" subdomains with the central repositories (this is so that DNS lookups don't go into a recursive loop of doom). After an initial play, and fail, around with Bind 9 I cast about for hosted DNS. In the end I went with DynDNS for my personal domain - it was pretty cheap ($29.99 for a year) and seems a stable service. Doing this made me a lot happier about attempting to self-host DNS for the other sites.
Bind is a pig; there I said it. Luckily I came across PowerDNS, which for me, had several advantages:
- Installation was a breeze, just a few seconds
- It is MySQL based (which fits in with some future plans)
- There is Power Admin, a drop in PHP configuration manager
Once happy I added my DNS zones, asked Fast Hosts to register ns1/ns2.errant.me.uk as Glue records and changed all the DNS records. Phew.
Side note: I wish I had explored Power DNS before buying DynDNS! It could easily have convinced me to risk the full self-host.
I suppose cost is important. For me costs went down (as I will explain) but for those with only shared hosting you may end up paying more. It's up to you but I much prefer the versatility!
My previous setup was:
- Shared Hosting with Servage: £75/year
- Dedicated Server with Fast Hosts: £960/year
Currently I have two shares with Gandi priced at £240/year. Which is a pretty substantial saving overall - though a big leap up from shared hosting costs.
On the other hand there are a lot of advantages that may make it worth it; not least that you have full access to the server to do whatever the hell you like (site deployment using Mercurial has become a dream!)
- Domains: My next plan is to administer my own domains directly. At the moment they are spread about amongst Fast Hosts, Gandi and Servage and it would be handy to consolidate those into one place. From what I can gather this is looking to be rather expensive, so perhaps for a later date. It's something I would like, though, just to be entirely self sufficient.
- DNS: soon I plan to ditch DynDNS and bring all my DNS service "in-house". That's a pretty major leap so I plan to be very ready before trying :)
- Control Panel; hand configuration of Nginx is pretty trivial if you don't have many domains (a lot of the cfgs can be reused). Plus I have Power Admin and PHPMyAdmin for DNS and MySQL maintenance. But an "all in one" method would be quite nice (particularly one that could handle domains/DNS together). None of the current control panels support Nginx very well - so it is easier to hand configure.
- Mongrel 2; an interesting project which is configured using SQLite. As soon as it becomes stable I will be testing it to sit in front of Nginx (or even directly in front of PHP) - because of the SQLite approach it should be easy to hack together a Power DNS/Mongrel based control panel.
Self hosting has been on my mind for a while, but I have always shied away from the difficulty. So I am actually pleased Servage gave me a push.
One major concern was that this makes me responsible for server maintenance - I'm not a bad sysadmin but you could hardly call me great. The positive thing is that this is proving to be less of a worry that I thought. The only serious stumbling block so far has been the caching/slowness issue with PHP; but I managed to figure that out in just a few hours.
Best of all I am learning a lot of useful stuff in the process.
Security is another major problem. I think everything is safe but I do need to remember to update software regularly (this is becoming an advantage because I can update much faster than most hosts!).
If you want to do this then I highly recommend it! But I also recommend you take it slow and do your research. I rushed the initial process (due to being mad at Servage) and made some mistakes.
By the way, yes, the blog you are reading is self hosting. I hope it coped!