Tuesday, July 28, 2020

Virtual or Web Hosting on Ubuntu 18.04 LTS (Bionic Beaver)

The following virtual or web hosting setup intends to:

• Make the Apache2 home directory for the virtual hosts in "/home"
• Virtual hosts will be located in their own directory (e.g., user "rasul" will be located in "/home/rasul") and accessible via remote SSH
• Web pages of each virtual host (e.g., user "rasul") will be located in "/home/rasul/www/html"
• Error pages of Apache2 will be located in "/home/rasul/www/error"
• Access log pages of Apache2 will be located in "/home/rasul/www/access"


My preferred editor in here is "joe", a WordStar-like text editor, but you can use your own preferred editor like "vi", "vim", or "nano". This also assumes that you have made the relevant DNS entries for the web host and pointed to the IP address of the Apache webserver.
Step 1: Edit the "apache2.conf" configuration file and add the following entries that will allow apache2 to enter the "/home" directory:

# cd /etc/apache2
# joe apache2.conf

< Directory /home/ >
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
< Directory >



Step 2: Edit the "000-default.conf" in the subdirectory "/etc/apache2/sites-available" and enter the following entries that will define the web pages directory, error pages, and access logs:

# cd /etc/apache2/sites-available
# joe 000-default.conf

< VirtualHost *:80 >
ServerName www.rasul.ph
ServerAdmin webmaster@rasul.ph
DocumentRoot /home/rasul/www/html
ErrorLog /home/rasul/www/error/error.log
CustomLog /home/rasul/www/log/access.log combined
< VirtualHost >



Step 3: Create the virtual host "username" and the corresponing directories, subdirectories, and files:

# adduser rasul
# mkdir /home/rasul/www
# mkdir /home/rasul/www/html
# mkdir /home/rasul/www/error
# mkdir /home/rasul/www/log
# touch /home/rasul/www/error/error.log
# touch /home/rasul/www/log/access.log


Step 4: Change group of the virtual hosts into "www-data". Ubuntu's Apache uses the username "www-data" and group "www-data".

# cd /home
# chown -R rasul.www-data rasul

Listing the directory should display as:

# ls -l
drwxr-xr-x 2 rasul www-data 4096 Jul 29 10:37 rasul




Step 5: Restart the Apache webserver to load the virtual hosts settings

# systemctl restart apache2

Step 6: Check to see by placing a sample webpage in the html directory of the virtual hosts and viewing it in your browser.

No comments: