{"id":2435,"date":"2024-06-02T17:17:10","date_gmt":"2024-06-02T14:17:10","guid":{"rendered":"https:\/\/www.fibacloud.com\/community\/tutorials\/?p=2435"},"modified":"2026-10-04T22:57:46","modified_gmt":"2026-10-04T19:57:46","slug":"how-to-install-and-configure-apache-web-server","status":"publish","type":"post","link":"https:\/\/www.fibacloud.com\/community\/tutorials\/en\/how-to-install-and-configure-apache-web-server\/","title":{"rendered":"Install and Configure Apache on Ubuntu 24.04"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"2435\" class=\"elementor elementor-2435\" data-elementor-post-type=\"post\">\n\t\t\t\t<div class=\"elementor-element elementor-element-d673756 e-con-full e-flex e-con e-parent\" data-id=\"d673756\" data-element_type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-fdaa3b7 elementor-widget elementor-widget-text-editor\" data-id=\"fdaa3b7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<style>\/*! elementor - v3.21.0 - 20-05-2024 *\/\n.elementor-widget-text-editor.elementor-drop-cap-view-stacked .elementor-drop-cap{background-color:#69727d;color:#fff}.elementor-widget-text-editor.elementor-drop-cap-view-framed .elementor-drop-cap{color:#69727d;border:3px solid;background-color:transparent}.elementor-widget-text-editor:not(.elementor-drop-cap-view-default) .elementor-drop-cap{margin-top:8px}.elementor-widget-text-editor:not(.elementor-drop-cap-view-default) .elementor-drop-cap-letter{width:1em;height:1em}.elementor-widget-text-editor .elementor-drop-cap{float:left;text-align:center;line-height:1;font-size:50px}.elementor-widget-text-editor .elementor-drop-cap-letter{display:inline-block}<\/style>\t\t\t\t<p>Apache HTTP Server can serve different websites according to the requested hostname. This guide creates one virtual host using <strong>Ubuntu 24.04 LTS and its Apache 2.4 package<\/strong>. It does not mix in CentOS\/RHEL commands: <code>a2ensite<\/code>, <code>www-data<\/code> and <code>APACHE_LOG_DIR<\/code> belong to this Ubuntu workflow.<\/p>\n<figure class=\"fc-editorial-figure\" data-fc-visual=\"20260920\" aria-labelledby=\"fc-editorial-caption-2435\"><a href=\"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-content\/uploads\/community-editorial-20260920\/fc-apache-en-inline-20260920.webp\" target=\"_blank\" rel=\"noopener\" aria-label=\"Open full-size illustration\"><picture><source media=\"(max-width: 600px)\" srcset=\"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-content\/uploads\/community-editorial-20260920\/fc-apache-en-mobile-20260920.webp\" width=\"720\" height=\"1140\"><img loading=\"lazy\" src=\"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-content\/uploads\/community-editorial-20260920\/fc-apache-en-inline-20260920.webp\" srcset=\"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-content\/uploads\/community-editorial-20260920\/fc-apache-en-inline-20260920.webp 1440w, https:\/\/www.fibacloud.com\/community\/tutorials\/wp-content\/uploads\/community-editorial-20260920\/fc-apache-en-inline-20260920-300x242.webp 300w, https:\/\/www.fibacloud.com\/community\/tutorials\/wp-content\/uploads\/community-editorial-20260920\/fc-apache-en-inline-20260920-1024x825.webp 1024w, https:\/\/www.fibacloud.com\/community\/tutorials\/wp-content\/uploads\/community-editorial-20260920\/fc-apache-en-inline-20260920-768x619.webp 768w\" sizes=\"auto, (max-width: 900px) 100vw, 820px\" width=\"1440\" height=\"1160\" alt=\"How virtual host selection works\" class=\"wp-image-2584\"  decoding=\"async\"><\/picture><\/a><figcaption id=\"fc-editorial-caption-2435\"><strong>How virtual host selection works<\/strong> Apache selects a virtual host using the connection address\/port and requested hostname. With HTTPS, SNI also affects certificate selection; unmatched names may reach the default host.<details><summary>Step-by-step explanation<\/summary><ol><li>Receive: Identify the address and port.<\/li><li>Match: Use Host and, for HTTPS, SNI.<\/li><li>Route: Select the matching VirtualHost configuration.<\/li><li>Check: Test the default site too.<\/li><\/ol><\/details><\/figcaption><\/figure>\n<h2>Prerequisites and scope<\/h2>\n<p>Use a new or separate test server, a sudo-capable account and a domain you control for public deployment. Replace <code>site.example.com<\/code> consistently with your own hostname. Do not install over an existing Nginx, Apache, control-panel or container server without first reviewing its configuration and port ownership:<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f6b283d elementor-widget elementor-widget-text-editor\" data-id=\"f6b283d\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<pre><code class=\"language-bash\">cat \/etc\/os-release\nsudo ss -ltnp '( sport = :80 or sport = :443 )'<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f1bb2fb elementor-widget elementor-widget-text-editor\" data-id=\"f1bb2fb\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Validate the virtual host and response checks in a separate environment. Package installation, system services and a publicly trusted TLS certificate require additional acceptance checks on your server; providing commands is not a claim of complete environment testing.<\/p>\n<h2>1. Install Apache<\/h2>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7b301b5 elementor-widget elementor-widget-text-editor\" data-id=\"7b301b5\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<pre><code class=\"language-bash\">sudo apt update\nsudo apt install apache2\napache2 -v\nsudo systemctl status apache2 --no-pager<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f5663ec elementor-widget elementor-widget-text-editor\" data-id=\"f5663ec\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>The Ubuntu package can start the service during installation. Preserve SSH access when changing firewall rules and allow only the web ports you need. Do not disable the firewall. HTTPS needs port 443; HTTP redirection and HTTP-01 certificate validation can require port 80.<\/p>\n<h2>2. Create a separate document root<\/h2>\n<p>The deployment account owns the example files. The web server does not receive write access to the entire content tree.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2563fb5 elementor-widget elementor-widget-text-editor\" data-id=\"2563fb5\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<pre><code class=\"language-bash\">sudo install -d -o \"$(id -u)\" -g \"$(id -g)\" -m 0755 \/var\/www\/fc-example\/public\ncat &gt; \/var\/www\/fc-example\/public\/index.html &lt;&lt;'HTML'\n&lt;!doctype html&gt;\n&lt;html lang=\"en\"&gt;&lt;meta charset=\"utf-8\"&gt;&lt;title&gt;Apache test&lt;\/title&gt;\n&lt;h1&gt;Apache virtual host OK&lt;\/h1&gt;&lt;\/html&gt;\nHTML\nchmod 0644 \/var\/www\/fc-example\/public\/index.html<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0982d78 elementor-widget elementor-widget-text-editor\" data-id=\"0982d78\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>If an application needs an upload or cache directory, grant access only to that directory according to its requirements. A static website does not need the web server to modify its files.<\/p>\n<h2>3. Configure the virtual host<\/h2>\n<p>If <code>\/etc\/apache2\/sites-available\/fc-example.conf<\/code> already exists, inspect and back it up instead of overwriting an existing site. For a new file, use:<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6efa288 elementor-widget elementor-widget-text-editor\" data-id=\"6efa288\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<pre><code class=\"language-apache\">&lt;VirtualHost *:80&gt;\n    ServerName site.example.com\n    DocumentRoot \/var\/www\/fc-example\/public\n\n    &lt;Directory \/var\/www\/fc-example\/public&gt;\n        Options -Indexes +FollowSymLinks\n        AllowOverride None\n        Require all granted\n    &lt;\/Directory&gt;\n\n    ErrorLog ${APACHE_LOG_DIR}\/fc-example-error.log\n    CustomLog ${APACHE_LOG_DIR}\/fc-example-access.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c5b9c31 elementor-widget elementor-widget-text-editor\" data-id=\"c5b9c31\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p><code>Options -Indexes<\/code> disables directory listings. <code>AllowOverride None<\/code> prevents <code>.htaccess<\/code> files from altering this static example. Applications such as WordPress may need rewrite rules; permit only the required directives within the relevant directory.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d353f5d elementor-widget elementor-widget-text-editor\" data-id=\"d353f5d\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<pre><code class=\"language-bash\">sudo a2ensite fc-example.conf\nsudo apache2ctl configtest\nsudo apache2ctl -S<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-033d3de elementor-widget elementor-widget-text-editor\" data-id=\"033d3de\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Do not reload until <code>configtest<\/code> reports <strong>Syntax OK<\/strong>. Confirm that <code>-S<\/code> maps the hostname to the intended file and port. Then run:<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ce2f21a elementor-widget elementor-widget-text-editor\" data-id=\"ce2f21a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<pre><code class=\"language-bash\">sudo systemctl reload apache2\ncurl --fail --resolve site.example.com:80:127.0.0.1 http:\/\/site.example.com\/\ncurl -I --resolve site.example.com:80:127.0.0.1 http:\/\/site.example.com\/not-found<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-46b0dc0 elementor-widget elementor-widget-text-editor\" data-id=\"46b0dc0\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>The first request should return the test heading; the second should return 404. <code>--resolve<\/code> changes DNS resolution only for that curl request, not public DNS. Seeing a default site at the server&#8217;s IP address does not prove that the hostname selects the correct virtual host.<\/p>\n<h2>4. Complete DNS and HTTPS<\/h2>\n<p>Point the real domain&#8217;s A record and any AAAA record to the intended server. If you also need a <code>www<\/code> name, include it consistently in DNS, <code>ServerAlias<\/code> and the certificate. This example uses one hostname.<\/p>\n<p>For the Certbot Apache plugin packaged by Ubuntu:<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e660533 elementor-widget elementor-widget-text-editor\" data-id=\"e660533\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<pre><code class=\"language-bash\">sudo apt install certbot python3-certbot-apache\nsudo certbot --apache -d site.example.com\nsudo apache2ctl configtest\nsudo certbot renew --dry-run<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-935b6cf elementor-widget elementor-widget-text-editor\" data-id=\"935b6cf\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Use your real domain only after its validation requirements are satisfied. DNS-01 validation or an external load balancer requires that deployment&#8217;s own certificate workflow. Review the virtual-host changes made by Certbot, verify HTTP-to-HTTPS redirection and test renewal. HTTPS should work before entering application credentials.<\/p>\n<h2>Acceptance, troubleshooting and rollback<\/h2>\n<p>Check HTTPS from outside the server, the certificate chain, an internal page and a nonexistent page. Confirm directory listings are disabled, logs contain no unexplained errors and the web account cannot modify application code.<\/p>\n<ul>\n<li><strong>Address already in use:<\/strong> identify the process holding port 80 or 443; do not stop an existing server indiscriminately.<\/li>\n<li><strong>403:<\/strong> inspect directory traversal permissions and <code>Require<\/code> rules instead of granting <code>777<\/code>.<\/li>\n<li><strong>Wrong website:<\/strong> check <code>apache2ctl -S<\/code>, the Host header and DNS including AAAA records.<\/li>\n<li><strong>Failed reload:<\/strong> inspect <code>configtest<\/code> and <code>journalctl -u apache2<\/code>. Repeated restarts do not repair invalid configuration.<\/li>\n<\/ul>\n<p>To roll back, restore the previous site configuration or disable only this new example with <code>sudo a2dissite fc-example.conf<\/code>. Review any additional file created by the certificate tool. Run <code>configtest<\/code> before a controlled reload. Do not remove other sites or bulk-delete content directories, and keep backup files outside the document root.<\/p>\n<h2>Official references<\/h2>\n<ul>\n<li><a href=\"https:\/\/documentation.ubuntu.com\/server\/how-to\/web-services\/install-apache2\/\" rel=\"nofollow noopener\" target=\"_blank\">Install Apache on Ubuntu<\/a><\/li>\n<li><a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/vhosts\/examples.html\" rel=\"nofollow noopener\" target=\"_blank\">Apache 2.4 virtual-host examples<\/a><\/li>\n<li><a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/programs\/apachectl.html\" rel=\"nofollow noopener\" target=\"_blank\">apachectl and configuration testing<\/a><\/li>\n<li><a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/mod\/core.html#options\" rel=\"nofollow noopener\" target=\"_blank\">Directory Options directive<\/a><\/li>\n<li>\n<p><a href=\"https:\/\/documentation.ubuntu.com\/server\/how-to\/security\/obtain-tls-certificates\/\" rel=\"nofollow noopener\" target=\"_blank\">Ubuntu certificate management<\/a><\/p>\n<\/li>\n<li><a href=\"https:\/\/eff-certbot.readthedocs.io\/en\/stable\/using.html#apache\" rel=\"nofollow noopener\" target=\"_blank\">Certbot Apache plugin and renewal<\/a><\/li>\n<\/ul>\n<p class=\"fc-article-review-date\">Technical content and sources reviewed on October 4, 2026. Recheck the relevant official documentation when a version or provider changes.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Configure Apache 2.4 on Ubuntu 24.04 with a separate document root, virtual host, configuration checks, HTTPS and a rollback plan.<\/p>\n","protected":false},"author":1,"featured_media":2583,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[76,233,264,217],"class_list":["post-2435","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials-en","tag-apache-en","tag-fibacloud","tag-web-server","tag-webserver"],"lang":"en","translations":{"en":2435,"tr":2002},"pll_sync_post":[],"_links":{"self":[{"href":"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-json\/wp\/v2\/posts\/2435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-json\/wp\/v2\/comments?post=2435"}],"version-history":[{"count":13,"href":"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-json\/wp\/v2\/posts\/2435\/revisions"}],"predecessor-version":[{"id":2449,"href":"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-json\/wp\/v2\/posts\/2435\/revisions\/2449"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-json\/wp\/v2\/media\/2583"}],"wp:attachment":[{"href":"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-json\/wp\/v2\/media?parent=2435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-json\/wp\/v2\/categories?post=2435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fibacloud.com\/community\/tutorials\/wp-json\/wp\/v2\/tags?post=2435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}