{"id":5629,"date":"2020-04-30T11:13:22","date_gmt":"2020-04-30T05:43:22","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=5629"},"modified":"2026-11-10T16:31:43","modified_gmt":"2026-11-10T11:01:43","slug":"apache-virtual-hosts-on-ubuntu-16-04","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/apache-virtual-hosts-on-ubuntu-16-04\/","title":{"rendered":"How To Set Up Apache Virtual Hosts on Ubuntu 16.04"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\"><strong>Post Date:<\/strong> April 30, 2020<br><strong>Last Updated<\/strong>: November 10, 2026<\/h4>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache is one of the most widely used open-source web servers for hosting websites. Apache Virtual Hosts allow you to host multiple websites or domains on a single Ubuntu server, with each website having its own configuration, document root, and content.In this tutorial, we will walk you through the process of configuring Apache Virtual Hosts on Ubuntu 16.04. You will learn how to create website directories, configure permissions, set up virtual host configuration files, enable the websites, and verify that the configuration is working correctly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding with this tutorial, ensure that you have the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A server running Ubuntu 16.04.<\/li>\n\n\n\n<li>Apache web server installed on the server.<\/li>\n\n\n\n<li>A user account with sudo privileges.<\/li>\n\n\n\n<li>A registered domain name (e.g., <code>example.com<\/code>).<\/li>\n\n\n\n<li>DNS records (A records) pointing your domain name to the server&#8217;s IP address.<\/li>\n\n\n\n<li>Basic knowledge of Linux commands and Apache configuration.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1:Create the Directory Structure<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The first step that we are going to take is to make a directory structure that will hold the site data.<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">       sudo mkdir -p \/var\/www\/example.com\/public_html<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2:Grant Permissions<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now we have the directory structure for our files, but they are owned by our root user. If we want our regular user to be able to modify files in our web directories, we can change the ownership by doing this,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">sudo chown -R $www-data2:$www-data\/var\/www\/example.com\/public_html<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We should also modify our permissions a little bit to ensure that read access is permitted to the general web directory and all of the files and folders it contains so that pages can be served correctly.<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">    sudo chmod -R 755 \/var\/www\/example.com<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3:Create Demo Pages for Each Virtual Host<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We can open up an index.html file in our editor by typing,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">        nano \/var\/www\/example.com\/public_html\/index.html<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this file, create a simple HTML document that indicates the site it is connected to. The file looks like,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"408\" height=\"156\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-from-2020-04-28-13-40-03.png\" alt=\"\" class=\"wp-image-5630\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-from-2020-04-28-13-40-03.png 408w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-from-2020-04-28-13-40-03-300x115.png 300w\" sizes=\"(max-width: 408px) 100vw, 408px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Save and close the file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4:Create New Virtual Host Files<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apache comes with a default virtual host file called 000-default.conf. Start copying the file for our domain.<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">sudo cp \/etc\/apache2\/sites-available\/000-default.conf \/etc\/apache2\/sites-available\/example.com.conf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the new file in editor with root privileges,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">sudo nano \/etc\/apache2\/sites-available\/example.com.conf<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"478\" height=\"118\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-from-2020-04-28-13-55-00.png\" alt=\"\" class=\"wp-image-5631\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-from-2020-04-28-13-55-00.png 478w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-from-2020-04-28-13-55-00-300x74.png 300w\" sizes=\"(max-width: 478px) 100vw, 478px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">First, we need to change the ServerAdmin directive to an email that the site administrator can receive emails through.<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">ServerAdmin admin@example.com <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After that we need to add servername and server alias name.<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">ServerName example.com<br>ServerAlias www.example.com<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then, we need to change the document root path as,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">DocumentRoot \/var\/www\/example.com\/public_html<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The file looks like,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"484\" height=\"140\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-from-2020-04-28-14-01-24.png\" alt=\"\" class=\"wp-image-5632\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-from-2020-04-28-14-01-24.png 484w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-from-2020-04-28-14-01-24-300x87.png 300w\" sizes=\"(max-width: 484px) 100vw, 484px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Save and close the file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5:Enable the New Virtual Host Files<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We need to enable our site using a2ensite by, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">sudo a2ensite example.com.conf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then, we need disable 000-default.conf file by, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">sudo a2dissite 000-default.conf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We need to verify syntax before restarting apache,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">apachectl -t<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After that, we need to restart apache,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">sudo systemctl restart apache2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">                                                             or,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background wp-block-paragraph\">sudo service apache2 restart<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6:Test your Results<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We need to go to this page http:\/\/example.com.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The result page looks like,<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background wp-block-paragraph\">Success!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You have successfully created virtual hosting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CONCLUSION<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this tutorial, we have successfully configured an Apache Virtual Host on Ubuntu 16.04. We covered creating the website directory, setting the appropriate permissions, creating a sample web page, configuring the virtual host file, and enabling the site.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache Virtual Hosts make it easier to manage and host multiple websites on a single server while maintaining separate configurations and document roots. You can follow the same process to add additional domains to your Ubuntu server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By following these steps, you can efficiently manage multiple websites using Apache Virtual Hosting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. What is Apache Virtual Hosting?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache Virtual Hosting is a feature that allows you to host multiple websites or domain names on a single Apache web server. Each website can have its own document root and configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. What are the prerequisites for configuring Apache Virtual Hosts on Ubuntu 16.04?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You need an Ubuntu 16.04 server, Apache web server, a user account with sudo privileges, a registered domain name, and DNS records pointing to your server&#8217;s IP address.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Where are Apache Virtual Host configuration files stored in Ubuntu 16.04?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache Virtual Host configuration files are stored in the <code>\/etc\/apache2\/sites-available\/<\/code> directory. Enabled virtual hosts are linked to the <code>\/etc\/apache2\/sites-enabled\/<\/code> directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/add-multiple-domainsvirtual-hosts-apache-ubuntu\/\">How to Configure Multiple Domains Using Virtual Hosts on Apache Ubuntu<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Documentation<\/h2>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/vhosts\/\" target=\"_blank\" rel=\"noopener\">Apache HTTP Server \u2013 Virtual Host Documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/vhosts\/examples.html\" target=\"_blank\" rel=\"noopener\">Apache HTTP Server \u2013 Virtual Host Examples<\/a><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Need Help Configuring and Managing Apache Web Servers?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Looking to host multiple websites on a single server or configure Apache Virtual Hosts for your domains?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/\">Pheonix Solutions<\/a> provides Linux server administration, Apache web server configuration, cloud hosting, website migration, server management, and infrastructure support services.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our team can help you configure Apache Virtual Hosts, manage multiple domains, troubleshoot web server issues, optimize server performance, and maintain your hosting environment securely.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/contact\/\">Get in touch with our team<\/a> to discuss your web hosting and server management requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: April 30, 2020Last Updated: November 10, 2026 Introduction Apache is one of the most widely used open-source web [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13116,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[278],"class_list":["post-5629","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-architecture","tag-apache","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1sN","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/images.png","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=5629"}],"version-history":[{"count":4,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5629\/revisions"}],"predecessor-version":[{"id":13125,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5629\/revisions\/13125"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media\/13116"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=5629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=5629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=5629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}