{"id":3719,"date":"2019-03-07T16:10:51","date_gmt":"2019-03-07T10:40:51","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=3719"},"modified":"2026-10-10T17:48:53","modified_gmt":"2026-10-10T12:18:53","slug":"create-apache-virtual-hosts-ubuntu","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/create-apache-virtual-hosts-ubuntu\/","title":{"rendered":"How to Create Apache Virtual Hosts in Ubuntu: A Step-by-Step Guide"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Post Date: March 07, 2019<br>Last Updated: October 10, 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create Apache Virtual Hosts in Ubuntu to host multiple websites on a single server using the Apache web server. Apache Virtual Hosts allow you to configure separate domain names, document roots, and log files for each website. In this tutorial, we will explain how to create Apache Virtual Hosts in Ubuntu step by step, enable the configuration, verify the syntax, and restart Apache to apply the changes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before creating Apache Virtual Hosts in Ubuntu, ensure you have the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An Ubuntu server with sudo or root access.<\/li>\n\n\n\n<li>Apache2 installed on the server, or permission to install it.<\/li>\n\n\n\n<li>A registered domain name, such as <code>example.com<\/code>.<\/li>\n\n\n\n<li>The domain&#8217;s DNS A record pointing to your server&#8217;s public IP address.<\/li>\n\n\n\n<li>Basic knowledge of Linux commands and Apache configuration files.<\/li>\n\n\n\n<li>Access to a terminal or SSH client to execute the required commands.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Create Apache Virtual Hosts in Ubuntu<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this post we will explain how to create the virtual hosts in ubuntu. <br><br>Apache is the most important used web server software in the world because it is an open source software. This web server developed and maintained by Apache Software Foundation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong> 1)<\/strong> Install the apache web server on your ubuntu server<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ sudo apt-get install apache2\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2)<\/strong> Make the new directory for the new domain. <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo mkdir -p \/var\/www\/html\/example.com<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"> <strong>3)<\/strong> You can use the code for your new domain.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vi \/var\/www\/html\/example.com\/index.html\n&lt;html>\n &lt;head>\n &lt;title>example.com&lt;\/title>\n &lt;\/head>\n &lt;body>\n &lt;h1>Hello, This is a test page for example.com website&lt;\/h1>\n &lt;\/body>\n&lt;\/html><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3)<\/strong> New configuration file for example.com domain.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo vi \/etc\/apache2\/sites-available\/example.com.conf\n\n&lt;VirtualHost *:80>\n # The ServerName directive sets the request scheme, hostname and port that\n # the server uses to identify itself. This is used when creating\n # redirection URLs. In the context of virtual hosts, the ServerName\n # specifies what hostname must appear in the request's Host: header to\n # match this virtual host. For the default virtual host (this file) this\n # value is not decisive as it is used as a last resort host regardless.\n # However, you must set it for any further virtual host explicitly.\n #ServerName www.example.com\n\n   ServerAdmin webmaster@example.com\n   ServerName example.com\n   ServerAlias www.example.com\n   DocumentRoot \/var\/www\/html\/example.com\/public_html\n\n# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,\n # error, crit, alert, emerg.\n # It is also possible to configure the loglevel for particular\n # modules, e.g.\n #LogLevel info ssl:warn\n\nErrorLog ${APACHE_LOG_DIR}\/error.log\n CustomLog ${APACHE_LOG_DIR}\/access.log combined\n\n# For most configuration files from conf-available\/, which are\n # enabled or disabled at a global level, it is possible to\n # include a line for only one particular virtual host. For example the\n # following line enables the CGI configuration for this host only\n # after it has been globally disabled with \"a2disconf\".\n #Include conf-available\/serve-cgi-bin.conf\n&lt;\/VirtualHost><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"> <strong>4)<\/strong> Enable virtual host configuration files.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">a2ensite example.com.conf\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5)<\/strong> Run this command and check the apache files is syntax is correct or not.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apachectl configtest\n\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6)<\/strong> If made any change in the apache related configuration you need to restart apache web server to take a look upon the changes.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">systemctl restart apache2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Congratulations! You have completed the virtual host setup and can now be able to access your websites.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Creating Apache Virtual Hosts in Ubuntu allows you to host and manage multiple websites on a single server efficiently. By creating a separate document root and configuration file for each domain, you can organize website files and manage individual site settings. After enabling the virtual host, checking the Apache configuration syntax, and restarting the service, your website will be ready to serve requests once the domain&#8217;s DNS is correctly configured. Follow these steps to configure Apache Virtual Hosts in Ubuntu and simplify website management. For more information about Apache Virtual Hosts, refer to the official documentation <a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/vhosts\" target=\"_blank\" rel=\"noopener\">Link<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For professional assistance with Apache configuration, web hosting, and server management, please reach out to here. <a href=\"https:\/\/pheonixsolutions.com\/contact\">Link<\/a> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. What are Apache Virtual Hosts in Ubuntu?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apache Virtual Hosts in Ubuntu allow you to host multiple websites on a single Apache web server. Each website can have its own domain name, document root, and configuration settings.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. How do I create Apache Virtual Hosts in Ubuntu?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To create Apache Virtual Hosts in Ubuntu, install Apache2, create a document root for your website, configure a virtual host file in <code>\/etc\/apache2\/sites-available\/<\/code>, enable the configuration, and restart Apache.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Where are Apache Virtual Host configuration files stored in Ubuntu?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apache Virtual Host configuration files are stored in <code>\/etc\/apache2\/sites-available\/<\/code>. Enabled virtual hosts are linked in 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\/modify-virtualhost-single-domain-cpanelapache-2-4\/\">How to Modify the Apache VirtualHost Configuration for a Single Domain in cPanel<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/add-custom-virtualhost-configurationapache-2-4\/\">How to Configure a Custom VirtualHost in cPanel with Apache 2.4<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Need Help with Apache Virtual Hosts in Ubuntu?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Need help with Apache Virtual Hosts in Ubuntu, domain configuration, website hosting, or Apache server management? Our experts can help with Apache configuration, Linux server administration, web server optimization, security hardening, and cloud hosting solutions. Get in touch with our team <a href=\"https:\/\/pheonixsolutions.com\/contact\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: March 07, 2019Last Updated: October 10, 2026 Introduction Create Apache Virtual Hosts in Ubuntu to host multiple websites [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"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,274,579,159],"class_list":["post-3719","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-apache","tag-ubuntu","tag-virtual-hosts","tag-webserver","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-XZ","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3719","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=3719"}],"version-history":[{"count":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3719\/revisions"}],"predecessor-version":[{"id":12228,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3719\/revisions\/12228"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}