Keith Cirkel

JavaScript Cyber Shepherd

Swapping out your LAMP stack

The LAMP stack is the backbone of the web these days - every hosting provider uses it, sometimes exclusively. Many think their only other option is a WIMA (Windows, ISS, MSSQL, ASP) but in fact there are a whole wealth of options to choose from. When you have the freedom to pick your own server environment, should you move away from LAMP? It’s certainly a tried and tested platform, many of the top websites of the world use it - but why? How can it be improved? Well, you might be surprised to find out the different choices you have available…

L is for Linux

I love Linux. 3 of my 5 machines at home run it. It runs on my home server. I use it every day - I’ve used it to set people up with countless web sites. Linux is certainly a strong platform for your server stack. For me, Windows isn’t even an option. I’ve used Windows, but for me, Linux wins. The majority of Linux servers run on the CentOS distribution - a great distro, built on the shoulders of RedHat. I think today, however, there emerge some stronger platforms:

Ubuntu Server Edition (Linux)

Ok, ok. Ubuntu is a Linux distribution just like CentOS, so what gives right? Ubuntu Desktop is the Linux desktop, the forums swell with avid users helping each other out, Ubuntu has one of the strongest communities going. That is a good base for a server platform. Unfortunately the server platform receives the same stigma as the desktop platform - “Ubuntu is for noobs”, “Ubuntu is not a proper distribution” etc. Ubuntu’s server platform is pretty amazing though. Ubuntu’s package management; APT is a strong contender for Yum (CentOS package manager), and in my opinion beats it hands down. Ubuntu Server Edition also has a strong selection of “automagic” packages through tasksel; things like “lamp-stack” which will get you serving for web in under 2 minutes. Sure CentOS has groupinstall but I feel tasksel has more going for it, especially with APT in tow. Combine this with the use of PPAs (Personal Package Archives) (ok, they aren’t recommended for mission critical operations, but useful still) and you’ve got a powerful system which you’ll rarely have to compile source under. Ubuntu Server Edition also includes Landscape as an option which, for enterprise – especially on the Cloud, is a fantastic management platform. Also Ubuntu provides their EUC “Cloud Edition” installers, which are tailored for services like Amazon EC2. Yes indeed, Ubuntu is shaping up to be an amazing server platform which seriously gives CentOS a run for its money.

OpenSolaris (Sun Solaris)

OpenSolaris would be a definite contender for those performance-oriented administrators. OpenSolaris runs a lot of the FOSS tools you’re used to; PHP, Apache, MySQL - it’s all there. Where OpenSolaris is different, is in its architecture. OpenSolaris includes the much talked about ZFS (Zettabyte File System), which is purported to be blazingly fast and maintained free. OpenSolaris also provides a very strong platform for Virtualisation, with extremely strong tools such as Sun’s own VirtualBox, Crossbow and Xen Hypervisor. All this, and more; with Ian Murdock (Debian founder, of which many systems are based) leading the way for OpenSolaris, you know it’s gotta be good.

A is for Apache

Apache is the defacto HTTPD (HyperText Transfer Daemon), and it’s no surprise; Apache is mature, cross platform, stable and has been maintained regularly for way over a decade. It serves over 50% of the web. Being as long in the tooth as it is, though, many alternatives have cropped up which, in their own ways, show Apache to be an outdated platform - one that you should consider switching from.

Lighttpd (Linux, Windows, Solaris) - BSD License

Lighttpd (apparently pronounced “Lighty”) was created around the idea that a server should withstand 10,000 simultaneous connections, also known as the C10K Problem. That should give you an idea of where Lighttpd exceeds over Apache. Lighttpd’s site claims the likes of Youtube, Wikipedia and Meebo are all powered by the little-server-than-can (although Netcraft seems to differ). It does seem to be, however, a fan favourite of trackers all over (see PirateBay, Mininova, IsoHunt). It has risen in popularity to the point where it has emerged out of Netcraft’s “other” category in their web server statistics, even if only by a little. Unfortunately, where lighttpd fails is its configuration. I have used lighttpd a few times, and compared to Apache, it is a fair amount harder to configure (or atleast, significantly different for Apache die-hards to have difficulty), and the documentation is sparse. But hey, if its good enough for The Pirate Bay, right?

NginX (Linux, Windows, Solaris) - BSD License

NginX (pronounced Engine-X) is more of a bare-bones server. It is another server, built around the C10K Problem. It doesn’t come with the great configuration options that Apache and Lighttpd do, but it is fast. And much more popular than lighttpd (8% vs 0.35%). I haven’t used NginX enough to give you my opinion on it, but some pretty large websites use it, including Wordpress.com, GitHub and FastMail.fm. Also pretty compelling are its testimonials, which say more for it than I can.

Cherokee (Linux, Windows, Solaris) - GPL 2 License

Cherokee is shaping up to be my personal favourite for web servers. It’s as fast, if not faster than Lighttpd and Nginx, once again, another “C10k server”. But the real killer feature for Cherokee is the web-based admin panel, and associated wizards. Now I’ve got to say I’ve set up many a Wordpress install before using Apache, and it is pretty quick to get off the ground. In Cherokee, however, you can do it in under a minute, using the in built Wordpress wizard. Same goes for PHP support, Django, Ruby, you name it! Cherokee’s web interface gives you super fast access to all of these features, without you digging around conf files and killing your server because you typo’d “AllowOverrride”. If you want some big names that use Cherokee? Well, there aren’t any… but that should not stop you using it!

M is for MySQL

MySQL has had a turbulent life. It was acquired by Sun not so long ago, some took this badly, and many speculated on the outcome of MySQL. Recently, Sun was acquired by Oracle, which has only refuelled the speculation. Around the time Sun acquired it, a few engineers released open source alternatives; MariaDB, and the depressingly named Drizzle. There are, however, other efforts to improve on database utility, including moving out of RDBMS altogether…

PostgreSQL (Linux, Windows, Solaris) - PostgreSQL “BSD Style” License

PostgreSQL, the successor to the Ingres SQL database is an RDBMS very similar to MySQL. The biggest difference on the surface, is that PostgreSQL is a single layered engine, that is to say it has one storage engine, unified with the database driver (as opposed to MySQL which has MyISAM, InnoDB, Maria et all). Speed wise PostgreSQL’s storage is pretty much identical to MySQL’s; and is fully ACID compliant (whereas MyISAM isn’t, and InnoDB barely is). Otherwise, pretty much everything MySQL does, PostgreSQL does to: Inner & Outer Joins, Transactions, Stored Procedures, Triggers, the list goes on. There are many small differences that may or may not bother you - for example something that bugs me is the lack of TinyInt and MediumInt types. Another gripe I have with PostgreSQL: the lack of a decent admin interface. When you look at MySQL Administrator and MySQL Query Browser you see two very powerful yet very easy to use tools. PostgreSQL has pgAdmin 3 which in my opinion pales in comparison. Ultimately though, PostgreSQL is a well supported & documented standards oriented database engine, with speed pretty much identical to MySQL, with the added benefit of much looser licensing, and is used by many big names including Skype, Yahoo!, and the amazing OpenStreetMap.

MongoDB (Linux, Windows, Solaris) - AGPL 3 License

MongoDB is a product of the “NoSQL” movement, which is getting a lot of hype at the moment. Trying to keep within this article’s scope, “NoSQL” storage is pretty much dumb storage, non-ACID, non-RDBMS. In other words, what you get is a very simple storage layer that lets you look up a key, and get a value. Forget inner/outer joins, cascading, triggers, constraints - pretty much forget everything to do with SQL (Hense, NoSQL). The benefit of losing all of this, is that they are ridiculously faster than the likes of RDBMSes. Even faster than that. A rough estimate for MongoDB is that it is 15-20 times faster than MySQL/PostgreSQL. So you lose a lot with something like MongoDB, but you also gain a lot. You probably aren’t going to need the kind of performance MongoDB achieves unless you’re huge and struggling with the speed of RDBMS. But perhaps is especially cool about MongoDB in particular is that it uses JSON for resultsets, so you don’t have to waste time processing a resultset, just a quick parseJSON(); will get you a nice keyed array in PHP. Beautiful. MongoDB is pretty new - but SourceForge uses it.

Cassandra (Linux, Solaris) - Apache 2.0 License

Cassandra is a different beast to MongoDB, but still fits within the “NoSQL” bracket. It was written by Facebook to replace the relational database they use, inspired by Amazon’s Dynamo. Cassandra is designed to run on a cluster, which is where it’s strength lies. Cassandra is pretty much the poster boy for the NoSQL movement, with massive sites such as Digg, Reddit, Facebook, Twitter - basically every site that takes an unfathomable amount of data in and out daily. An important thing to think about here - many of these sites are still using an RDBMS, and Cassandra has not been a complete replacement for them.

P is for PHP

PHP is the double-sided coin of web development. A lot of hatred for PHP floats around, some of it justified. Parts of PHP are a huge mess, for example the whole haystack-needle-needle-haystack thing and the huge delays with PHP 6, not to mention the convoluted politics with the core developers. However, PHP is still the single most widely used server side scripting language. Period. Couple PHP with excellent frameworks such as CodeIgniter, CakePHP, Symfony, or just look at great projects like Wordpress, Drupal and ExpressionEngine, and the problems seemingly slip away. However, there are some really interesting languages that might just surprise you…

Ruby - GPL License

Ruby is a Strong Object Oriented (Strong, as opposed to PHP’s Weak Object Oriented model) language created in Japan, inspired in some part by Perl. Ruby’s main reason for success on the web is 37SignalsRuby On Rails project - a framework not too dissimilar to CakePHP (CakePHP started out as a “Rails” clone). Ruby is certainly faster than PHP, and nicer looking (which I feel is important, case in point). In fact, there isn’t much to dislike about Rails, or Ruby for that matter. But then you’ve not met Python!

Python - Python License (GPL Compatible)

Python is a mature and beautiful language, successor to ABC (a BASIC alternative). Don’t let it’s background fool you though - Python is nothing like BASIC. Python has a massive library of… well, libraries, an interactive shell, can be compiled or interpreted, is great on the web and on the desktop (a lot of great Gnome/Ubuntu applications are written in the Python language). Like Ruby, the code is very clean (perhaps cleaner). Python has two strong pillars of web-frameworks: Django and TurboGears. This post is pretty long already, and so I’m not going to go in depth about Python - but let’s just say after 8 years of PHP I’m about ready to jump into Python. Also, if you have a Linux or Mac OSX machine, you already have Python installed! And if you’re interested in moving away from PHP to Python, check out this site__ for some great migration tips__!

Javascript - No License?

I bet you were pretty surprised when you read Javascript right? There’s a lot of discussion about using Javascript on the server side, also known as SSJS. This idea isn’t new, but thanks to new Javascript engines like Rhino, SpiderMonkey and V8 it becomes a viable choice. Javascript itself is a mature, well formed language, which once again has a Strong Object Oriented approach. There is one huge benefit of using JS server side: your developers (or you!) can write in one language. If your developers work in both backend and frontend this can be quite a good idea. The big downside is that SSJS, despite its age is really not very mature, many like Node.JS (which runs the awesome V8 engine) run standalone servers, which becomes a problem of scalability & flexibility. Others such as JSEXT are very promising, but for mission critical applications don’t have enough evidence to justify to your boss or client.

Bonus: Google App Engine

Google’s App Engine (GAE) is a free hosted environment for your application or service. It uses Google’s proprietary web serves such as it’s GWS web server, and it’s BigTable NoSQL datastore. You can code your apps in both Java and Python, but some bright sparks have gotten PHP to work through Java, which means you can install Wordpress on GAE! There are some downsides to GAE, especially considering it is built around proprietary web services, portability is a huge issue. But it is a worthy consideration, especially when bootstrapping a startup company, or if looking for a cheaper service than Amazon EC2.

What is right for you

Ultimately you’ll have to pick what is right for you. Many hobbyists chose the ULPPy (Ubuntu, Lighttpd, PostgreSQL and Python) stack. If you’re deploying a large scale application, you’ll most likely extend the LAMP stack with tools like NginX and Cassandra, so uh… LANCMP. The “in” side of web development are using UNMR (Ubuntu, NginX, MongoDB and Rails). Perhaps the best combinations are the hardest to make acronyms out of? Personally, I’ve become pretty sold with UCPPy (Ubuntu, Cherokee, PostgreSQL, Python), and over the coming weeks will be converting my home server to this setup, as I continue to dive into python. But that’s another story…

Thoughts? Chat to me, @keithamus on Twitter