In the games I typically end up running, the classic fighter, cleric, rogue and wizard party tends to be the exception, not the rule. However, party composition plays an incredibly important role in determining what the characters are capable of facing. In this vein, I hope to share of the ideas I've accumulated. Some of these will seem like common sense, but I hope they will help. Most of the word count of this piece will focus on the situation where party composition is simply thrown to the wind.
Substituting Similar Classes
If you don't want the same old party every time, substituting similar classes is an easy way to go. Barbarians can replace the fighter fairly easily. A sorcerer can fill in for a wizard. The issue is that while this kind of substitution is easy to do and account for, it doesn't make for the most original party.
Substituting Classes Based on Ability
I've seen wizard focused on utility spells substitute for a rogue. Of course, there were some implications for this substitute that would not be present for a rogue such as spell slots, but at the same time it worked reasonably well. There are also some situations where multiple different characters can collectively substitute for a class. You could try to replace the wizard from the party with a combination of a cleric and an Eldritch Knight in order to fill in the utility portion of that role. Generally, while this kind of substitution works quite well, it isn't a perfect substitution. Instead, you try to cover the most important portions of the class (protection against magic and utility for the wizard example) and give up portions that you can afford to give up (damage spells can be substituted by the Eldritch Knight weapon damage).
The last general approach for the balancing party problem is to simply not to worry about it. The best way to accomplish this is heavily dependent on the kind of game being run (more so than the above methods). If there are no magic creatures to face the wizard's protection spells end up being redundant. In this kind of case, it is up to the Dungeon Master to somehow let the player's know the kind of game being run so that they can make sure to form a party that won't get horribly decimated. At the same time, the problem can be thrown on the other side of the DM screen. In this case, if the players want to have no cleric then maybe they need to have some kind of house rules to increase the amount of healing they can do (as a quick aside, this can be easily done by increasing the amount of healing from the second wind feature or by making the healer feat useful past level 1).
The most common issues I have seen involves healing and curing effects. If a party has no cleric, a medusa is absolutely terrifying since there isn't a good way to un-petrify characters. To get around this we either need changes in lore (killing the medusa might undo the effects or smearing the medusa's blood might as well), potions or some other way of gaining the ability.
One of the situations I encountered involved a game of the newest version of D&D (5th edition, in case you are looking at this way in the future) where the entire 4 man party was composed of fighters. It was 1 champion and 3 battle masters, each with a different build. Since the world was very low magic, this actually managed to work just fine without any changes. The players would rotate the lines when the front line got hurt enough and as a result could spread out the damage. They also had their hit dice and second wind for healing. They could have more staying power by increasing the healing from second wind or by making the healer feat worth using (maybe 1d6 more per 2 levels).
There we have it. Like I said, most of this stuff is probably common sense but I hope writing it down like this helps at least one person out there. In particular, I want to stress how much the definition of a “balanced party” depends on the campaign itself. As usual, feel free to comment on anything related to this topic.