What should I do considering search engine ranking if I need to change my primary domain name?

Changing the primary domain name for your website and preserving the search engine ranking can be a tricky task.
First and foremost, you should keep both domain names up and running. The safest way to start is by parking the old domain name to the new one once you have performed the domain name change.
You can check our parked domain names tutorial for detailed instructions how to park your domain name via cPanel.
However, the odds are that search engines will continue indexing your old domain name. Thus the next step is to create a wild card 301 (moved permanently) redirect from your old domain name to the new one.
You can check our article how to create 301 redirects via cPanel for more information how to accomplish this.
The 301 redirect will tell search engines to look for the website pages at the new domain name.
You should, however, bear in mind that it might take time for the search engines to start returning search results for the new domain name. It is possible to get results from the old domain as well as results from both the old and the new domain names. Considering you have an appropriate 301 redirect set, it should not be too long before all search results are from your new domain name.