Installing apache2 on Ubuntu
$ sudo apt update
$ sudo apt install apache2
Apache comes with a default site. The contents are located at /var/www/html and its settings are in a Virtual Host file at /etc/apache2/sites-enabled/000-default.conf
Create directory for the new site
$ mkdir /var/mysite
Creating the virtual host for the new site
Clone the configuration file of default site for the new site
$ cd /etc/apache2/sites-available/
$ cp 000-default.conf mysite.conf
Edit the new configuration file to update the new port number(optional), ServerAdmin, DocumentRoot & add Permissions
$ sudo nano /etc/apache2/sites-available/mysite.conf
The configuration file should look something like this -
<VirtualHost *:8081>
ServerAdmin dev@localhost
DocumentRoot /var/mysite
<Directory /var/mysite>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
Configure apache to listen to the new port
$ sudo nano /etc/apache2/ports.conf
Add the following lines for the new port
NameVirtualHost *:8081
Listen 8081
Activate the virtual host
$ sudo a2ensite mysite.conf
Reload the apache service to load new configuration
$ sudo systemctl reload apache2
or
$ sudo service apache2 reload
Test the new site at http://<hostname>:8081/