Friedrich Nietzsche, in Twilight of the Idols (1889), the twelfth of the “Maxims and Arrows”: “Hat man sein warum? des Lebens, so verträgt man sich fast mit jedem wie?” The famous English wording is a free translation; the maxim then adds: “Man does not aspire to happiness; only the Englishman does that.”
What it means
If you know what you are living for, you can put up with almost any way of having to live. A reason makes hardship bearable; without one, even comfort can feel empty.
Where it comes from
The German, as Wikiquote gives it, is: “Hat man sein warum? des Lebens, so verträgt man sich fast mit jedem wie?” Anthony Ludovici's 1911 translation renders it: “If a man knows the wherefore of his existence, then the manner of it can take care of itself. Man does not aspire to happiness; only the Englishman does that.” The second sentence, a dig at English utilitarian philosophers, is almost never quoted.
The popular form, “He who has a why to live can bear almost any how”, is a looser translation of the same German sentence.