To host multiple systems on the same Ubuntu linux server with separate folders inside the /var/www/ directory  for example you have one system skillg and the other elearning;  So, you create the directories as /var/www/skillsg and /var/www/elearning), you need to configure Apache using virtual hosts.

Step 1: Create Directories for Each System

sudo mkdir -p /var/www/skillsg

sudo mkdir -p /var/www/elearning

 Give appropriate ownership:

sudo chown -R www-data:www-data /var/www/skillsg

sudo chown -R www-data:www-data /var/www/elearning

sudo chmod -R 755 /var/www/

Step 2: Create Virtual Host Config Files

Apache virtual host files are stored in /etc/apache2/sites-available/

For skillsg

Create a configuration file:

sudo nano /etc/apache2/sites-available/skillsg.conf

Add the following:

<VirtualHost *:80>

ServerAdmin admin@yourdomain.com

ServerName skillsg.yourdomain.com

DocumentRoot /var/www/skillsg

<Directory /var/www/skillsg>

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/skillsg_error.log

CustomLog ${APACHE_LOG_DIR}/skillsg_access.log combined

</VirtualHost>

 

For elearning

Create another configuration file:

sudo nano /etc/apache2/sites-available/elearning.conf

Add the following:

<VirtualHost *:80>

ServerAdmin admin@yourdomain.com

ServerName elearning.yourdomain.com

DocumentRoot /var/www/elearning

<Directory /var/www/elearning>

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/elearning_error.log

CustomLog ${APACHE_LOG_DIR}/elearning_access.log combined

</VirtualHost>

Step 3: Enable Virtual Hosts

sudo a2ensite skillsg.conf

sudo a2ensite elearning.conf

Disable the default site but this is optional

sudo a2dissite 000-default.conf

Step 4: Restart Apache

sudo systemctl restart apache2

Share this post