For the first entry of this chapter, see Imprisoned at Ephesus.
This short letter only gives a few hints of its setting, but it gives enough for us to get the general picture. Paul calls himself a prisoner in verses 1 and 9, and mentions someone named Epaphras as his "fellow prisoner" in verse 23. More to the point, Paul mentions that he led Onesimus to faith while imprisoned (10) and indicates how helpful Onesimus has been to him throughout his imprisonment (13). Thus we conclude that Paul is in prison when he writes this letter.
Colossians 4:12 indicates that Epaphras was from the city of Colossae, to which Colossians is addressed. Indeed, Colossians and Philemon have in common other names like Mark, Aristarchus, Demas, Luke (Col. 4:10-14; Phlm 24) and Archippus (Col. 4:17; Phlm 2). Most have thus concluded that Philemon, to whom the letter is addressed, lived in Colossae, a city about a hundred miles east of Ephesus. 
If we leave Colossians out of consideration, the question of whether Paul was imprisoned in Ephesus or Rome when he wrote Philemon focuses on two things: 1) the proximity between Ephesus and Colossae and 2) Paul's apparent expectation that he will visit Colossae soon (Phlm 22). It is certainly possible that a slave from Colossae might find his way to Rome. Indeed, this slave Onesimus might have come to Rome with individuals like Epaphras and Aristarchus who were specifically sent there from the church at Colossae to aid Paul.
But in the end, it is far more likely that the church at Colossae would send help to Paul at Ephesus than at Rome. Rome was well over a thousand miles from Colossae and, depending on the route and time of year, could take months to get there. We can easily imagine the church hearing Paul was in prison and sending a group to him on a five or six day journey, especially if one of their own, Epaphras, had been arrested along with Paul. It is harder to imagine them sending the same group on a two month journey. And Paul apparently hopes Philemon will send Onesimus back to him (Phlm 14)--a four or five month expectation if Paul is in Rome.
Perhaps even more problematic is Paul's apparent plan to come to Colossae when he tells Philemon to prepare him a guest room (Phlm 22). Paul certainly was not thinking about heading back east when he had left the area. In Romans 15:23, Paul says there is no more room for him to work in the east, and he clearly has his eyes on a mission to Spain (Rom. 15:24). It is possible that Paul changed his mind during some four years of imprisonment in Caesarea and Rome, or that he does not really mean to come. After all, he does call himself an "old man" in Philemon 8. But if we take Paul straightforwardly, a plan to visit Colossae fits much better with an early imprisonment at Ephesus than with his time in Rome.
It is not entirely clear what exactly Onesimus had done to anger his master Philemon. It has often been suggested that he was a run-away (cf. Phlm 15), but there are other possibilities. For example, Philemon might have been upset with Onesimus because he had failed at some task. Perhaps he had been unsuccessful at some matter of business and had lost his master money of some significance. After all, Paul tells Philemon that he will pay for any loss he has suffered as a result of Onesimus (Phlm 18). And of course for this reason Onesimus might have stayed away for a bit.
We should not think of slaves in the ancient Mediterranean on quite the same terms as Americans think about slavery in the south before the Civil War. For one thing, race was not a defining feature in ancient slavery, although certainly the Romans did enslave foreigners when they defeated them. And while there were slaves of the servile sort that existed in the American South, many slaves in the ancient world were highly educated and functioned much more like an employee than as an absolute servant. It is quite possible that Onesimus was of this sort.
In any case, Onesimus had somehow angered Philemon. Since Paul speaks of sending Onesimus back to his owner, it would not seem that Onesimus met Paul because he himself had been imprisoned. Rather, it would seem that Onesimus sought Paul out to serve as a go-between with his master--or perhaps he ran into Paul seeking out Epaphras as a go-between. Slaves in trouble with their masters sometimes sought out a go-between in hope that the mediator might soften their owner's reception of them. For example, in the case of a runaway slave, the owner had the authority to put them to death.
Paul's request of Philemon is simple: welcome him back... as he would welcome Paul himself (Phlm 17). Paul never tells Philemon to give him his freedom, although some think Philemon 21 hints at it. Paul indicates he could command him to receive him back, since after all, he would be on a path to eternal death if it were not for Paul (8-9, 19). But Paul--mind you with the entire church listening in (2)--chooses rather to ask Philemon this favor. The fact that the book of Philemon is in Scripture perhaps hints that Philemon did in fact forgive Onesimus.
Whether Philemon sent Onesimus back to Paul, whether he ever emancipated him from slavery, these things we do not know. However, it is interesting that Paul never brings up slavery as an institution. The same Paul who in Galatians 3:28 says that in Christ there is neither slave or free does not tell slave owners to begin to set them free, even when he has the opportunity. He says not to receive Onesimus back as a slave, but he qualifies it by saying to receive him as "more than a slave" (16). In other words, Onesimus becomes a slave and a brother, "more than" a slave but a slave still.
Similarly, Paul says he knows Philemon will do more than he is asking (21). This statement could allude to emancipation, but perhaps it refers more likely to sending Onesimus back to continue helping provide for Paul in his imprisonment. In the end, it is probably our post-Civil War glasses that lead us to read more into Philemon than it actually says about giving Onesimus his freedom.
Yet few of us would now second guess the decisions of Western nations like Britain and the U.S. to do away with slavery. Certainly there were many Christians in the early 1800s who used the Bible and books like Philemon to argue that slavery was perfectly compatible with Christian faith. Some of them in fact criticized the way slave owning was often practiced, while not condemning the institution itself. They found in the Bible no basis for ending the institution, only a basis for reforming its practice. It would be easy to condemn these well-meaning individuals, but with a little effort we can see that they were conscientiously following their understanding of the Bible.
We would argue that we face a similar situation with women today, where many individuals conscientiously find no basis for women in ministry or for a structure in the home that does not always have the husband at the helm. This matter of looking beyond the letter of certain passages to where Scripture as a whole is a difficult business, the stuff of prophets, and not everyone is a prophet. Yet despite certain differences, we would argue that the situation is very similar. Slavery was a social institution of the broader culture then, just as patriarchal structures were. The heavenly principle was then as now no hierarchical distinction in the kingdom between slave and free, male or female. Nevertheless, Paul made concessions in the name of order and of keeping to the priorities of spreading the gospel.
Yet we suspect that Christians a hundred years from now will also find it hard to think well of those who sincerely oppose women in ministry today. How could they not have seen that the full place of women in the church and the home was the obvious outworking of the gospel? After all, there is no physical, intellectual, or psychological basis for such differentiation. Hopefully they will be charitable just as we should to those who could not see where God was leading 150 years ago.
An even more fundamental take-away from Philemon is the need for forgiveness toward one another. We do not really know what Philemon's temperament as a person was. Maybe he was a hard task-master. Maybe his expectations were unreasonable. Whatever the case, Paul presumably knew he was asking a lot of Philemon, to forgive this slave who had so wronged him, at least in his eyes.
It is often easy for us to forgive others, especially when it is not something that matters much to us. In fact, some people are so apologetic for minor things that they almost need forgiveness for asking our forgiveness too much! But Philemon is a reminder of our need to show forgiveness on the big things, the things that do matter a lot to us. I would like to think that God and I together, alone could work out that level of forgiveness on our own. But sometimes God has to use an outsider, like Paul, to come in and exert some pressure. I know what I think Philemon decided, as Archippus, Apphia, and the entire church at Colossae heard this letter read in their public assembly, and turned to Philemon to see what he would say.
 John Knox ingeniously suggested that it was actually Archippus who was the slave owner who lived at Colossae and that the letter of Philemon was in fact the lost letter to the Laodiceans mentioned in Colossians 4:16. Philemon would thus have been the overseer of the church at Laodicea. Few have followed Knox's suggestion (Philemon among the Letters of Paul, 91-108).