I have always hated shared hosting and I’m never going back to BlueHost, HostGator,etc because they’re always very un-reliable and the problem with shared hosting is that they’re just too crowded, also it doesn’t allow you to customize your environment, and has many limits like email sent per hour, max bandwidth, file size limit, etc.
You can use sameid.net to check how many websites are actually hosted on the same server by entering the server’s IP address on it. below what you can see is one of the servers of Hostgator. some of them even have more than 300 websites on the same server
And then I thought, what about dedicated servers? nope, They’re just too expensive. Also you don’t need 8 or 16Gigabytes of RAM & 1TB of HDD for only a tiny WordPress site
So, I moved to IaaS cloud hosting. It wasn’t so cheap neither too expensive. but it was worth the price. So, I signed up for Digitalocean and installed WordPress on a $5/month server with 512MB of RAM. And then it was okay for a few months, but then on May 2014 my site took so much of traffic (thousands of requests/second). And 512Megs of RAM wasn’t able to handle all the requests, so it always ended up with error 500(Internal Server Error)
So I quickly upgraded my server with 8GB of RAM. And then it was okay for a while. But on June 2014 I saw that the traffic went down by 90%. The server had to handle only a few requests/second. Now I have 8GB of RAM, but wasn’t using even 1GB, so it was only a waste of resources because more than 7GB of RAM was unused
After doing some research. I found ‘WPEngine’, its a managed WordPress hosting service (PaaS Cloud service) where they manage everything for you- scalability, CDN, security, updates, etc. I tried it for a month, I was very satisfied with their service, but the only problem was the price. As because for an extra 1K visitors they’d charge me $1.
So what if I get 200K visitors, so now its $200? That’s surely overpriced because I can get unlimited visitors on a Digitalocean cloud server for a lower price and finally I ended up closing my WPEngine account.
I found another PaaS service called Appfog, the price was lower than WPEngine, also I got a free 1 month trial so I tried it. but it wasn’t quite how I expected, everything was just too hard for me to manage.
- Firstly- they just give you a ruby command line tool to upload your files, no FTP or something(of course tech geeks like me can use ‘git’ but what about beginners ?)
- Second- scaling WordPress was always an issue cause it didn’t support any persistent file storage (new files on ‘/wp-content’ would get erased everytime it was scaled up or down)
- Third- when the app was scaled up or down it would end up with lots of redirection errors(maybe it was a problem with their service itself)
- Fourth- extra bandwidth was expensive
What Is Openshift ?
So now I thought ‘what if I could build my own PaaS Service like WPEngine ?’. I did a lot of research and found a opensource PaaS software called ‘Openshift origin’. Which basically allows users to host multiple scalable web applications on a distributed cluster of servers that can be scaled up or scaled down automatically whenever required.
There are three versions of openshift- Openshift Online, Openshift Origin & Openshift Enterprise. They’re basically the same code, but the ‘Openshift Online’ is the hosted version of openshift, where redhat hosts your applications on Amazon EC2. ‘Openshift Origin’ is the core project where openshift is developed, and openshift enterprise is just the tested & bug free version of Origin, for use in enterprise environments.
- You can find more info about how it works, by going here- https://www.openshift.com/walkthrough/how-it-works
- The project it up on github, you can always contribute if you’re a developer- https://github.com/openshift/origin-server
Installing OpenShift on CloudOcean
Openshift Origin can be installed on RHEL, CentOS or Fedora. But Openshift Enterprise can be installed only on RHEL.
So, Now I went back to Digitalocean and installed a small multinode openshift origin cluster on few centOS servers. The installation was quite easy, they’ve a very well documented guide on installing/configuring it. And now I had to spend only $50/month. And I can add more nodes and scale it whenever I need it without needing to reinstall anything or even remove the nodes whenever I don’t need it. And now i have many terabytes of bandwidth as well as unlimited visitors
Now I can scale up automatically whenever I get a lot of traffic or scale down automatically whenever the traffic comes down.
And guess what ? Now I can even install many more web applications, WordPress sites, laravel PHP apps, nodeJS apps, ruby on rails apps, python djnago apps, etc, etc
And I can even add my own configurations and dependencies. And it can even be accessed via SFTP
Solving A Major Problem : WordPress and hosting Chaos!
Okay that’s great but are we forgetting something ? yeah that’s one of the major problems why WordPress cannot be scaled. So what’s the problem ?
The problem is non-persistent file storage. Have a look a /wp-content folder, whenever you upload a file, it will be stored on /wp-content/uploads.
So lets assume that you’ve installed wordpress on openshift gear1. And suddenly the traffic went so high. Now what will happen is- openshift will automatically scale it by copying the wordpress script to the new gear(gear2) and then another gear(gear3). So now you basically have 3 virtual servers running your wordpress site(gear1,gear2,gear3), load balanced using HAProxy. So now lets say now you’re logged in to WordPress admin on gear3 (HAproxy will route you randomly to any available gear) and you’ve uploaded a new photo, and it’s stored on /wp-content/uploads, suddenly the traffic decreased. Now openshift will scale down it down automatically to 1gear. And now the photo you’ve uploaded on /wp-content is gone. Why ? because when you uploaded it, it was stored on gear3, and now it has scaled down to only 1 gear(i.e gear1) but gear2 & gear3 are now deleted.
So how to solve it ? there’s a very easy way to solve this problem, i.e to use an external storage platform like amazon s3(Which is very cheap, and also you get a 1 year free tier when you sign up)
- There’s a free plugin here that does it- https://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront
- and you can sign up for amazon s3 here(requires a valid credit card)- http://aws.amazon.com/free
Testing Your server load
After a while I tested whether if it can really handle lots of requests by creating a script that consumes a lot of RAM & CPU, it was basically a script that calculates the value of pi to a few thousand decimal places, and it also had 2 images on it(more than 1 Megabyte in total) the single page had only 3 requests in total. but the test was successful, it was able to handle more than 1900 requests per second without any single error.
You can view the entire test result here – http://loadimpact.com/load-test/test-cloud.zanswers.com-a040d8e6793712a1ca901c36b734a886
now I host all of my web applications & sites on my openshift cluster. and now I don’t have to worry about scalability issues as long as the application is scalable.
Since I’m a web developer, scalability was a very major problem that i faced in the past years, now I have learned how to build scalable applications to fit scalable environments so now i only build applications that are very easy to scale , and i even advise many of my friends to build applications that scales easily unlike WordPress(which is very hard to scale). If you’re looking for a more scalable blogging platform you can go for Mongopress, Gho.st,etc which can too be installed on openshift
That’s quite okay for now, it can handle a few thousand requests/second but there are still some works need to be done such as caching, database replication, etc. but that’s quite some complicated & geeky stuffs. So I’ll post it in my upcoming posts if i receive any good responses.
And as always thank you for reading such a long post.