The type of defense you use is always dependent upon the situation. There is one universal truth, however: the best defensive investment you can ever make is a good fleet. Without a good fleet, any defense (no matter how good) is just going to delay the inevitable.
The best static defense is the repair bay. It's very inexpensive and very useful. Even if the planet isn't under attack, you can always retreat injured units (particularly capital ships) to those locations to repair to full strength. Repair bays should be one of the first military technologies you research. When you build your repair bays, try to build them in pairs so they can repair each other, and build any other buildings in the area they overlap.
Turrets are typically a waste of your time and money. The AI will happily run right into them and get killed, but their range is too short and a player will simply avoid them. There are also some units that completely outrange turrets (available very early in the tech tree) which essentially defeats the whole point of the thing. There are some situations where they are useful, but more often than not you shouldn't buy them at all.
Hangers are slightly better than turrets, but they're rather expensive. At very least their strike craft can attack anything in the gravity well, so the enemy can't avoid them like turrets, but usually you're better off buying more frigates for your fleet than building these things.
A common defensive configuration is two repair bays and a frigate factory all built very close together. The reason this defense is so popular is because it's not exclusively a defense. Even if you're fighting in another nearby gravity well, you can still use the frigate factory to produce reinforcements and retreat injured units to the repair bays. It also functions as a very effective defense, and in an otherwise even fleet battle it's very hard to defeat this simple combination. The catch is that your main fleet needs to be nearby, and if you're significantly outnumbered by the enemy this won't do much to stop them. In the early game, this should be all you really need (and, in fact, all you can realistically afford).
There are only three reasons you should build heavy defenses on one planet. The first is if it's late game and you have lots of money to spare. The second is if you have an effective choke point that the enemy must bypass to attack you, then it makes sense putting up a blockade there. The third is if the enemy is overrunning your empire and you're preparing for a last stand (team games only; this is considered very bad mannered in 1v1 since it's really just a delay tactic). To do this, pick a planet with lots of phase lanes leading out from it (your homeworld, preferably) and build lots of defense there. Now constantly counter-attack the enemy whenever their fleet moves away from one of their planets. If they come to attack you, retreat back to your defenses. You can probably keep an overwhelmingly powerful enemy flustered for a good half-hour with these antics, or better yet get them to attack your little fortress head on.