• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Saturday, May 10, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home VPS/Servers management guides

How To setup Apache Virtual Hosts On Ubuntu 18

How VPS by How VPS
November 2, 2018
in VPS/Servers management guides
0
How To setup Apache Virtual Hosts On Ubuntu 18
0
SHARES
13
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Introduction
  2. Before You Start
  3. Step 1 – Creating A Directory Structure
  4. Step 2 – Creating Apache Virtual Hosts
  5. Conclusion
  6. Check out these top 3 Linux hosting services
    1. Was this article helpful?

Introduction

Apache is one of the best web servers that accounts for more than 50% of all active websites and applications on the internet. It is a powerful and flexible package that enables users to deliver content on the web without a struggle.

Apache web server breaks its components and functionality into minute units that can be configured and customized independently. One of these units is the Apache Virtual Host; a component used to describe a domain or a website.

Apache Virtual Hosts enable you to handle multiple websites on one VPS or dedicated server. They permit you to stipulate your site document root, use unique SSL certificate for each site, create different security policies for each domain, and much more.

This tutorial will help you create Apache Virtual Host on your Ubuntu 18.04 system.

Ready? Let’s get started!

Before You Start

For this installation to work out perfectly, you require the following:

  • A domain pointing to a public server Internet Protocol. This tutorial will utilize the domain example.com. (Kindly use your domain name)
  • Fully configured Apache o your Ubuntu 18.04
  • Sudo user with non-root privileges

Step 1 – Creating A Directory Structure

The first step when setting up Apache Virtual Host is to define the directory structure. The spine of our directory structure will be a document root; a location where all the website files for our domain will be stored. The document root can be set to any location, but in our guide we’ll utilize the structure below:

/var/www/
├── domain1.com
│   └── public_html
├── domain2.com
│   └── public_html
├── domain3.com
│   └── public_html

Basically, we should create unique directory inside /var/www for every domain to be hosted on our server. Then, within each the directories, we generate another directory; public_html, that will be used to save the websites files for the domain.

First execute the command below to create a document root directory for example.com:

$ sudo mkdir -p /var/www/example.com/public_html

Next, we’ll create a file; index.html, inside the document root directory of our domain. Then open the file using a nano editor.

 $ sudo nano /var/www/example.com/public_html/index.html

Add the content below to create a demo file:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Welcome to example.com</title>
  </head>
  <body>
    <h1>Success! example.com home page!</h1>
  </body>
</html>

Note: We are executing the commands in our tutorial as sudo users. Also, the directories and files we have created are owned by a root use. This may result to permission issues and it’s always wise to modify the ownership of your document root directory to  www-data (Apache User). Run the command:

$ sudo chown -R www-data: /var/www/example.com

That’s it! The ownership is changed and you should anticipate no permission issues.

Step 2 – Creating Apache Virtual Hosts

Ubuntu systems store the configuration files of Apache Virtual Hosts in the directory; /etc/apache2/sites-available. This means that creating symlinks to the directory; /etc/apache2/sites-enabled, can easily enable these configuration files. Now, run the command below to open a configuration file:

$ sudo nano /etc/apache2/sites-available/example.com.conf

Add the content below to create a basic configuration file for the Virtual Host:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/example.com/public_html

    <Directory /var/www/example.com/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverrideAll
    </Directory>

    ErrorLog${APACHE_LOG_DIR}/example.com-error.log
    CustomLog${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>

Here is an explanation of the content featured in theConfiguration file:

  • ServerName: This your domain name
  • ServerAlias: This value represents all the other domains, such as your www subdomains.
  • DocumentRoot: This the directory used by Apache to serve domain files.
  • Options: This is a directory used to determine the server features present in a directory. The -Indexes bar directory listings whereas, FollowSymLinks enables Apache to use the symlinks.
  • AllowOverride: As the name suggests, this part stipulates which .htaccess can override configuration directives.
  • ErrorLog, CustomLog: Stipulates the log files’ location.

There is no definite formula for the naming of the configuration files. However, it’s always wise to name the configuration file for Apache Virtual Host, using your domain name.

Now, we need to enable the new Apache Virtual Host file. We’ll create a symlink (symbolic link) from the Apache virtual host file to the directory; sites-enabled. Let’s use the the a2ensite helper to enable the virtual host file:

$ sudo a2ensite example.com

Alternatively, create the symlink manually:

$ sudo ln -s /etc/apache2/sites-available/example.com.conf /etc/apache2/sites-enabled/

Once that is done, execute the command below to verify the syntax:

$ sudo apachectl configtest

This will give you the output below:

Syntax OK

Now, restart your Apache2 service to implement the changes:

$ sudo systemctl restart apache2

Finally, go to your web browser and search http://example.com. This will give you the following output:

How To setup Apache Virtual Hosts On Ubuntu 18

Conclusion

Congratulations! You have successfully set up an Apache Virtual Host on your Ubuntu 18.04 virtual server. If you have multiple domains and would like to create Apache Virtual Hosts for them, repeat the steps outlined in the tutorial for each of the domain.

Check out these top 3 Linux hosting services

0

Was this article helpful?

Submit
Previous Post

Add Rainbow Colors to Linux Command Output in Slow Motion

Next Post

How to Use Rsync to Sync New or Changed/Modified Files in Linux

Next Post

How to Use Rsync to Sync New or Changed/Modified Files in Linux

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet