Some Web Development Tips, In No Particular Order, With No Particular Count, and Of No Particular Importance
Originally posted on 2008-03-21 at masonbrowne.info
After reading Yongfook's Dirty Little Web Development Tricks, I thought I'd share my own.
Become Efficient In Your Editor of Choice
No, IDEs do not make the man. But saving tons of time because you know every shortcut of your favorite editor will.
I personally prefer TextMate. It was the first no-nonsense editor I found after switching away from bull-blown IDEs, and it suits me quite nicely.
Ditch the FTP
The n00b way of updating files on your web host would be to FTP in and drag and drop / delete stuff. Doing it like this will quickly get you into a mess with a large site with many files - there’s the potential to forget to upload certain files, accidentally overwriting things you shouldn’t etc.
Using SCM as a deployment tool really is a slick trick to ease your life as a developer. But it gets better...
Use Capistrano (Or Something Similar) For Deploying Code
Contrary to popular believe, Capistrano is not just for Rails projects. In case you haven't heard of it (and are too lazy to click the link I just gave you), Capistrano a tool for automating tasks via SSH on multiple (or single) servers. Because it is a DSL written in Ruby, many people assume it can only be used to deploy Ruby projects. In truth, Capistrano could care less what language capified projects are written in. All it needs is a Capfile and a deploy recipe.
When Would I Use Capistrano?
Let's say you have three servers behind a reverse-proxy/load-balancer. Each server has an instance of your application code, and requests are being passed along by your balancer to each of those instances. When you make a change to your application code, it has to be updated on all three machines simultaneously with minimal downtime, else you have to make sure you're only reverse-proxying to machines with the updated code. This would likely mean setting the balancer to balance between two machines, updating the third, setting the proxy to balance to the new machine, updating the first and second, then setting the proxy back to all three machines.
Capistrano enables you simultaneously deploy your application code to all three instances, and almost instantly flip requests to use that code, without taking down machines or messing with your balancer. (In the case or Rails applications, the application servers actually have to be restarted to load the new code into memory. With PHP, the app is usually loaded with each request, so it would, in effect, be instantaneous.) Moreover, Capistrano gives you the ability to revert to a previous deployment with the same ease.
Once you're set up, deploying code is as easy as:
cap deploy
and rolling back:
cap deploy:rollback
Definitely slick. It deploys code by running a subversion checkout from a specified repository for each server you've defined. It then symlinks the latest deployment to a "current" directory. Rolling back is done by symlinking the "current" directory to a previous deployment, and deleting the folder for the deployment you just rolled back from.
But Deployment Is Only Part Of It
Capistrano can do a whole lot more. Basically, any administrative task you can do via SSH, you can automate with Capistrano. Trimming old log files, emptying cache directories, restarting servers, setting up configuration scripts, even installing software. If you have the willingness to extend Capistrano with your own recipes, the possibilities are limitless. The true glory is that it runs these commands on multiple machines at once. (Technically, they're run serially, but effect is that you only feel like you're dealing with one machine.)
Invest In A Dedicated Machine, Or At Least Get A VPS Or Three
Sooner or later, shared hosting just isn't going to cut it. The resources are spread too thin, and you're at the mercy of your provider for nearly everything. If a couple hundred a month for a dedicated server is too much, pick up a couple VPSs at Slicehost. You have dedicated resources, and fine-grained control over your environment. Need to install something as root? Go for it. Need a non-standard Apache configuration? Go for it. Dedicated/VPS is truly the way to go for anything beyond the most basic web projects.
Start Using Something Besides Windows For Development
Let me lay down the disclaimer and say, yes, I am an Apple zealot. I have an Apple MacBook Pro. Before that, a Powerbook. Before that, a Compaq. Before that, an iBook. Before that, a Toshiba. Notice something in there? I actually switched back from Mac to Windows... and then a month later realized it was unbearable and ponied up for a proper computer. But I digress.
Most of the machines powering the web these days are some type of Linux/Unix variant. If the code you're spending so much time creating will ultimately live on these machines, why not use something similar for development? Mac OS X is a fully Unix-compliant operating system, but a lot of developers I know work on Debian-based systems. Ubuntu, for example, has many of the same amenities you're used to on a Windows machine, except you end up getting a lot more bang for your buck, both in terms of cost and performance. Additionally, since the setup closely resembles your production machines (or can be, in some cases, identical), you'll know whatever you're running on the development machine will work in prod.
It's just a sensible thing to do.