The X-men movie franchise is divided in two timelines (And about 3 or 4 universes), original and the alternate. This is because the franchise as a whole is a hot mess of continuity mistakes and retcons seeing the IP got passed around more then it should have.
(mistakes like people suddenly becoming younger/older then they are supposed to be, characters being on different places at the same time or have completely different backstories/personalities and so on for Example this is supposed to be the same person:
)
They both start with X-Men: First Class, and in the original they progress as following:
- X-Men Origins: Wolverine
- X-Men
- X2: X-Men United
- X-Men: The Last Stand
- The Wolverine
- X-Men: Days of Future Past
But the Days of Future past movie travels back in time to somewhere between First Class and Origins Wolverine. And due tot he events in that movie everything except for First Class gets erased, creating the alternate timeline.
Seeing the time travel events happen after First Class that movie is also the start of this universe but instead is followed by the last movie in the original timeline (Days Of Future Past).
After these the movies the order is:
- X-Men: Apocalypse
- X-Men: Dark Phoenix
- Deadpool
- Deadpool 2
- Logan
About the shows, Laura Shuler Donner, the Producer of the Legion show stated in an Interview that the show has no connection to the movies and is it's own universe (making it the third).
The Gifted on the other hand is kept vague without any official statements to where it belongs in the canon. The story fits in both timelines. Either in the original timeline where it is somewhere between The Wolverine and Days of Future Past or in the Alternate one somewhere between Deadpool 2 and Logan.
And as you might have noticed, The New Mutants remain unmentioned seeing it's also vague in what timeline it belongs. Josh Boone, the director of new mutants said that it started in the original timeline (placing it somewhere between The Wolverine and Days Of Future Past) but became it's own universe yet still lightly connected...making it universe number 4 or part of the original timeline.