Paul writes rejoice from prison, which is worth remembering before the verse is used to tell anyone to cheer up. He is not describing a temperament or recommending a positive outlook. He is chained to a guard and telling a church he loves to rejoice, and then, as if aware how it sounds, saying it a second time: and again I say, Rejoice.
The crucial words are in the Lord. The command is not to rejoice in your circumstances, which would be either dishonest or impossible. It is to rejoice in something that has not changed. Paul's situation is bad; the thing his joy is anchored to is not his situation.
This distinction rescues the verse from cruelty. Christians are not required to feel good about a diagnosis, a bereavement, or a betrayal. Paul does not do that himself — the same letter speaks of sorrow upon sorrow and of a friend who nearly died. Grief and rejoicing coexist in this book without embarrassment.
What follows is practical. Let your moderation be known; be anxious for nothing; pray about everything; think about what is true and honest and lovely. Joy here is not a mood that descends. It is fed by where you deliberately put your attention, and Paul is directing that attention to a Lord who is at hand.