{"id":14833,"date":"2024-10-09T12:11:47","date_gmt":"2024-10-09T12:11:47","guid":{"rendered":"https:\/\/truehost.com\/support\/?post_type=docs&#038;p=14833"},"modified":"2025-01-10T14:13:47","modified_gmt":"2025-01-10T14:13:47","password":"","slug":"how-to-configure-the-apache-web-server-on-an-ubuntu-debian","status":"publish","type":"docs","link":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\/","title":{"rendered":"How To Configure the Apache Web Server on an Ubuntu\/Debian"},"content":{"rendered":"\n<p>The Apache HTTP Server, commonly known as Apache, is one of the most popular and widely used web servers. This guide will walk you through the steps required to install, configure, and manage Apache on an Ubuntu system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before you begin, make sure you have the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Ubuntu Server or Desktop<\/strong>: A system running Ubuntu (18.04\/20.04\/22.04).<\/li>\n\n\n\n<li><strong>Root or Sudo Privileges<\/strong>: You need administrative access to install and configure Apache.<\/li>\n\n\n\n<li><strong>Basic Terminal Skills<\/strong>: Familiarity with Linux command-line utilities.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step-by-step<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Follow these steps<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 1<\/strong>: SSH into your server as root. See <strong><a href=\"https:\/\/truehost.com\/support\/knowledge-base\/how-to-access-a-server-via-ssh-terminal\/\" target=\"_blank\" rel=\"noreferrer noopener\">these steps<\/a><\/strong> on how to.<\/h5>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 2: Update the Package Index<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It\u2019s always good practice to update your package list before installing any new software.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo apt update<\/strong><\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 3: Install Apache<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To install Apache, run the following command:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo apt install apache2<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You might be prompted for confirmation with a Y\/n option. Press y and then Enter to proceed. The Apache2 web server and all its dependencies will be installed on your system.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Once done, you can check apache version using the command below;<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>apache2 -version<\/strong><\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 4: Adjust the Firewall to Allow Apache<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you have a firewall enabled on your server, you\u2019ll need to open ports for Apache. Apache typically uses port <code>80<\/code> for HTTP and port <code>443<\/code> for HTTPS.<\/li>\n\n\n\n<li>To allow traffic on these ports, use the following command:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo ufw allow 'Apache'<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To verify that the rules were added successfully, run:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo ufw status<\/strong><\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 5: Check Apache Status<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>After installation, Apache should start automatically. You can check its status using the following command:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo systemctl status apache2<\/strong><\/code><\/pre>\n\n\n\n<p>You should see a message indicating that the service is active and running.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 6: Test Apache Installation<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To test that Apache is working correctly, open a web browser and enter your server&#8217;s IP address:<\/li>\n\n\n\n<li>You can get your IP bu running <strong>hostname -I<\/strong> on your terminal, then access the it on your browser.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>http:\/\/your-server-ip<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You should see the default Apache welcome page, confirming that the web server is running correctly.<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 7: Managing Apache Service<\/strong><\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can manage the Apache service using the <code>systemctl<\/code> command. Here are some common tasks:\n<ul class=\"wp-block-list\">\n<li><strong>Start Apache<\/strong>: sudo systemctl start apache2<\/li>\n\n\n\n<li><strong>Stop Apache<\/strong>: sudo systemctl stop apache2<\/li>\n\n\n\n<li><strong>Restart Apache<\/strong>: sudo systemctl restart apache2<\/li>\n\n\n\n<li><strong>Reload Apache (without stopping)<\/strong>: sudo systemctl reload apache2<\/li>\n\n\n\n<li><strong>Enable Apache to Start at Boot<\/strong>: sudo systemctl enable apache2<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Step 8: Configure Apache Virtual Hosts<\/strong><\/h5>\n\n\n\n<p>Apache uses virtual hosts to serve multiple domains from the same server. Here\u2019s how you can create a virtual host configuration.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Create the Directory for the Website<\/strong>:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo mkdir -p \/var\/www\/your_domain<\/strong>\/<strong>public_html<\/strong>\/<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Assign Ownership<\/strong>: Assign ownership of the directory to the user running the web server (typically <code>www-data<\/code>):<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo chown -R www-data:www-data \/var\/www\/your_domain\/public_html<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Create a Virtual Host Configuration File<\/strong>: Apache stores virtual host configurations in <code>\/etc\/apache2\/sites-available\/<\/code>. Create a new configuration file for your domain:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo vim \/etc\/apache2\/sites-available\/your_domain.conf<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add the following content: Replace <strong>your_domain<\/strong> with your domain name<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerName your_domain.com\n    ServerAlias www.your_domain.com\n    DocumentRoot \/var\/www\/your_domain.com\/public_html\n    ErrorLog \/var\/www\/your_domain.com\/error.log\n    CustomLog \/var\/www\/your_domain.com\/requests.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Enable the Virtual Host<\/strong>: Enable your virtual host by running:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo a2ensite your_domain.conf<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Disable the Default Virtual Host<\/strong> (Optional): If you no longer want to serve the default Apache page:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo a2dissite 000-default.conf<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Reload Apache<\/strong>: For the changes to take effect:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo systemctl reload apache2<\/strong><\/code><\/pre>\n\n\n\n<p><strong>Step 8: Test if your set up can serve a website <\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a sample index.html file in your document root, using vim or nano or your preferred text editor:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>vi \/var\/www\/your_domain\/public_html\/index.html<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add the following sample HTML code inside the file:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n    &lt;title&gt;Styled Text&lt;\/title&gt;\n    &lt;style&gt;\n        .styled-text {\n            font-family: Arial, sans-serif;\n            font-size: 20px;\n            color: #333;\n            line-height: 1.5;\n            text-align: center;\n            margin-top: 50px;\n        }\n    &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;div class=\"styled-text\"&gt;\n        Yoh! You get me?.&lt;br&gt;\n        My apache set up is working. Let's celebrate!\n    &lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Save the file once you have added the code and restart apache.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>sudo systemctl restart apache2<\/strong><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Visit your domain on the browser to see if it displays content of your index.html file. <\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The Apache HTTP Server, commonly known as Apache, is one of the most popular and widely used web servers. This guide will walk you through the steps required to install, configure, and manage Apache on an Ubuntu system. Prerequisites Before you begin, make sure you have the following: Step-by-step Step 1: SSH into your server [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_eb_attr":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"doc_category":[1820,1824,1879,2128],"doc_tag":[],"class_list":["post-14833","docs","type-docs","status-publish","hentry","doc_category-cloud-servers-in-kenya","doc_category-dedicated-servers","doc_category-servers","doc_category-vps-servers"],"year_month":"2026-07","word_count":753,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"Eugene","author_nicename":"eugene","author_url":"https:\/\/www.truehost.com\/support\/author\/eugene\/"},"doc_category_info":[{"term_name":"Cloud servers in Kenya","term_url":"https:\/\/www.truehost.com\/support\/docs-category\/cloud-servers-in-kenya\/"},{"term_name":"dedicated servers","term_url":"https:\/\/www.truehost.com\/support\/docs-category\/dedicated-servers\/"},{"term_name":"Servers","term_url":"https:\/\/www.truehost.com\/support\/docs-category\/servers\/"},{"term_name":"VPS-Servers","term_url":"https:\/\/www.truehost.com\/support\/docs-category\/vps-servers\/"}],"doc_tag_info":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How To Configure the Apache Web Server on an Ubuntu\/Debian -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Configure the Apache Web Server on an Ubuntu\/Debian -\" \/>\n<meta property=\"og:description\" content=\"The Apache HTTP Server, commonly known as Apache, is one of the most popular and widely used web servers. This guide will walk you through the steps required to install, configure, and manage Apache on an Ubuntu system. Prerequisites Before you begin, make sure you have the following: Step-by-step Step 1: SSH into your server [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\/\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-10T14:13:47+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\\\/\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\\\/\",\"name\":\"How To Configure the Apache Web Server on an Ubuntu\\\/Debian -\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#website\"},\"datePublished\":\"2024-10-09T12:11:47+00:00\",\"dateModified\":\"2025-01-10T14:13:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Configure the Apache Web Server on an Ubuntu\\\/Debian\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#website\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\",\"name\":\"\",\"description\":\"Help In a Click\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#organization\",\"name\":\"Truehost Kenya\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"contentUrl\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"width\":240,\"height\":48,\"caption\":\"Truehost Kenya\"},\"image\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Configure the Apache Web Server on an Ubuntu\/Debian -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\/","og_locale":"en_US","og_type":"article","og_title":"How To Configure the Apache Web Server on an Ubuntu\/Debian -","og_description":"The Apache HTTP Server, commonly known as Apache, is one of the most popular and widely used web servers. This guide will walk you through the steps required to install, configure, and manage Apache on an Ubuntu system. Prerequisites Before you begin, make sure you have the following: Step-by-step Step 1: SSH into your server [&hellip;]","og_url":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\/","article_modified_time":"2025-01-10T14:13:47+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\/","url":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\/","name":"How To Configure the Apache Web Server on an Ubuntu\/Debian -","isPartOf":{"@id":"https:\/\/www.truehost.com\/support\/#website"},"datePublished":"2024-10-09T12:11:47+00:00","dateModified":"2025-01-10T14:13:47+00:00","breadcrumb":{"@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-configure-the-apache-web-server-on-an-ubuntu-debian\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.truehost.com\/support\/"},{"@type":"ListItem","position":2,"name":"How To Configure the Apache Web Server on an Ubuntu\/Debian"}]},{"@type":"WebSite","@id":"https:\/\/www.truehost.com\/support\/#website","url":"https:\/\/www.truehost.com\/support\/","name":"","description":"Help In a Click","publisher":{"@id":"https:\/\/www.truehost.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.truehost.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.truehost.com\/support\/#organization","name":"Truehost Kenya","url":"https:\/\/www.truehost.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.truehost.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","contentUrl":"https:\/\/www.truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","width":240,"height":48,"caption":"Truehost Kenya"},"image":{"@id":"https:\/\/www.truehost.com\/support\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/docs\/14833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/comments?post=14833"}],"version-history":[{"count":16,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/docs\/14833\/revisions"}],"predecessor-version":[{"id":18411,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/docs\/14833\/revisions\/18411"}],"wp:attachment":[{"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/media?parent=14833"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/doc_category?post=14833"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.truehost.com\/support\/wp-json\/wp\/v2\/doc_tag?post=14833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}