Non-native speaker here.

#### First choice: How do I ...

On a question-answering site, ask questions as if you asked some people around you right away, since that is what lets you aim at an answer, and that is what makes the needed answer clearer at a first glimpse, and it is the way most people enter their search in a search engine.

You should not write "How to ...?", which is not 100-percent-proper English - see the remark under the question at ["How to ... ?" questions might be wrong grammar. Will it help dropping the question mark for all questions or warning the user or something the like?](https://meta.stackexchange.com/questions/398259/how-to-questions-might-be-wrong-grammar-will-it-help-dropping-the-quest):

> It may not be 'proper' according to some, but it works.

Ask "How do I" / "How can I", which keeps it short and clear, and it is the main way how the people write down their search in the search engines.

#### Second and last choice (since Stack Exchange is not a blog): "How to ... [without a question mark]" / gerund

If your question builds up a frame of a sort of technical writing, perhaps a self-answered question, a guide or some code that needs to be checked, you *may* (but rather should not) switch to a blog-style "How to ..." (*without* a question mark at the end) or a gerund. Both aren't questions, they are a style of blogs or technical platforms. That is why they do not fit well enough to this question-answering site.