I don't believe in prescriptive grammar, so the only "rules" for a language are how the language is currently used by native speakers.
In this case, both are widely used and widely understood. "If only he were here" is more formal, but the subjunctive is largely archaic in English, and I think just as many people (or more, depending on the area) would say "if only he was here".
In the end, I don't think anyone, except grammar nazis, would correct you if you used either in conversation. For writing formal documents, "were" would be slightly preferred.