I need help with virtualhost settings in apache2. I do not want users to access my website directly using a server ip like http://55.66.77.88 and want to ensure that it opens only when the particular domain (example.com) is typed in. The direct ip access should result in a redirect the example.com.

Just create a default VirtualHost which will be defined before any other VirtualHost. If the HTTP/1.1 Host header contains a domain which no VirtualHost exists for, no domain at all or if HTTP/1.0 is used, the default VirtualHost will be served to the client.

You can easily put a RedirectPermanent directive inside that default VirtualHost.