Apr 9, 2010

Ubuntu for Web Development, Revisited

I was reading a post I made a couple years ago, it strikes me as amazing how much I've learned and changed in those years! So I'm revisiting this post with the way that I see things now.

The question is, "Can you use Ubuntu for web development?" The answer is yes, since that's what I've been using since I left Mansef in the summer of 2008. I've discovered it works really well, since everything is right there for you. It is quick and easy to set everything up, and there are a number of great tools available for you to use for coding.

A quick disclaimer before I get too into this, I am not trying to say that Ubuntu is better than other platforms for web development, I'm saying that if you want to use Ubuntu for development then it is quite possible and you're not really going to hurt yourself by trying - except for maybe the little hiccups in the beginning when you're still getting used to the system, but this is true for any software.

I'll talk about various different platforms:
  • Java/JVM Languages - I haven't really done any Java development under Ubuntu, so I can't really give a good answer about it. I've done a fair bit of JRuby which uses a lot of the same tools and software, but they aren't all the same. Anyway I'm assuming that since Java stuff is all cross-platform, you can use all the same tools that you're used to using. Eclipse and Netbeans work fine under Linux, as do servers like Tomcat and Glassfish.
  • Ruby - I don't really need to say much here, since most Ruby developers seem to view Linux as a suitable development platform anyway. From my experience with Ruby development you usually just use a text editor and a command line for everything, which Linux is ideal at. The only reason not to use it is if you're married to Textmate.
  • Others - I'm not too well versed with other development like with .NET or Python, so I can't really give a good analysis here. I'm going to assume that if you're using .NET then you're pretty screwed with anything that isn't Windows, although Mono seems to be doing fairly well. As for Python I can't think of any reason why using Ubuntu would be bad, but since I haven't done too much Python I can't really say. Maybe if there is a Python expert in the audience they can shed some light on this one.
The big one I want to talk about is PHP, mainly due to it's popularity and also because it's the one web language that I've worked with extensively under both Windows and Ubuntu. So let's dive in!

Setup


Setting up PHP under Windows is a pain. Where I worked we used a Linux server and mounted a network share as our dev drive. This is not a bad solution, however to me it seems a bit inefficient to have to use another computer to do your development when you can just do it all on your own machine. This gets even more problematic when you don't have admin rights to the dev server and can't fiddle with things (this gets really bad when files/folders are owned by www-data, so you can't modify them without executing some PHP code from the server).
If you want to install everything on your own computer, you have to go out and download all the software manually and install it. I'm not sure how much configuring you have to do for this either, but it is still a pain.
After a bit of research I discovered PHP Triad, which supposedly solves a lot of these problems. I'll have to check this out later on.

Setting up PHP under Ubuntu on the other hand is trivial. From a terminal (you can also install these via System->Administration->Synaptic Package Manager, it's just usually faster to use a terminal) you can just do:
sudo apt-get install apache2 php5 mysql-server php5-mysql
This will install the web server, PHP, and the DB server; it will also come pre-configured for Ubuntu so that you don't really have to tinker with anything. If you go to your browser after doing this and browse to http://localhost/, you should see something that says "It works!" This means that Apache is installed properly. Now you can do everything you need to do without worrying about network shares or any of that. The nice thing about this is that you don't have to worry about the network going down, permissions, other people messing with your stuff, etc.
The default folder for Apache is /var/www. Typically what I do since I'm usually working on different sites is make sub-folders in here for each project and then give myself write access to them:
sudo mkdir /var/www/my_project
sudo chown rob:rob /var/www/my_project
You would then access this project by going to http://localhost/my_project. Make sure to use your username instead of "rob".

Tools


Of course, the system wouldn't be very good without any development tools. Let's talk about a few of these:
  • IDEs/Text Editors - I've found that there are plenty more IDEs available for Windows than for Ubuntu. I've used Dreamweaver and PhpEd under Windows, and Quanta Plus for Linux. Of these, PhpEd is by far the best since it is an actual PHP editor rather than an HTML-editor-turned-PHP-editor and it comes with nice things for profiling and debugging. On the other hand it is not free in any sense of the word, so be prepared to shell out some cash if you want it.
    Ones that I haven't tried include PHP Triad which is Windows only, Bluefish which is Linux only, and Eclipse and Netbeans which are cross-platform.
    From this you'd say that Windows has the better editors, and I'm not sure if I'll argue against that - although if you're one of those folks who swear by Eclipse or Netbeans (and there are a lot of them out there!), then you're really not constrained by the operating system.
    These days though, I do all my development using Vim. I'd argue that it is important to know how to use Vim at least a basic level, since so many of the *nix/BSD servers out there might only have Vim installed on them - although once I used a Linux server that had pico as the only editor installed, which was odd.
    Since this is an article about the merits of Ubuntu, not Vim, I'll save the Vim argument for another day. However since it (and its popular alternative, Emacs) are available for most desktop operating systems, there isn't really a reason to use one OS over another.
    So who wins here? I'd say Windows if you're in love with a specific Windows-only editor, however if you're willing to learn something else then there are plenty of good programs available in Ubuntu.
  • Databases - Most PHP apps use some kind of database, whether it is MySQL, PostgreSQL, etc. If you're using a database that doesn't work under Linux (like MS SQL) then you're probably better off not using Ubuntu, but pretty much everything else will work fine. If you're using MySQL or PostgreSQL it is nice and easy to install phpmyadmin or phppgadmin via Synaptic or apt-get to give you a database interface that is slightly easier to use than the command line. Who wins here? Nobody really, since databases other than MS SQL are available for most operating systems.
  • Command-line Tools - Here is where Linux wins. I know many people hate the command line (I used to as well) because it has a steeper learning curve and/or feels archaic, but it is an extremely efficient way to get things done sometimes. When you couple it with simple tools like grep, or bash scripting, or with specific programs like ffmpeg/mencoder/ImageMagick you can get your PHP app to do a lot of interesting things.
Anyway in conclusion I feel that Ubuntu is quite well suited to web development in most languages - the exception being any Microsoft languages. You have a large variety of tools available to you (probably not quite as large as with Windows, but the nice thing about Linux tools is they're usually free) many of which are well proven in the market. There is a bit of a learning curve to Ubuntu if you've never used it before (although I think that if you're reading this blog, chances are you know your way around Ubuntu) and that might deter a few folks, but if you're wanting to use Ubuntu for web development then you can go for it and you're not putting yourself at a disadvantage.

3 comments:

Blues said...

The only problem that I have with Ubuntu as a web development platform is font rendering. If you move from a mac to ubuntu, you'll go through a phase of repulsion every time you see your webpage rendered.

Python works well on ubuntu.

Rob Britton said...

Heh yes, Mac folks love their fonts. Fortunately you can install the Mac fonts on Ubuntu: http://www.ubuntu-unleashed.com/2008/05/howto-install-mac-fonts-on-ubuntu.html.

Ahmad Shukr said...

i recently ( about 1 month ) , switch to Ubuntu from win 7 , i use it mainly to develop in PHP ...