What is use of these two directories in apache2 and how can we do it?
The difference is that virtual sites listed in the sites-enabled
directory are served by apache. In the sites-available
directory there are the virtual sites that exist on your server but people can't access them because they are not enabled yet.
sites-available: this directory has configuration files for Apache2 Virtual Hosts. Virtual Hosts allow Apache2 to be configured for multiple sites that have separate configurations.
sites-enabled: like mods-enabled, sites-enabled contains symlinks to the /etc/apache2/sites-available directory. Similarly when a configuration file in sites-available is symlinked, the site configured by it will be active once Apache2 is restarted.