{"id":4543,"date":"2024-07-03T13:39:14","date_gmt":"2024-07-03T08:09:14","guid":{"rendered":"https:\/\/www.veeble.org\/kb\/?p=4543"},"modified":"2025-04-08T12:19:49","modified_gmt":"2025-04-08T06:49:49","slug":"how-to-setup-apache-to-host-a-website-in-linux","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/how-to-setup-apache-to-host-a-website-in-linux\/","title":{"rendered":"How to setup Apache Web Server to host a website in Linux"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/08\/APache.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"508\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/08\/APache-1024x508.jpg\" alt=\"How to setup Apache Web Server to host a website in Linux\" class=\"wp-image-5104\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/08\/APache-1024x508.jpg 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/08\/APache-300x149.jpg 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/08\/APache-768x381.jpg 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/08\/APache-1536x761.jpg 1536w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/08\/APache.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><a href=\"https:\/\/httpd.apache.org\/\" target=\"_blank\" rel=\"noopener\">Apache web server<\/a> is one of the most widely used web servers in the world. One of its powerful features is the ability to host multiple websites on a single server, each with its own domain name. This is achieved using Virtual Hosts. When a requested is received by the Apache server  on a virtual host system, it reads the hostname from the client&#8217;s HTTP header and utilizes it to route traffic to the correct domain.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h3>\n\n\n<p>Before we begin, ensure you have the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An <a href=\"https:\/\/www.veeble.org\/in\/vps-hosting\/\" target=\"_blank\" rel=\"noreferrer noopener\">Linu<\/a><a href=\"https:\/\/www.veeble.org\/in\/vps-hosting\/\" target=\"_blank\" rel=\"noopener\">x VPS<\/a> with Apache web server installed. (Here, Ubuntu)<\/li>\n\n\n\n<li>Root or sudo access to your server.<\/li>\n\n\n\n<li>Domain names pointing to your server&#8217;s IP address. (Here we use a test domain <strong>domain1.com<\/strong>)<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Learn how to host a Website in Apache Virtual Host<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Confirm Apache is installed<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl status apache2<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/07\/image.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"493\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/07\/image-1024x493.png\" alt=\"\" class=\"wp-image-4544\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/image-1024x493.png 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/image-300x144.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/image-768x370.png 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/image.png 1172w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><strong>2. Create a directory structure.<\/strong><\/p>\n\n\n\n<p>Create a directory structure for your websites. In this example, we&#8217;ll set up directories for <code><strong>domain1.com<\/strong><\/code>.<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p \/var\/www\/domain1.com\/public_html<\/code><\/pre>\n\n\n\n<p><strong>3. Create a sample index page for domain1.com<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi \/var\/www\/domain1.com\/public_html<\/code><\/pre>\n\n\n\n<p>Add the following content to the file;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/07\/image-1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"933\" height=\"275\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/07\/image-1.png\" alt=\"\" class=\"wp-image-4545\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/image-1.png 933w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/image-1-300x88.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/image-1-768x226.png 768w\" sizes=\"auto, (max-width: 933px) 100vw, 933px\" \/><\/a><\/figure>\n\n\n\n<p><br><strong>4. Create Virtual Configuration<br><\/strong><br>Create a new virtual host configuration file for <code>domain1.com<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi \/etc\/apache2\/sites-available\/domain1.com.conf<\/code><\/pre>\n\n\n\n<p>Add the following content to the file;<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-5-color has-black-background-color has-text-color has-background has-link-color wp-elements-6628678d90bf2dfd023e2ec3817eaf75\"><code>&lt;VirtualHost *:80&gt;\n    ServerAdmin webmaster@domain1.com\n    ServerName domain1.com\n    ServerAlias www.domain1.com\n    DocumentRoot \/var\/www\/domain1.com\/public_html\n\n    &lt;Directory \/var\/www\/domain1.com\/public_html&gt;\n        Options Indexes FollowSymLinks\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory&gt;\n\n    ErrorLog ${APACHE_LOG_DIR}\/domain1.com_error.log\n    CustomLog ${APACHE_LOG_DIR}\/domain1.com_access.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<p><strong>5. Enable the Virtual Host<\/strong><\/p>\n\n\n\n<p>Enable the new virtual host with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a2ensite domain1.com.conf<\/code><\/pre>\n\n\n\n<p><strong>6. Test the Configuration<\/strong><\/p>\n\n\n\n<p>Check the configuration for syntax errors:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apache2ctl configtest<\/code><\/pre>\n\n\n\n<p>If the output is <code>Syntax OK<\/code> as below, proceed to the next step.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/07\/image-3.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"114\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/07\/image-3-1024x114.png\" alt=\"\" class=\"wp-image-4547\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/image-3-1024x114.png 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/image-3-300x34.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/image-3-768x86.png 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/image-3.png 1181w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><strong>7. Restart <\/strong><\/p>\n\n\n\n<p>Restart Apache to apply the changes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart apache2<\/code><\/pre>\n\n\n\n<p><strong>8. Test Your Virtual Host<\/strong><\/p>\n\n\n\n<p>Open a web browser and navigate to <code>http:\/\/domain1.com<\/code>. You should see the sample index page you created earlier. Thus you can see your website if you have correctly pointed your Domain name to your server&#8217;s IP address. <\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h3>\n\n\n<p>You have successfully set up Apache Virtual Hosts on your Ubuntu server. This allows you to host multiple websites on a single server, each with its own domain name. Repeat these steps to add more virtual hosts as needed.<\/p>\n\n\n\n<p><strong>Related Searches and Questions Asked<\/strong>:-<br><a href=\"https:\/\/www.veeble.org\/kb\/hide-version\/\" target=\"_blank\" rel=\"noopener\">How to hide <\/a>a<a href=\"https:\/\/www.veeble.org\/kb\/hide-version\/\" target=\"_blank\" rel=\"noopener\">pache version<br><\/a><a href=\"https:\/\/www.veeble.org\/kb\/how-to-redirect-http-to-https-using-htaccess\/\" target=\"_blank\" rel=\"noopener\">How to Redirect HTTP to HTTPS using .htaccess<br><\/a><a href=\"https:\/\/www.veeble.org\/kb\/apache-error-file-size-exceeded\/\" target=\"_blank\" rel=\"noopener\">Apache error file size exceeded<br><\/a><a href=\"https:\/\/www.veeble.org\/kb\/configure-to-listen-on-multiple-ports\/\" target=\"_blank\" rel=\"noopener\">How to Configure to listening on multiple ports<\/a><\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-7e13eb92 wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Unleash the Power of AWS, Without the Hassle<\/h3><p class=\"uagb-cta__desc\">AWS offers incredible potential, but managing it can be complex. Veeble&#8217;s managed hosting simplifies everything, from setup to security, so you can benefit from AWS without the headaches.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/managed-aws-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">Explore Managed AWS<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Apache web server is one of the most widely used web servers in the world. One of its powerful features is the ability to [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":8498,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","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":"","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":"set","ast-page-background-enabled":"default","ast-page-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":"","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-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":"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":""},"mobile":{"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":""}},"footnotes":""},"categories":[2,5],"tags":[],"class_list":["post-4543","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache","category-linux"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/How-to-setup-Apache-Web-Server-to-host-a-website-in-Linux.jpg",1536,1024,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/How-to-setup-Apache-Web-Server-to-host-a-website-in-Linux-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/How-to-setup-Apache-Web-Server-to-host-a-website-in-Linux-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/How-to-setup-Apache-Web-Server-to-host-a-website-in-Linux-768x512.jpg",768,512,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/How-to-setup-Apache-Web-Server-to-host-a-website-in-Linux-1024x683.jpg",1024,683,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/How-to-setup-Apache-Web-Server-to-host-a-website-in-Linux.jpg",1536,1024,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/07\/How-to-setup-Apache-Web-Server-to-host-a-website-in-Linux.jpg",1536,1024,false]},"uagb_author_info":{"display_name":"Nayana Nair","author_link":"https:\/\/www.veeble.com\/kb\/author\/nayana\/"},"uagb_comment_info":0,"uagb_excerpt":"Apache web server is one of the most widely used web servers in the world. One of its powerful features is the ability to [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/4543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=4543"}],"version-history":[{"count":10,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/4543\/revisions"}],"predecessor-version":[{"id":8499,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/4543\/revisions\/8499"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/8498"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=4543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=4543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=4543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}