He made him lord of his house, and ruler of all his substance:
 To bind his princes at his pleasure; and teach his senators wisdom.
The psalmist is recalling the events of Genesis where Joseph rose to power and became the second highest ranked person in Egypt (cf. Genesis 41:40). With Joseph in leadership, his brothers (who betrayed him many years earlier) were now going to move to Egypt and be protected from this famine that affected an area which included Egypt and Israel.
It is refreshing to remember God both allows and controls the tragedies in our lives. God also makes a way for us to escape or get through a difficult time (see 1 Corinthians 10:13). Just as God allowed the Israelites to survive through a long multi-year famine, so God makes a way for you and I to continue to serve Him as long as we are trusting in Him.
 Israel also came into Egypt; and Jacob sojourned in the land of Ham.
The name Israel refers to Jacob and his sons (Genesis 46). The land of Ham is another name for Egypt (Genesis 10:6). Ham was one of three sons of Noah, who many centuries earlier, settled in Egypt and is the ancestor of all Egyptians. Just as the writer already used the word Egypt in the previous part of this sentence and now needed a synonym, he used “Ham”.