Create Virtual Host Files
By default, Apache comes with a default virtual host file called 000-default.conf. We will copy the 000-default.conf file contents to our new virtual host files.

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mysite.local.conf
# Make the relevant changes that reflect to the site.
sudo vi /etc/apache2/sites-available/mysite.local.conf
# Add the following scripts below to mysite.local.conf
# Assign the app to a specific port 8081
<VirtualHost *:8081>
  ServerAdmin webmaster@mysite.local
  ServerName mysite.local:8081
  ServerAlias www.mysite.local
  DocumentRoot /var/www/html/mysite.local/public_html
  ErrorLog /var/www/html/mysite.local/logs/error.log
  CustomLog /var/www/html/mysite.local/logs/access.log combined

<VirtualHost *:80>
  ServerName local.helloworldapp.com
  ServerAlias local.helloworldapp.com
  DocumentRoot /var/www/html/helloworldapp
  ErrorLog /var/www/html/helloworldapp/logs/error.log
  CustomLog /var/www/html/helloworldapp/logs/access.log
  <Directory /var/html/helloworldapp>
    Options Indexes FollowSymLinks MultiViews
    #AllowOverride All
    #Order allow,deny
    #Allow from all
    Require all granted       

Edit ports.conf, add port 8081 for our site

$ sudo vi /etc/apache2/ports.conf
Listen 80
Listen 8081

If you want to use a custom domain name(e.g. mysite.com) follow the format use in helloworld app(See above). And then update the local hosts file.

$ sudo vi /etc/hosts	localhost	local.helloworldapp.com

Thats it..it should work.

After modifying the virtual hosts files, you can enable it now:

##To enable the site:
$ cd /etc/apache2/sites-available
$ sudo a2ensite mysite.local.conf
$ service apache2 reload
##To disable the site:
$ sudo a2dissite mysite.local.conf

Finally, restart the apache service.

sudo service apache2 restart      # for Ubuntu 14.10
sudo systemctl restart apache2    # for Ubuntu 15.04
sudo /etc/init.d/apache2 restart  # for Ubuntu 15.04

Thats it, the site is ready to serve!! Type the url in your browser
mysite.local:8081. If it does not appear then there’s something wrong in the configuration. Check the error log for debugging..

$ tail -f /var/log/apache2/error.log

How to list all vHosts Currently enabled In Apache?

$ apache2ctl -S   # for Ubuntu/Debian
$ httpd -S        # for CentOS

If you encountered an error that says “apache2: Could not reliably determine the server’s fully qualified domain name, using Set the ‘ServerName’ directive globally to suppress this message”

$ sudo vi /etc/apache2/apache2.conf

# Add this line and then restart it
ServerName localhost

$ sudo /etc/init.d/apache2 restart
artheman@ub3c:/etc/apache2/sites-available$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.
artheman@ub3c:/etc/apache2/sites-available$ apache2ctl -S
VirtualHost configuration:
*:80 localhost (/etc/apache2/sites-enabled/000-default.conf:1)
*:8081 ciblog.local (/etc/apache2/sites-enabled/ciblog.local.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used